camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r1240071 - in /camel/trunk/components/camel-websocket: ./ src/main/java/org/apache/camel/component/websocket/ src/test/java/org/apache/camel/component/websocket/ src/test/resources/
Date Fri, 03 Feb 2012 10:47:54 GMT
Author: cmoulliard
Date: Fri Feb  3 10:47:53 2012
New Revision: 1240071

URL: http://svn.apache.org/viewvc?rev=1240071&view=rev
Log:
Add a first camel unit test for websocket

Added:
    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
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java

Modified: camel/trunk/components/camel-websocket/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/pom.xml?rev=1240071&r1=1240070&r2=1240071&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/pom.xml (original)
+++ camel/trunk/components/camel-websocket/pom.xml Fri Feb  3 10:47:53 2012
@@ -62,15 +62,31 @@
         </dependency>
         <!-- Unit test -->
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-         		<dependency>
-			<groupId>org.mockito</groupId>
-			<artifactId>mockito-core</artifactId>
-
-			<scope>test</scope>
-		</dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>de.roderick</groupId>
+            <artifactId>weberknecht</artifactId>
+            <version>0.1.1</version>
+            <scope>test</scope>
+        </dependency>
+        <!-- logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java?rev=1240071&r1=1240070&r2=1240071&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
Fri Feb  3 10:47:53 2012
@@ -16,10 +16,6 @@
  */
 package org.apache.camel.component.websocket;
 
-import java.net.InetSocketAddress;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
 import org.eclipse.jetty.server.Server;
@@ -32,6 +28,10 @@ import org.eclipse.jetty.servlet.Servlet
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
 public class WebsocketComponent extends DefaultComponent {
 
     private static final Logger LOG = LoggerFactory.getLogger(WebsocketComponent.class);
@@ -62,9 +62,6 @@ public class WebsocketComponent extends 
     }
 
     @Override
-    /**
-     * uri --> websocket://foo?storeImplementationClass=org.apache.camel.hazelcast.HazelcastWebsocketStore&storeName=foo
-     */
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         WebsocketEndpoint endpoint = endpoints.get(remaining);
         if (endpoint == null) {
@@ -165,7 +162,7 @@ public class WebsocketComponent extends 
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        LOG.info("Staring server {}:{}; static resources: {}", new Object[] {host, port,
staticResources});
+        LOG.info("Starting server {}:{}; static resources: {}", new Object[] {host, port,
staticResources});
         context = createContext();
         server = createServer(context, host, port, staticResources);
         server.start();

Added: 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=1240071&view=auto
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
(added)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
Fri Feb  3 10:47:53 2012
@@ -0,0 +1,83 @@
+package org.apache.camel.component.websocket;
+
+import de.roderick.weberknecht.WebSocketConnection;
+import de.roderick.weberknecht.WebSocketEventHandler;
+import de.roderick.weberknecht.WebSocketException;
+import de.roderick.weberknecht.WebSocketMessage;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.CamelTestSupport;
+import org.junit.Test;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+public class WebsocketClientCamelRouteTest extends CamelTestSupport {
+
+    private static URI uriWS;
+    private static WebSocketConnection webSocketConnection;
+
+    @Test
+    public void testWSHttpCall() throws WebSocketException {
+
+        try {
+            uriWS = new URI("ws://127.0.0.1:9292/test");
+            WebSocketConnection webSocketConnection = new WebSocketConnection(uriWS);
+
+            // Register Event Handlers
+            webSocketConnection.setEventHandler(new WebSocketEventHandler() {
+                public void onOpen() {
+                    System.out.println("--open");
+                }
+
+                public void onMessage(WebSocketMessage message) {
+                    System.out.println("--received message: " + message.getText());
+                }
+
+                public void onClose() {
+                    System.out.println("--close");
+                }
+            });
+
+            // Establish WebSocket Connection
+            webSocketConnection.connect();
+            System.out.println(">>> Connection established.");
+
+                        // Send Data
+            webSocketConnection.send("Hello from WS Client");
+
+
+        } catch (WebSocketException ex) {
+            ex.printStackTrace();
+        } catch (URISyntaxException e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("websocket://test")
+                    .setExchangePattern(ExchangePattern.InOut)
+                    .log(">>> Message received from WebSocket Client : ${body}")
+/*                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws Exception {
+                           String response = ">> welcome on board";
+                            exchange.getOut().setBody(response);
+                            exchange.getIn().setBody(response);
+                        }
+                    });*/
+                    .loop(10)
+                        .setBody().constant(">> Welcome on board !")
+                        .to("websocket://test");
+
+            }
+        };
+    }
+
+
+}

Added: 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=1240071&view=auto
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-websocket/src/test/resources/log4j.properties Fri Feb  3
10:47:53 2012
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+log4j.logger.de.roderick.weberknecht=DEBUG
+
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+#log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+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



Mime
View raw message