Next define the class to configure route-
package com.javainuse;
import org.apache.camel.builder.RouteBuilder;
public class SimpleRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("{{route.start}}
").split().tokenize("\n").to("{{route.end}}
");
}
}
Next define the xml configuration which defines the jms and camel context in the main/resources
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">
<bean class="org.apache.activemq.camel.component.ActiveMQComponent"
id="jms">
<property name="connectionFactory" ref="singleCF" />
<property name="useSingleConnection" value="true" />
<property name="usePooledConnection" value="false" />
<property name="preserveMessageQos" value="true" />
</bean>
<bean class="org.springframework.jms.connection.SingleConnectionFactory"
id="singleCF">
<property name="targetConnectionFactory" ref="AMQCF" />
</bean>
<bean class="org.apache.activemq.ActiveMQConnectionFactory" id="AMQCF">
<property name="userName" value="admin" />
<property name="password" value="admin" />
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="simpleRouter" class="com.javainuse.SimpleRouteBuilder" />
<camelContext id="simpleRouterContext" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="placeholder" location="classpath:camel.properties" />
<routeBuilder ref="simpleRouter" />
</camelContext>
</beans>
Define the camel.properties file in main/resources as follows-
route.start=file:C:/inbox?noop=true
route.end=jms:queue:javainuse
Define the main class to load the camel-context and start the route-
package com.javainuse;
import org.apache.camel.CamelContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext springCtx = new ClassPathXmlApplicationContext("camel-context.xml");
CamelContext ctx = springCtx.getBean("simpleRouterContext", CamelContext.class);
try {
ctx.start();
Thread.sleep(5 * 60 * 1000);
ctx.stop();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Now start the ActiveMQ.

and goto
http://localhost:8161/admin/queues.jsp, we will see all no active queues on this page.

Next run the MainApp class as a java application and refresh the above activeMQ page. We will see a new queue named javainuse
is created and it has messages in it.
Next we define the Test class as follows-
We load the camel-context.xml defined in the test/resources folder
Define the mock endpoint and send the message. Also we verify the message count for the test to pass.
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SimpleRouteBuilderTest
extends CamelSpringTestSupport {
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("camel-context.xml");
}
@Test
public void testPayloadIsReached()
throws InterruptedException {
MockEndpoint mockOut = getMockEndpoint("mock:out");
mockOut.setExpectedMessageCount(1);
template.sendBody("direct:in", "this is test");
assertMockEndpointsSatisfied();
}
}
Next define the camel-context in the test/resources folder as follows-
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">
<bean class="org.apache.activemq.camel.component.ActiveMQComponent"
id="jms">
<property name="connectionFactory" ref="singleCF" />
<property name="useSingleConnection" value="true" />
<property name="usePooledConnection" value="false" />
<property name="preserveMessageQos" value="true" />
</bean>
<bean class="org.springframework.jms.connection.SingleConnectionFactory"
id="singleCF">
<property name="targetConnectionFactory" ref="AMQCF" />
</bean>
<bean class="org.apache.activemq.ActiveMQConnectionFactory" id="AMQCF">
<property name="userName" value="admin" />
<property name="password" value="admin" />
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="simpleRouter" class="com.javainuse.SimpleRouteBuilder" />
<camelContext id="simpleRouterContext" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="placeholder" location="classpath:camel.properties" />
<routeBuilder ref="simpleRouter" />
</camelContext>
</beans>
Define the camel.properties in the test/resources for pocking the camel endpointd as follows-
route.start=direct:in
route.end=mock:out
Run the SimpleRouteBuilderTest as a JUnit as follows-
Download Source Code
Download it -
Apache Camel JUnit Testing
See Also
Spring Boot Hello World Application- Create simple controller and jsp view using Maven
Spring Boot Tutorial-Spring Data JPA
Spring Boot + Simple Security Configuration
Pagination using Spring Boot Simple Example
Spring Boot + ActiveMQ Hello world Example
Spring Boot + Swagger Example Hello World Example
Spring Boot + Swagger- Understanding the various Swagger Annotations
Spring Boot Main Menu
Spring Boot Interview Questions