[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #134: Fix #133 Test netty4-http as a producer

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #134: Fix #133 Test netty4-http as a producer

GitBox
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_r313728474
 
 

 ##########
 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 {
 
 Review comment:
   I did not want to expand the class path while we cannot use the test scope. I did not like `com.sun.net.httpserver.HttpServer` for not being portable accross Java vendors. I have not thought of Undertow (or vert.x) though. Let me have a look if it is there in the CP already.

----------------------------------------------------------------
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:
[hidden email]


With regards,
Apache Git Services