camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1297103 - in /camel/trunk/components/camel-websocket: ./ src/test/java/org/apache/camel/component/websocket/ src/test/resources/
Date Mon, 05 Mar 2012 15:56:39 GMT
Author: davsclaus
Date: Mon Mar  5 15:56:38 2012
New Revision: 1297103

URL: http://svn.apache.org/viewvc?rev=1297103&view=rev
Log:
CAMEL-4498: Use AHC client for websocket unit tests.

Removed:
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRoute2Test.java
Modified:
    camel/trunk/components/camel-websocket/pom.xml
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
    camel/trunk/components/camel-websocket/src/test/resources/log4j.properties

Modified: camel/trunk/components/camel-websocket/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/pom.xml?rev=1297103&r1=1297102&r2=1297103&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/pom.xml (original)
+++ camel/trunk/components/camel-websocket/pom.xml Mon Mar  5 15:56:38 2012
@@ -43,14 +43,6 @@
         </camel.osgi.import.pkg>
     </properties>
 
-    <repositories>
-        <repository>
-            <id>fusesource.m2</id>
-            <name>Fusesource Dependency Repository</name>
-            <url>http://repo.fusesource.com/maven2</url>
-        </repository>
-    </repositories>
-
     <dependencies>
         <!-- Camel -->
         <dependency>
@@ -85,9 +77,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>de.roderick</groupId>
-            <artifactId>weberknecht</artifactId>
-            <version>0.1.1</version>
+            <groupId>com.ning</groupId>
+            <artifactId>async-http-client</artifactId>
+            <version>${ahc-version}</version>
             <scope>test</scope>
         </dependency>
         <!-- logging -->

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java?rev=1297103&r1=1297102&r2=1297103&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
Mon Mar  5 15:56:38 2012
@@ -16,45 +16,70 @@
  */
 package org.apache.camel.component.websocket;
 
-import java.net.URI;
-
-import de.roderick.weberknecht.WebSocketConnection;
-import de.roderick.weberknecht.WebSocketEventHandler;
-import de.roderick.weberknecht.WebSocketMessage;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.websocket.WebSocket;
+import com.ning.http.client.websocket.WebSocketTextListener;
+import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.CamelTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
 public class WebsocketClientCamelRouteTest extends CamelTestSupport {
 
+    private static List<String> received = new ArrayList<String>();
+    private static CountDownLatch latch = new CountDownLatch(10);
+
     @Test
     public void testWSHttpCall() throws Exception {
-        WebSocketConnection webSocketConnection = new WebSocketConnection(new URI("ws://127.0.0.1:9292/test"));
-
-        // Register Event Handlers
-        webSocketConnection.setEventHandler(new WebSocketEventHandler() {
-            public void onOpen() {
-                log.info("--open");
-            }
-
-            public void onMessage(WebSocketMessage message) {
-                log.info("--received message: " + message.getText());
-            }
-
-            public void onClose() {
-                log.info("--close");
-            }
-        });
-
-        // Establish WebSocket Connection
-        webSocketConnection.connect();
-        log.info(">>> Connection established.");
+        AsyncHttpClient c = new AsyncHttpClient();
 
-        // Send Data
-        webSocketConnection.send("Hello from WS Client");
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/test").execute(
+            new WebSocketUpgradeHandler.Builder()
+                .addWebSocketListener(new WebSocketTextListener() {
+                    @Override
+                    public void onMessage(String message) {
+                        received.add(message);
+                        log.info("received --> " + message);
+                        latch.countDown();
+                    }
+
+                    @Override
+                    public void onFragment(String fragment, boolean last) {
+                    }
+
+                    @Override
+                    public void onOpen(WebSocket websocket) {
+                    }
+
+                    @Override
+                    public void onClose(WebSocket websocket) {
+                    }
+
+                    @Override
+                    public void onError(Throwable t) {
+                        t.printStackTrace();
+                    }
+                }).build()).get();
+
+        getMockEndpoint("mock:client").expectedBodiesReceived("Hello from WS client");
+
+        websocket.sendTextMessage("Hello from WS client");
+        assertTrue(latch.await(10, TimeUnit.SECONDS));
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals(10, received.size());
+        for (int i = 0; i < 10; i++) {
+            assertEquals(">> Welcome on board!", received.get(i));
+        }
 
-        // Close WebSocket Connection
-        webSocketConnection.close();
+        websocket.close();
+        c.close();
     }
 
     @Override
@@ -62,10 +87,11 @@ public class WebsocketClientCamelRouteTe
         return new RouteBuilder() {
             public void configure() {
                 from("websocket://test")
-                    .log(">>> Message received from WebSocket Client : ${body}")
-                    .loop(10)
-                        .setBody().constant(">> Welcome on board!")
-                        .to("websocket://test");
+                        .log(">>> Message received from WebSocket Client : ${body}")
+                        .to("mock:client")
+                        .loop(10)
+                            .setBody().constant(">> Welcome on board!")
+                            .to("websocket://test");
             }
         };
     }

Modified: camel/trunk/components/camel-websocket/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/resources/log4j.properties?rev=1297103&r1=1297102&r2=1297103&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-websocket/src/test/resources/log4j.properties Mon Mar  5
15:56:38 2012
@@ -23,6 +23,7 @@ log4j.rootLogger=INFO, file
 # uncomment the following line to turn on Camel debugging
 #log4j.logger.org.apache.camel.component.websocket=DEBUG
 #log4j.logger.org.eclipse.jetty.websocket=DEBUG
+#log4j.logger.com.ning.http.client=DEBUG
 
 
 # CONSOLE appender not used by default
@@ -35,4 +36,4 @@ log4j.appender.out.layout.ConversionPatt
 log4j.appender.file=org.apache.log4j.FileAppender
 log4j.appender.file.layout=org.apache.log4j.PatternLayout
 log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.file.file=target/camel-netty-test.log
\ No newline at end of file
+log4j.appender.file.file=target/camel-websocket-test.log
\ No newline at end of file



Mime
View raw message