...
Name | Testing Frameworks Supported | Description | Required Camel Test Dependencies |
---|---|---|---|
|
| Provided by:
These base classes provide feature parity with the simple |
|
Plain Spring Test |
| Either extend the abstract base classes:
provided in Spring Test or use the Spring Test JUnit4 runner. These approaches support both the Camel annotations and Spring annotations. However, they do NOT have feature parity with:
|
|
Camel Enhanced Spring Test |
| Either:
| JUnit 3.x (deprecated) - JUnit 4.x - TestNG - |
...
In this approach, your test classes directly inherit from the Spring Test abstract test classes or use the JUnit 4.x test runner provided in Spring Test. This approach supports dependency injection into your test class and the full suite of Spring Test annotations but . However, it does not support the features provided by the CamelSpringTestSupport
classes.
...
Here is a simple unit test using JUnit 3.x support from Spring Test using XML Config.
Wiki Markup |
---|
{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java} |
@DirtiesContext
on the test methods to force Spring Testing to automatically reload the CamelContext after each test method - this ensures that the tests don't clash with each other (, e.g., one test method sending to an endpoint that is then reused in another test method).Also notice the use of @ContextConfiguration
to indicate that by default we should look for the the file FilterTest-context.xml on the classpath to configure the test case which . The test context looks like this:
Wiki Markup |
---|
{snippet:lang=xml|id=example|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml} |
FilterTest-context.xml
from the classpath in the same package structure as the FilterTest
class and initialize it along with any Camel routes we define inside it, then inject theCamelContextinstance
inject the CamelContext
instance into our test case.For instance, like this maven folder layout:
...
Annotation Class | Applies To | Description | Default Behavioir If Not Present | Default Behavior If Present |
---|---|---|---|---|
|
| Indicates if JMX should be globally disabled in the CamelContexts that are bootstrapped during the test through the use of Spring Test loaded application contexts. | JMX is disabled | JMX is disabled |
|
| Indicates if certain route builder classes should be excluded from discovery. Initializes a | Not enabled and no routes are excluded | No routes are excluded |
|
| Deprecated. Indicates if the CamelContexts that are bootstrapped during the test through the use of Spring Test loaded application contexts should use lazy loading of type converters. | Type converters are not lazy loaded | Type converters are not lazy loaded |
|
| Triggers the auto-mocking of endpoints whose URIs match the provided filter. The default filter is | Not enabled | All endpoints are sniffed and recorded in a mock endpoint. |
|
| Triggers the auto-mocking of endpoints whose URIs match the provided filter. The default filter is | Not enabled | All endpoints are sniffed and recorded in a mock endpoint. The original endpoint is not invoked. |
|
| Indicates that the annotated method returns an | N/A | The returned |
|
| Indicates to set the shutdown timeout of all CamelContexts instantiated through the use of Spring Test loaded application contexts. If no annotation is used, the timeout is automatically reduced to 10 seconds by the test framework. | 10 seconds | 10 seconds |
|
| Indicates the use of The test author is responsible for injecting the Camel contexts into the test and executing | CamelContexts do not automatically start. | CamelContexts do not automatically start. |
org.apache.camel.test.spring.UseOverridePropertiesWithPropertiesComponent | Method | Camel 2.16:Indicates that the annotated method returns a java.util.Properties for use in the test, and that those properties override any existing properties configured on the PropertiesComponent . | Override properties |
...