You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "JiriOndrusek (via GitHub)" <gi...@apache.org> on 2023/04/21 06:36:33 UTC

[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4813: Snmp: Extend test coverage #4797

JiriOndrusek commented on code in PR #4813:
URL: https://github.com/apache/camel-quarkus/pull/4813#discussion_r1173360219


##########
integration-tests-jvm/snmp/src/test/java/org/apache/camel/quarkus/component/snmp/it/SnmpTest.java:
##########
@@ -16,19 +16,80 @@
  */
 package org.apache.camel.quarkus.component.snmp.it;
 
+import java.util.concurrent.TimeUnit;
+
+import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
+import org.hamcrest.Matchers;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+
+/**
+ * There is a responder defined in the test resource. Which returns 2 responses without a delay and the third one
+ * with delay longer then default timeout. This means following behavior:
+ * - send PDU will receive 1 response
+ * - get_next will receive 2 responses (the third one reaches timeout)
+ * - poll returns unending stream of responses
+ */
 @QuarkusTest
+@QuarkusTestResource(SnmpTestResource.class)
 class SnmpTest {
 
     @Test
-    public void loadComponentSnmp() {
-        /* A simple autogenerated test */
-        RestAssured.get("/snmp/load/component/snmp")
+    public void testSendReceiveTrap() throws Exception {
+
+        RestAssured.given()
+                .body("TEXT")
+                .post("/snmp/produceTrap")
                 .then()
                 .statusCode(200);
+
+        await().atMost(10L, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS).until(() -> {
+            String result = RestAssured.given()
+                    .body("trap")
+                    .post("/snmp/results")
+                    .then()
+                    .statusCode(200)
+                    .extract().body().asString();
+
+            return result.contains("TEXT");
+        });
+    }
+
+    @Test
+    public void testPoll() throws Exception {
+        await().atMost(10L, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS).until(() -> {
+            String result = RestAssured.given()
+                    .body("poll")
+                    .post("/snmp/results")
+                    .then()
+                    .statusCode(200)
+                    .extract().body().asString();
+
+            return result.startsWith("Response from the test #1,Response from the test #2,Response from the test #3");
+        });
     }
 
+    @Test
+    public void testProducePDU() {
+
+        RestAssured
+                .get("/snmp/producePDU")
+                .then()
+                .statusCode(200)
+                .body(Matchers.equalTo("Response from the test #1"));
+    }
+
+    @Test
+    public void testGetNext() {
+
+        RestAssured.given()
+                .body("TEXT")
+                .post("/snmp/getNext")
+                .then()
+                .statusCode(200)
+                .body(Matchers.equalTo("Response from the test #1,Response from the test #2"));

Review Comment:
   No, tests uses different OID and the test resource returns for each of oids a freshly counted responses.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org