Versions Compared

Key

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

...

In all approaches the test classes look pretty much the same in that they all reuse the Camel binding and injection annotations.

Camel Test Example

Here is the Camel Test 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}

Notice how it derives from the Camel helper class CamelTestSupport but has no Spring or Guice dependency injection configuration but instead overrides the createRouteBuilder() method.

Spring Test with XML Config Example

Here is the Spring Test example using XML Config.

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

Notice the use of @ContextConfiguration to indicate that by default we should look for the FilterTest-context.xml on the classpath to configure the test case which looks like this

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

Spring Test with Java Config Example

Here is the Spring Test example using Java Config.

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

This is similar to the XML Config example above except that there is no XML file and instead the nested ContextConfig class does all of the configuration.

Testing endpoints

Camel provides a number of endpoints which can make testing easier.

...