camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1301942 - /camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
Date Sat, 17 Mar 2012 14:29:50 GMT
Author: davsclaus
Date: Sat Mar 17 14:29:50 2012
New Revision: 1301942

URL: http://svn.apache.org/viewvc?rev=1301942&view=rev
Log:
CAMEL-5061: Added example for documentation

Added:
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
      - copied, changed from r1301919, camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java

Copied: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
(from r1301919, 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/WebsocketRouteExampleTest.java?p2=camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java&p1=camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java&r1=1301919&r2=1301942&rev=1301942&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/WebsocketRouteExampleTest.java
Sat Mar 17 14:29:50 2012
@@ -29,16 +29,16 @@ import org.apache.camel.builder.RouteBui
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class WebsocketClientCamelRouteTest extends CamelTestSupport {
+public class WebsocketRouteExampleTest extends CamelTestSupport {
 
     private static List<String> received = new ArrayList<String>();
-    private static CountDownLatch latch = new CountDownLatch(10);
+    private static CountDownLatch latch = new CountDownLatch(1);
 
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/test").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/echo").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -66,17 +66,11 @@ public class WebsocketClientCamelRouteTe
                     }
                 }).build()).get();
 
-        getMockEndpoint("mock:client").expectedBodiesReceived("Hello from WS client");
-
-        websocket.sendTextMessage("Hello from WS client");
+        websocket.sendTextMessage("Beer");
         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));
-        }
+        assertEquals(1, received.size());
+        assertEquals("BeerBeer", received.get(0));
 
         websocket.close();
         c.close();
@@ -86,12 +80,16 @@ public class WebsocketClientCamelRouteTe
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("websocket://test")
-                        .log(">>> Message received from WebSocket Client : ${body}")
-                        .to("mock:client")
-                        .loop(10)
-                            .setBody().constant(">> Welcome on board!")
-                            .to("websocket://test");
+                // START SNIPPET: e1
+                // expose a echo websocket client, that sends back an echo
+                from("websocket://echo")
+                    .log(">>> Message received from WebSocket Client : ${body}")
+                    .transform().simple("${body}${body}")
+                    // send back to the client, by sending the message to the same endpoint
+                    // this is needed as by default messages is InOnly
+                    // and we will by default send back to the current client using the provided
connection key
+                    .to("websocket://echo");
+                // END SNIPPET: e1
             }
         };
     }



Mime
View raw message