Author: davsclaus
Date: Mon Aug 27 07:10:10 2012
New Revision: 1377585
URL: http://svn.apache.org/viewvc?rev=1377585&view=rev
Log:
CAMEL-5541: Use vysper for unit testing camel-xmpp. Thanks to Rich Newcomb for
the patch.
Added:
camel/trunk/components/camel-xmpp/src/test/resources/xmppServer.jks (with
props)
Modified:
camel/trunk/components/camel-xmpp/README.txt
camel/trunk/components/camel-xmpp/pom.xml
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
camel/trunk/parent/pom.xml
Modified: camel/trunk/components/camel-xmpp/README.txt
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/README.txt?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/README.txt (original)
+++ camel/trunk/components/camel-xmpp/README.txt Mon Aug 27 07:10:10 2012
@@ -7,34 +7,15 @@ For more details see
http://camel.apache.org/xmpp.html
-
-Using Spring based xml configuration in 'activemq.xml'
-------------------------------------------------------
-
-In this example an xmpp user called 'bot' will propagate any messages to the
queue 'gimme_an_a' to a muc
-called 'monitor'. The conference subdomain is part of openfire muc jid
implementation (i guess). Notice
-the quoted ampersands.
-
-<camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
- <route>
- <from uri="activemq:gimme_an_a"/>
- <to
uri="xmpp://[email protected]/?port=5222&password=meapassword&[email protected]"/>
- </route>
-</camelContext>
-
-
-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=
-
-
+
+About the XMPP unit / integration tests
+------------------------------------------
+Most of the tests in this module are configured to execute against an embedded
version
+of the Apache Vysper XMPP server (http://mina.apache.org/vysper/). A small
number of users and
+chat rooms are statically configured during the server setup and are re-used
across the tests.
+
+@see org.apache.camel.component.xmpp.EmbeddedXmppTestServer.java in
./src/test/java
+
+A few of the tests in this module specifically require a GoogleTalk service.
These tests are
+annotated with @Ignore by default. The tester must configure such tests with
known gmail
+credentials prior to execution.
Modified: camel/trunk/components/camel-xmpp/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/pom.xml?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/pom.xml (original)
+++ camel/trunk/components/camel-xmpp/pom.xml Mon Aug 27 07:10:10 2012
@@ -36,7 +36,6 @@
</properties>
<dependencies>
-
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
@@ -46,7 +45,6 @@
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack</artifactId>
@@ -57,7 +55,6 @@
<artifactId>smackx</artifactId>
<version>${smack-version}</version>
</dependency>
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -68,6 +65,24 @@
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.vysper</groupId>
+ <artifactId>vysper-core</artifactId>
+ <version>${vysper-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.vysper.extensions</groupId>
+ <artifactId>xep0045-muc</artifactId>
+ <version>${vysper-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>${mina2-version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -76,16 +91,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
- <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>
Modified:
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
---
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
(original)
+++
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
Mon Aug 27 07:10:10 2012
@@ -19,7 +19,6 @@ package org.apache.camel.component.xmpp;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -32,15 +31,14 @@ public class XmppMultiUserChatTest exten
protected String body1 = "the first message";
protected String body2 = "the second message";
- @Ignore
@Test
public void testXmppChat() throws Exception {
- // TODO: requires online against jabber. Test this manually
consumerEndpoint = context.getEndpoint("mock:out", MockEndpoint.class);
consumerEndpoint.expectedBodiesReceived(body1, body2);
//will send chat messages to the room
template.sendBody("direct:toProducer", body1);
+ Thread.sleep(50);
template.sendBody("direct:toProducer", body2);
consumerEndpoint.assertIsSatisfied();
@@ -60,11 +58,17 @@ public class XmppMultiUserChatTest exten
}
protected String getProducerUri() {
- return
"xmpp://jabber.org:5222?room=camel-test&[email protected]&password=secret&serviceName=jabber.org";
+
+ // the nickname paramenter is necessary in these URLs because the '@'
in the user name can not be parsed by
+ // vysper during chat room message routing.
+
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]&[email protected]&password=secret&nickname=camel_producer";
}
protected String getConsumerUri() {
- return
"xmpp://jabber.org:5222?room=camel-test&[email protected]&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]&[email protected]&password=secret&nickname=camel_consumer";
}
}
Modified:
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
---
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
(original)
+++
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
Mon Aug 27 07:10:10 2012
@@ -22,7 +22,6 @@ import java.util.concurrent.Executors;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -30,19 +29,13 @@ import org.junit.Test;
*/
public class XmppProducerConcurrentTest extends CamelTestSupport {
- @Ignore
@Test
public void testNoConcurrentProducers() throws Exception {
- // a disabled test... before enabling you must fill in your own gmail
credentials in the route below
-
doSendMessages(1, 1);
}
- @Ignore
@Test
public void testConcurrentProducers() throws Exception {
- // a disabled test... before enabling you must fill in your own gmail
credentials in the route below
-
doSendMessages(10, 5);
}
@@ -71,9 +64,10 @@ public class XmppProducerConcurrentTest
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").
-
to("xmpp://talk.google.com:5222/[email protected]?serviceName=gmail.com&user=fromuser&password=secret").
- to("mock:result");
+ from("direct:start")
+ .to("xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"?user=camel_consumer&password=secret&serviceName=apache.camel")
+ .to("mock:result");
}
};
}
Modified:
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
---
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
(original)
+++
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
Mon Aug 27 07:10:10 2012
@@ -19,7 +19,6 @@ package org.apache.camel.component.xmpp;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -32,10 +31,8 @@ public class XmppRouteChatTest extends C
protected String body1 = "the first message";
protected String body2 = "the second message";
- @Ignore
@Test
public void testXmppChat() throws Exception {
- // TODO: requires online against jabber. Test this manually
consumerEndpoint = context.getEndpoint("mock:out1",
MockEndpoint.class);
producerEndpoint = context.getEndpoint("mock:out2",
MockEndpoint.class);
@@ -44,9 +41,11 @@ public class XmppRouteChatTest extends C
//will send chat messages to the consumer
template.sendBody("direct:toConsumer", body1);
+ Thread.sleep(50);
template.sendBody("direct:toConsumer", body2);
template.sendBody("direct:toProducer", body1);
+ Thread.sleep(50);
template.sendBody("direct:toProducer", body2);
consumerEndpoint.assertIsSatisfied();
@@ -74,11 +73,12 @@ public class XmppRouteChatTest extends C
}
protected String getProducerUri() {
- return
"xmpp://jabber.org:5222/[email protected]?user=camel_producer&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]?user=camel_producer&password=secret&serviceName=apache.camel";
}
protected String getConsumerUri() {
- return
"xmpp://jabber.org:5222/[email protected]?user=camel_consumer&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]?user=camel_consumer&password=secret&serviceName=apache.camel";
}
-
}
Modified:
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
---
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
(original)
+++
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
Mon Aug 27 07:10:10 2012
@@ -19,7 +19,6 @@ package org.apache.camel.component.xmpp;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -29,7 +28,6 @@ public class XmppRouteMultipleProducersS
protected MockEndpoint goodEndpoint;
protected MockEndpoint badEndpoint;
- @Ignore
@Test
public void testProducerGetsEverything() throws Exception {
@@ -53,8 +51,6 @@ public class XmppRouteMultipleProducersS
return new RouteBuilder() {
public void configure() throws Exception {
- //getContext().setTracing(true);
-
from("direct:toProducer1")
.to(getProducer1Uri());
@@ -74,15 +70,18 @@ public class XmppRouteMultipleProducersS
}
protected String getProducer1Uri() {
- return
"xmpp://jabber.org:5222/[email protected]?user=camel_producer&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]?user=camel_producer&password=secret&serviceName=apache.camel";
}
protected String getProducer2Uri() {
- return
"xmpp://jabber.org:5222/[email protected]?user=camel_producer1&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]?user=camel_producer1&password=secret&serviceName=apache.camel";
}
protected String getConsumerUri() {
- return
"xmpp://jabber.org:5222/[email protected]?user=camel_consumer&password=secret&serviceName=jabber.org";
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ +
"/[email protected]?user=camel_consumer&password=secret&serviceName=apache.camel";
}
}
Modified:
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
---
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
(original)
+++
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
Mon Aug 27 07:10:10 2012
@@ -27,20 +27,14 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
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.impl.ProducerCache;
import org.jivesoftware.smack.packet.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * 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
- */
+
+
public class XmppRouteTest extends TestCase {
protected static boolean enabled;
protected static String xmppUrl;
@@ -60,24 +54,13 @@ public class XmppRouteTest extends TestC
}
public void testXmppRouteWithTextMessage() throws Exception {
- if (isXmppServerPresent()) {
- String expectedBody = "Hello there!";
- sendExchange(expectedBody);
-
- Object body = assertReceivedValidExchange();
- assertEquals("body", expectedBody, body);
+ String expectedBody = "Hello there!";
+ sendExchange(expectedBody);
- //Thread.sleep(100000);
- }
+ Object body = assertReceivedValidExchange();
+ assertEquals("body", expectedBody, body);
}
- 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() {
public void process(Exchange exchange) {
@@ -109,39 +92,34 @@ public class XmppRouteTest extends TestC
protected void setUp() throws Exception {
client = new ProducerCache(this, container, 10);
- if (isXmppServerPresent()) {
- String uriPrefix = getUriPrefix();
- final String uri1 = uriPrefix +
"&resource=camel-test-from&nickname=came-test-from";
- final String uri2 = uriPrefix +
"&resource=camel-test-to&nickname=came-test-to";
- final String uri3 = uriPrefix +
"&resource=camel-test-from-processor&nickname=came-test-from-processor";
- LOG.info("Using URI " + uri1 + " and " + uri2);
-
- endpoint = container.getEndpoint(uri1);
- assertNotNull("No endpoint found!", endpoint);
-
- // lets add some routes
- container.addRoutes(new RouteBuilder() {
- public void configure() {
- from(uri1).to(uri2);
- from(uri3).process(new Processor() {
- public void process(Exchange e) {
- LOG.info("Received exchange: " + e);
- receivedExchange = e;
- latch.countDown();
- }
- });
- }
- });
- }
+ String uriPrefix = getUriPrefix();
+ final String uri1 = uriPrefix +
"&resource=camel-test-from&nickname=came-test-from";
+ final String uri2 = uriPrefix +
"&resource=camel-test-to&nickname=came-test-to";
+ final String uri3 = uriPrefix +
"&resource=camel-test-from-processor&nickname=came-test-from-processor";
+ LOG.info("Using URI " + uri1 + " and " + uri2);
+
+ endpoint = container.getEndpoint(uri1);
+ assertNotNull("No endpoint found!", endpoint);
+
+ // lets add some routes
+ container.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from(uri1).to(uri2);
+ from(uri3).process(new Processor() {
+ public void process(Exchange e) {
+ LOG.info("Received exchange: " + e);
+ receivedExchange = e;
+ latch.countDown();
+ }
+ });
+ }
+ });
container.start();
}
protected String getUriPrefix() {
- if (xmppUrl != null) {
- return xmppUrl;
- }
- return System.getProperty("xmpp.url",
"xmpp://camel@localhost/?login=false&room=").trim();
+ return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort() +
"/camel?login=false&room=camel-anon";
}
@Override
Added: camel/trunk/components/camel-xmpp/src/test/resources/xmppServer.jks
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/resources/xmppServer.jks?rev=1377585&view=auto
==============================================================================
Binary file - no diff available.
Propchange: camel/trunk/components/camel-xmpp/src/test/resources/xmppServer.jks
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: camel/trunk/parent/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1377585&r1=1377584&r2=1377585&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Mon Aug 27 07:10:10 2012
@@ -193,6 +193,7 @@
<testng-version>6.0.1</testng-version>
<twitter4j-version>2.2.5</twitter4j-version>
<velocity-version>1.7</velocity-version>
+ <vysper-version>0.7</vysper-version>
<woodstox-version>4.1.4</woodstox-version>
<xbean-spring-version>3.5</xbean-spring-version>
<xml-resolver-version>1.2</xml-resolver-version>