...
As a simple alternative to using CDI Testing, Spring 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} |
...
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 |