Versions Compared

Key

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

...

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

...

You firstly need to derive from the class CamelTestSupport (org.apache.camel.test.CamelTestSupport, org.apache.camel.test.junit4.CamelTestSupport, or org.apache.camel.testng.CamelTestSupport for JUnit 3.x, JUnit 4.x, and TestNG, respectively) and typically you will need to override the createRouteBuilder() or createRouteBuilders() method to create routes to be tested.

Here is an example.

Wiki Markup
{snippet:lang=java|id=example|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java}
Notice how you can use the various Camel binding and injection annotations to inject individual Endpoint objects - particularly the Mock endpoints which are very useful for Testing. Also you can inject producer objects such as ProducerTemplate or some application code interface for sending messages or invoking services.

...

You may want to do this once, to share the CamelContext between test methods, to speedup unit testing. This requires to use JUnit 4! In your unit test method you have to extend the org.apache.camel.test.junit4.CamelTestSupport or the org.apache.camel.test.junit4.CamelSpringTestSupport test class and override the isCreateCamelContextPerClass method and return true as shown in the following example:

Wiki Markup
{snippet:id=example|lang=java|title=Setup CamelContext once per class|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterCreateCamelContextPerClassTest.java}

See Also

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