activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r524096 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/converter/ camel-xmpp/ camel-xmpp/src/main/java/org/apache/camel/component/xmpp/ camel-xmpp/src/test/java/org/apache/camel/component/xmpp/
Date Fri, 30 Mar 2007 14:15:49 GMT
Author: jstrachan
Date: Fri Mar 30 07:15:46 2007
New Revision: 524096

URL: http://svn.apache.org/viewvc?view=rev&rev=524096
Log:
added an integration test which is disabled by default but can be enabled via maven properties

Added:
    activemq/camel/trunk/camel-xmpp/README.txt   (with props)
    activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
    activemq/camel/trunk/camel-xmpp/pom.xml
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppGroupChatProducer.java
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppMessage.java
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
Fri Mar 30 07:15:46 2007
@@ -63,6 +63,6 @@
         if (value instanceof String) {
             return "true".equalsIgnoreCase(value.toString());
         }
-        return value != null;
+        return false;
     }
 }

Added: activemq/camel/trunk/camel-xmpp/README.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/README.txt?view=auto&rev=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/README.txt (added)
+++ activemq/camel/trunk/camel-xmpp/README.txt Fri Mar 30 07:15:46 2007
@@ -0,0 +1,24 @@
+Camel XMPP
+==========
+
+Welcome to the Camel XMPP transport for communicating with Jabber servers.
+
+For more details see
+
+  http://activemq.apache.org/camel/xmpp.html
+
+
+Running the Integration Tests
+-----------------------------
+
+To run the intergration tests you need a Jabber server to communicate with such as Jive Software's
WildFire
+
+
+To enable the integration tests set the maven property
+
+  xmpp.enable = true
+
+You may also want to overload the default value of the server to connect with via
+
+  xmpp.url = xmpp://camel@localhost/?login=false&room=
+

Propchange: activemq/camel/trunk/camel-xmpp/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-xmpp/README.txt
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-xmpp/README.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-xmpp/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/pom.xml?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/pom.xml (original)
+++ activemq/camel/trunk/camel-xmpp/pom.xml Fri Mar 30 07:15:46 2007
@@ -55,13 +55,6 @@
       <version>2.2.1</version>
     </dependency>
 
-<!--
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring</artifactId>
-    </dependency>
--->
-
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
@@ -69,4 +62,23 @@
     </dependency>
   </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemProperties>
+            <property>
+              <name>xmpp.enable</name>
+              <value>${xmpp.enable}</value>
+            </property>
+            <property>
+              <name>xmpp.server</name>
+              <value>${xmpp.url}</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
Fri Mar 30 07:15:46 2007
@@ -29,7 +29,6 @@
  * @version $Revision$
  */
 public class XmppBinding {
-    
     /**
      * Populates the given XMPP message from the inbound exchange
      */
@@ -44,7 +43,10 @@
                 message.setProperty(name, value);
             }
         }
-        message.setProperty("exchangeId", exchange.getExchangeId());
+        String id = exchange.getExchangeId();
+        if (id != null) {
+            message.setProperty("exchangeId", id);
+        }
     }
 
     /**

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
Fri Mar 30 07:15:46 2007
@@ -56,25 +56,31 @@
     }
 
     public void processPacket(Packet packet) {
-        if (log.isDebugEnabled()) {
-            log.debug("<<<< " + packet);
-        }
 
         if (packet instanceof Message) {
             Message message = (Message) packet;
+            if (log.isDebugEnabled()) {
+                log.debug("<<<< message: " + message.getBody());
+            }
             XmppExchange exchange = endpoint.createExchange(message);
             getProcessor().onExchange(exchange);
         }
         else if (packet instanceof RosterPacket) {
             RosterPacket rosterPacket = (RosterPacket) packet;
             if (log.isDebugEnabled()) {
-                log.debug("Roster packet with : " + rosterPacket.getRosterItemCount());
+                log.debug("Roster packet with : " + rosterPacket.getRosterItemCount() + "
item(s)");
                 Iterator rosterItems = rosterPacket.getRosterItems();
                 while (rosterItems.hasNext()) {
                     Object item = rosterItems.next();
                     log.debug("Roster item: " + item);
                 }
             }
+        }
+        else {
+            if (log.isDebugEnabled()) {
+                log.debug("<<<< ignored packet: " + packet);
+            }
+
         }
     }
 }

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppGroupChatProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppGroupChatProducer.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppGroupChatProducer.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppGroupChatProducer.java
Fri Mar 30 07:15:46 2007
@@ -58,7 +58,7 @@
 
         endpoint.getBinding().populateXmppMessage(message, exchange);
         if (log.isDebugEnabled()) {
-            log.debug(">>>> " + message);
+            log.debug(">>>> message: " + message.getBody());
         }
         try {
             chat.sendMessage(message);

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppMessage.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppMessage.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppMessage.java
Fri Mar 30 07:15:46 2007
@@ -20,9 +20,9 @@
 import org.apache.camel.impl.DefaultMessage;
 import org.jivesoftware.smack.packet.Message;
 
-import java.util.Map;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 /**
  * Represents a {@link org.apache.camel.Message} for working with XMPP
@@ -74,7 +74,12 @@
 
     @Override
     public void setHeader(String name, Object value) {
-        xmppMessage.setProperty(name, value);
+        if (value == null) {
+            xmppMessage.deleteProperty(name);
+        }
+        else {
+            xmppMessage.setProperty(name, value);
+        }
     }
 
     @Override

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java?view=diff&rev=524096&r1=524095&r2=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
Fri Mar 30 07:15:46 2007
@@ -60,7 +60,7 @@
 
         endpoint.getBinding().populateXmppMessage(message, exchange);
         if (log.isDebugEnabled()) {
-            log.debug(">>>> " + message);
+            log.debug(">>>> message: " + message.getBody());
         }
         try {
             chat.sendMessage(message);

Added: activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java?view=auto&rev=524096
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
(added)
+++ activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
Fri Mar 30 07:15:46 2007
@@ -0,0 +1,151 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.camel.component.xmpp;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.ObjectConverter;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.util.ProducerCache;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jivesoftware.smack.packet.Message;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * An integration test which requires a Jabber server to be running, by default on localhost.
+ * <p/>
+ * You can overload the <b>xmpp.url</b> system property to define the jabber
connection URI
+ * to something like <b>xmpp://camel@localhost/?login=false&room=</b>
+ *
+ * @version $Revision$
+ */
+public class XmppRouteTest extends TestCase {
+    protected static boolean enabled;
+    protected static String xmppUrl;
+    private static final transient Log log = LogFactory.getLog(XmppRouteTest.class);
+    protected XmppExchange receivedExchange;
+    protected CamelContext container = new DefaultCamelContext();
+    protected CountDownLatch latch = new CountDownLatch(1);
+    protected Endpoint<XmppExchange> endpoint;
+    protected ProducerCache<XmppExchange> client = new ProducerCache<XmppExchange>();
+
+    public static void main(String[] args) {
+        enabled = true;
+        if (args.length > 0) {
+            xmppUrl = args[0];
+        }
+        TestRunner.run(XmppRouteTest.class);
+    }
+
+    public void testXmppRouteWithTextMessage() throws Exception {
+        if (isXmppServerPresent()) {
+            String expectedBody = "Hello there!";
+            sendExchange(expectedBody);
+
+            Object body = assertReceivedValidExchange();
+            assertEquals("body", expectedBody, body);
+
+            //Thread.sleep(100000);
+        }
+    }
+
+    protected static boolean isXmppServerPresent() {
+        if (enabled) {
+            return true;
+        }
+        return ObjectConverter.toBoolean(System.getProperty("xmpp.enable"));
+    }
+
+    protected void sendExchange(final Object expectedBody) {
+        client.send(endpoint, new Processor<XmppExchange>() {
+            public void onExchange(XmppExchange exchange) {
+                // now lets fire in a message
+                XmppMessage in = exchange.getIn();
+                in.setBody(expectedBody);
+                in.setHeader("cheese", 123);
+            }
+        });
+    }
+
+    protected Object assertReceivedValidExchange() throws Exception {
+        // lets wait on the message being received
+        boolean received = latch.await(5, TimeUnit.SECONDS);
+        assertTrue("Did not recieve the message!", received);
+
+        assertNotNull(receivedExchange);
+        XmppMessage receivedMessage = receivedExchange.getIn();
+
+        Assert.assertEquals("cheese header", 123, receivedMessage.getHeader("cheese"));
+        Object body = receivedMessage.getBody();
+        XmppRouteTest.log.debug("Received body: " + body);
+        Message xmppMessage = receivedMessage.getXmppMessage();
+        assertNotNull(xmppMessage);
+
+        XmppRouteTest.log.debug("Received XMPP message: " + xmppMessage.getBody());
+        return body;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        if (isXmppServerPresent()) {
+            String uriPrefx = getUriPrefix();
+            final String uri1 = uriPrefx + "a";
+            final String uri2 = uriPrefx + "b";
+            log.info("Using URI " + uri1 + " and " + uri2);
+
+            // lets add some routes
+            container.addRoutes(new RouteBuilder() {
+                public void configure() {
+                    from(uri1).to(uri2);
+                    from(uri2).process(new Processor<XmppExchange>() {
+                        public void onExchange(XmppExchange e) {
+                            log.info("Received exchange: " + e);
+                            receivedExchange = e;
+                            latch.countDown();
+                        }
+                    });
+                }
+            });
+            endpoint = container.resolveEndpoint(uri1);
+            assertNotNull("No endpoint found!", endpoint);
+        }
+
+        container.activateEndpoints();
+    }
+
+    protected String getUriPrefix() {
+        if (xmppUrl != null) {
+            return xmppUrl;
+        }
+        return System.getProperty("xmpp.url", "xmpp://camel@localhost/?login=false&room=").trim();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        client.stop();
+        container.deactivateEndpoints();
+    }
+}

Propchange: activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message