ppalaga commented on a change in pull request #134: Fix #133 Test netty4-http 
as a producer
URL: https://github.com/apache/camel-quarkus/pull/134#discussion_r313731272
 
 

 ##########
 File path: 
integration-tests/netty4-http/src/test/java/org/apache/camel/quarkus/component/netty4/http/CamelTest.java
 ##########
 @@ -16,18 +16,119 @@
  */
 package org.apache.camel.quarkus.component.netty4.http;
 
+import static org.hamcrest.Matchers.is;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicBoolean;
 
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
 import org.junit.jupiter.api.Test;
 
-import static org.hamcrest.Matchers.is;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
 
 @QuarkusTest
 public class CamelTest {
+
     @Test
     public void testNetty4Http() throws Exception {
         RestAssured.when().get(new 
URI("http://localhost:8999/foo";)).then().body(is("Netty Hello World"));
     }
+
+    @Test
+    public void netty4HttpProducer() throws Exception {
+        try (Server s = new Server("HTTP/1.1 200 OK\r\n" +
+                "Content-Type: text/plain\r\n" +
+                "\r\n" +
+                "Hello from the mockserver!")) {
+            /* First check that our mockserver actually works */
+            RestAssured.when().get(new URI("http://localhost:"; + 
CamelRoute.PRODUCER_TARGET_PORT + "/")).then()
+                    .statusCode(200)
+                    .body(is("Hello from the mockserver!"));
+            /* The producer route should proxy the mockserver */
+            RestAssured.when().get(new 
URI("http://localhost:8999/producer";)).then()
+                    .statusCode(200)
+                    .body(is("Hello from the mockserver!"));
+        }
+    }
+
+    /**
+     * An HTTP server always sending the same response.
+     */
+    static class Server implements Closeable, Runnable {
+
+        private volatile AtomicBoolean stop = new AtomicBoolean(false);
 
 Review comment:
   `volatile AtomicBoolean` - what a nice nonsense! :)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to