Author: davsclaus
Date: Thu Dec 29 15:55:30 2011
New Revision: 1225578
URL: http://svn.apache.org/viewvc?rev=1225578&view=rev
Log:
CAMEL-4814: Use dynamic ports for unit testing examples. Removed AOP part of
this example as its just confusing a bit more.
Added:
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel.properties
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientRemotingServerTest.java
- copied, changed from r1225475,
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
Removed:
camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/AuditTracker.java
camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server-aop.xml
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsAOPClientServerTest.java
Modified:
camel/trunk/examples/camel-example-spring-jms/README.txt
camel/trunk/examples/camel-example-spring-jms/pom.xml
camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/ServerRoutes.java
camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel-client-remoting.xml
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
Modified: camel/trunk/examples/camel-example-spring-jms/README.txt
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/README.txt?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-spring-jms/README.txt (original)
+++ camel/trunk/examples/camel-example-spring-jms/README.txt Thu Dec 29
15:55:30 2011
@@ -8,11 +8,6 @@ with the received message.
The Server is required to be running when you try the clients.
-The Server comes in two flavors:
-- Normal that acts as a JMS broker
-- As normal plus an AOP aspect that does audit trails of the invocation
-of the business service and uses Camel for mediation of the storage of the
audit message.
-
And for the Client we have a total of three flavors:
- Normal use the ProducerTemplate ala Spring Template style
- Using Spring Remoting for powerful "Client doesn't know at all its a remote
call"
@@ -23,7 +18,6 @@ You will need to compile this example fi
The example should run if you type:
mvn exec:java -PCamelServer
- mvn exec:java -PCamelServerAOP
mvn exec:java -PCamelClient
mvn exec:java -PCamelClientRemoting
@@ -45,6 +39,3 @@ have. Enjoy!
------------------------
The Camel riders!
-
-
-
Modified: camel/trunk/examples/camel-example-spring-jms/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/pom.xml?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-spring-jms/pom.xml (original)
+++ camel/trunk/examples/camel-example-spring-jms/pom.xml Thu Dec 29 15:55:30
2011
@@ -66,30 +66,6 @@
</dependency>
<!-- END SNIPPET: e2 -->
- <!-- START SNIPPET: e3 -->
- <!-- required jars for aspectj AOP support -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.6.2</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.6.2</version>
- </dependency>
- <dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib-nodep</artifactId>
- <version>2.1_3</version>
- </dependency>
- <!-- END SNIPPET: e3 -->
-
<!-- for logging using log4j.properties in src/main/resources -->
<dependency>
<groupId>org.slf4j</groupId>
@@ -106,6 +82,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -119,14 +100,6 @@
</properties>
</profile>
<profile>
- <id>CamelServerAOP</id>
- <properties>
- <!-- we use Camel spring Main class as the server got all what
it needs to start in the camel-server-aop.xml file -->
-
<target.main.class>org.apache.camel.spring.Main</target.main.class>
- <target.cmd.args>-ac
META-INF/spring/camel-server-aop.xml</target.cmd.args>
- </properties>
- </profile>
- <profile>
<id>CamelClient</id>
<properties>
<!-- we start using our own class to control what we do in the
main -->
@@ -149,6 +122,7 @@
</profile>
</profiles>
<build>
+
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@@ -173,28 +147,18 @@
</executions>
</plugin>
- <!-- Allows the example to be run via 'mvn compile exec:java' -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <configuration>
- <mainClass>${target.main.class}</mainClass>
-
<includePluginDependencies>false</includePluginDependencies>
- <commandlineArgs>${target.cmd.args}</commandlineArgs>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkMode>pertest</forkMode>
- <childDelegation>false</childDelegation>
- <useFile>true</useFile>
- <includes>
- <include>**/*Test.*</include>
- </includes>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <!-- Allows the example to be run via 'mvn compile exec:java' -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <configuration>
+ <mainClass>${target.main.class}</mainClass>
+ <includePluginDependencies>false</includePluginDependencies>
+ <commandlineArgs>${target.cmd.args}</commandlineArgs>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
</project>
Modified:
camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/ServerRoutes.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/ServerRoutes.java?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/ServerRoutes.java
(original)
+++
camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/ServerRoutes.java
Thu Dec 29 15:55:30 2011
@@ -38,11 +38,11 @@ public class ServerRoutes extends RouteB
// as above but with the bean: prefix
//from("jms:queue:numbers").to("bean:multiplier");
- // beanRef is using explicity bean bindings to lookup the multiplier
bean and invoke the multiply method
+ // beanRef is using explicit bean bindings to lookup the multiplier
bean and invoke the multiply method
//from("jms:queue:numbers").beanRef("multiplier", "multiply");
// the same as above but expressed as a URI configuration
-
//from("activemq:queue:numbers").to("bean:multiplier?methodName=multiply");
+ //from("jms:queue:numbers").to("bean:multiplier?methodName=multiply");
}
}
Modified:
camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml
(original)
+++
camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml
Thu Dec 29 15:55:30 2011
@@ -34,6 +34,10 @@
<context:component-scan base-package="org.apache.camel.example.server"/>
<!-- END SNIPPET: e2 -->
+ <!-- spring property placeholder, ignore resource not found as the file
resource is for unit testing -->
+ <context:property-placeholder
location="classpath:camel.properties,file:target/custom.properties"
+ ignore-resource-not-found="true"/>
+
<!-- START SNIPPET: e3 -->
<!-- declare a camel context that scans for classes that is RouteBuilder
in the package org.apache.camel.example.server -->
@@ -49,15 +53,18 @@
<!-- lets configure the ActiveMQ JMS broker server to listen on TCP 61610 -->
<broker:broker useJmx="true" persistent="false" brokerName="myBroker">
<broker:transportConnectors>
- <broker:transportConnector name="tcp" uri="tcp://localhost:61610"/>
+ <!-- expose a VM transport for in-JVM transport between AMQ and Camel on
the server side -->
+ <broker:transportConnector name="vm" uri="vm://myBroker"/>
+ <!-- expose a TCP transport for clients to use -->
+ <broker:transportConnector name="tcp" uri="tcp://localhost:${tcp.port}"/>
</broker:transportConnectors>
</broker:broker>
<!-- END SNIPPET: e4 -->
<!-- START SNIPPET: e5 -->
- <!-- lets configure the Camel ActiveMQ to use the ActiveMQ broker declared
above -->
+ <!-- lets configure the Camel ActiveMQ to use the embedded ActiveMQ broker
declared above -->
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="brokerURL" value="tcp://localhost:61610"/>
+ <property name="brokerURL" value="vm://myBroker"/>
</bean>
<!-- END SNIPPET: e5 -->
Modified:
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel-client-remoting.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel-client-remoting.xml?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel-client-remoting.xml
(original)
+++
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel-client-remoting.xml
Thu Dec 29 15:55:30 2011
@@ -18,11 +18,17 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
+ <!-- spring property placeholder, ignore resource not found as the file
resource is for unit testing -->
+ <context:property-placeholder
location="classpath:camel.properties,file:target/custom.properties"
+ ignore-resource-not-found="true"/>
+
<camel:camelContext id="camel-client-2">
<camel:template id="camelTemplate"/>
<!-- START SNIPPET: e1 -->
@@ -36,7 +42,7 @@
<!-- Camel JMSProducer to be able to send messages to a remote Active MQ
server -->
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="brokerURL" value="tcp://localhost:61610"/>
+ <property name="brokerURL" value="tcp://localhost:${tcp.port}"/>
</bean>
</beans>
\ No newline at end of file
Added:
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel.properties
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel.properties?rev=1225578&view=auto
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel.properties
(added)
+++
camel/trunk/examples/camel-example-spring-jms/src/main/resources/camel.properties
Thu Dec 29 15:55:30 2011
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# properties for the application
+tcp.port=61610
Copied:
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientRemotingServerTest.java
(from r1225475,
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientRemotingServerTest.java?p2=camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientRemotingServerTest.java&p1=camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java&r1=1225475&r2=1225578&rev=1225578&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
(original)
+++
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientRemotingServerTest.java
Thu Dec 29 15:55:30 2011
@@ -16,102 +16,51 @@
*/
package org.apache.camel.example;
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Producer;
-import org.apache.camel.ProducerTemplate;
+import java.io.File;
+import java.io.FileOutputStream;
+
import org.apache.camel.example.server.Multiplier;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.TestSupport;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class SpringJmsClientServerTest extends Assert {
- protected static ConfigurableApplicationContext serverContext;
+public class SpringJmsClientRemotingServerTest extends TestSupport {
+ private static ClassPathXmlApplicationContext appCtx;
+
@BeforeClass
- public static void setUpServer() {
- if
(!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) {
- serverContext = new
ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
- } else {
- System.out.println("Skipping starting CamelContext as system
property skipStartingCamelContext is set to be true.");
- }
-
+ public static void setupFreePort() throws Exception {
+ // find a free port number from 9100 onwards, and write that in the
custom.properties file
+ // which we will use for the unit tests, to avoid port number in use
problems
+ int port = AvailablePortFinder.getNextAvailable(9100);
+ String bank1 = "tcp.port=" + port;
+
+ File custom = new File("target/custom.properties");
+ FileOutputStream fos = new FileOutputStream(custom);
+ fos.write(bank1.getBytes());
+ fos.close();
+
+ appCtx = new
ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml",
"camel-client-remoting.xml");
+ appCtx.start();
}
-
+
@AfterClass
- public static void tearDownServer() {
- if (serverContext != null) {
- serverContext.stop();
- }
+ public static void stopSpring() {
+ appCtx.stop();
}
-
- @Test
- public void testCamelClientInvocation() {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client.xml");
- // get the camel template for Spring template style sending of
messages (= producer)
- ProducerTemplate camelTemplate = context.getBean("camelTemplate",
ProducerTemplate.class);
-
- // as opposed to the CamelClientRemoting example we need to define the
service URI in this java code
- int response = (Integer)camelTemplate.sendBody("jms:queue:numbers",
ExchangePattern.InOut, 22);
-
- assertEquals("Get a wrong response", 66, response);
-
- context.stop();
- }
-
- @Test
- public void testCamelEndpointInvocation() throws Exception {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client.xml");
- CamelContext camel = context.getBean("camel-client",
CamelContext.class);
-
- // get the endpoint from the camel context
- Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");
-
- // create the exchange used for the communication
- // we use the in out pattern for a synchronized exchange where we
expect a response
- Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
- // set the input on the in body
- // must you correct type to match the expected type of an Integer
object
- exchange.getIn().setBody(11);
-
- // to send the exchange we need an producer to do it for us
- Producer producer = endpoint.createProducer();
- // start the producer so it can operate
- producer.start();
-
- // let the producer process the exchange where it does all the work in
this oneline of code
-
- producer.process(exchange);
-
- // get the response from the out body and cast it to an integer
- int response = exchange.getOut().getBody(Integer.class);
-
- assertEquals("Get a wrong response.", 33, response);
-
- // stop and exit the client
- producer.stop();
- context.stop();
- }
-
@Test
public void testCamelRemotingInvocation() {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client-remoting.xml");
// just get the proxy to the service and we as the client can use the
"proxy" as it was
// a local object we are invoking. Camel will under the covers do the
remote communication
// to the remote ActiveMQ server and fetch the response.
- Multiplier multiplier = context.getBean("multiplierProxy",
Multiplier.class);
+ Multiplier multiplier = appCtx.getBean("multiplierProxy",
Multiplier.class);
int response = multiplier.multiply(33);
-
assertEquals("Get a wrong response", 99, response);
-
- context.stop();
}
}
Modified:
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java?rev=1225578&r1=1225577&r2=1225578&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
(original)
+++
camel/trunk/examples/camel-example-spring-jms/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
Thu Dec 29 15:55:30 2011
@@ -16,62 +16,51 @@
*/
package org.apache.camel.example;
-import org.apache.camel.CamelContext;
+import java.io.File;
+import java.io.FileOutputStream;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Producer;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.example.server.Multiplier;
-import org.junit.AfterClass;
-import org.junit.Assert;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class SpringJmsClientServerTest extends Assert {
- protected static ConfigurableApplicationContext serverContext;
-
+public class SpringJmsClientServerTest extends CamelSpringTestSupport {
+
@BeforeClass
- public static void setUpServer() {
- if
(!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) {
- serverContext = new
ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
- } else {
- System.out.println("Skipping starting CamelContext as system
property skipStartingCamelContext is set to be true.");
- }
-
+ public static void setupFreePort() throws Exception {
+ // find a free port number from 9100 onwards, and write that in the
custom.properties file
+ // which we will use for the unit tests, to avoid port number in use
problems
+ int port = AvailablePortFinder.getNextAvailable(9100);
+ String bank1 = "tcp.port=" + port;
+
+ File custom = new File("target/custom.properties");
+ FileOutputStream fos = new FileOutputStream(custom);
+ fos.write(bank1.getBytes());
+ fos.close();
}
-
- @AfterClass
- public static void tearDownServer() {
- if (serverContext != null) {
- serverContext.stop();
- }
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
}
@Test
public void testCamelClientInvocation() {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client.xml");
-
- // get the camel template for Spring template style sending of
messages (= producer)
- ProducerTemplate camelTemplate = context.getBean("camelTemplate",
ProducerTemplate.class);
-
// as opposed to the CamelClientRemoting example we need to define the
service URI in this java code
- int response = (Integer)camelTemplate.sendBody("jms:queue:numbers",
ExchangePattern.InOut, 22);
-
+ int response = template.requestBody("jms:queue:numbers", 22,
Integer.class);
assertEquals("Get a wrong response", 66, response);
-
- context.stop();
}
@Test
public void testCamelEndpointInvocation() throws Exception {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client.xml");
- CamelContext camel = context.getBean("camel-client",
CamelContext.class);
-
// get the endpoint from the camel context
- Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");
+ Endpoint endpoint = context.getEndpoint("jms:queue:numbers");
// create the exchange used for the communication
// we use the in out pattern for a synchronized exchange where we
expect a response
@@ -85,8 +74,7 @@ public class SpringJmsClientServerTest e
// start the producer so it can operate
producer.start();
- // let the producer process the exchange where it does all the work in
this oneline of code
-
+ // let the producer process the exchange where it does all the work in
this one line of code
producer.process(exchange);
// get the response from the out body and cast it to an integer
@@ -94,24 +82,8 @@ public class SpringJmsClientServerTest e
assertEquals("Get a wrong response.", 33, response);
- // stop and exit the client
+ // stop the producer after usage
producer.stop();
- context.stop();
}
- @Test
- public void testCamelRemotingInvocation() {
- ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("camel-client-remoting.xml");
- // just get the proxy to the service and we as the client can use the
"proxy" as it was
- // a local object we are invoking. Camel will under the covers do the
remote communication
- // to the remote ActiveMQ server and fetch the response.
- Multiplier multiplier = context.getBean("multiplierProxy",
Multiplier.class);
-
- int response = multiplier.multiply(33);
-
- assertEquals("Get a wrong response", 99, response);
-
- context.stop();
- }
-
}