Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Camel Test

As a simple alternative to using Spring Testing or Guice the camel-test module was introduced into the Camel 2.0 trunk so you can perform powerful Testing of your Enterprise Integration Patterns easily.

Adding to your pom.xml

To get started using Camel Test you will need to add an entry to your pom.xml

Code Block
xml
xml

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-spring-javaconfig</artifactId>
  <version>${camel-version}</version>
  <scope>test</scope>
</dependency>

You might also want to add commons-logging and log4j to ensure nice logging messages (and maybe adding a log4j.properties file into your src/test/resources directory).

Code Block
xml
xml

<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <scope>test</scope>
</dependency>

Writing your test

You firstly need to derive from the class CamelTestSupport and typically you will need to override the createRouteBuilder() method to create routes to be tested.

Here is an example.

Wiki Markup
{snippet:lang=java|id=example|url=activemq/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java}

JNDI

Camel uses a Registry to allow you to configure Component or Endpoint instances or Beans used in your routes. If you are not using Spring or OSGi then JNDI is used as the default registry implementation.

So you will also need to create a jndi.properties file in your src/test/resources directory so that there is a default registry available to initialise the CamelContext.

Here is an example jndi.properties file

Code Block

java.naming.factory.initial = org.apache.camel.util.jndi.CamelInitialContextFactory

...