Versions Compared

Key

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

...

Name

Testing Frameworks Supported

Description

Required Camel Test Dependencies

CamelSpringTestSupport

  • JUnit 3.x (deprecated)
  • JUnit 4.x
  • TestNG - Camel 2.8

Provided by:

  • org.apache.camel.test.CamelSpringTestSupport
  • org.apache.camel.test.junit4.CamelSpringTestSupport
  • org.apache.camel.testng.CamelSpringTestSupport

These base classes provide feature parity with the simple CamelTestSupport classes from Camel Test but do not support Spring annotations on the test class such as @Autowired@DirtiesContext, and @ContextConfiguration.

  • JUnit 3.x (deprecated) - camel-test-spring
  • JUnit 4.x - camel-test-spring
  • TestNG - camel-test-ng

Plain Spring Test

  • JUnit 3.x
  • JUnit 4.x
  • TestNG

Either extend the abstract base classes:

  • org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests
  • org.springframework.test.context.junit38.AbstractJUnit4SpringContextTests
  • etc.

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:

  • org.apache.camel.test.CamelTestSupport
  • org.apache.camel.test.junit4.CamelTestSupport
  • org.apache.camel.testng.CamelSpringTestSupport
  • JUnit 3.x (deprecated) - None
  • JUnit 4.x - None
  • TestNG - None

Camel Enhanced Spring Test

  • JUnit 4.x - Camel 2.10
  • TestNG - Camel 2.10

Either:

  • use the org.apache.camel.test.junit4.CamelSpringJUnit4ClassRunner runner with the @RunWith annotation,
  • or extend org.apache.camel.testng.AbstractCamelTestNGSpringContextTests to enable feature parity with org.apache.camel.test.CamelTestSupport and org.apache.camel.test.junit4.CamelTestSupport. These classes support the full suite of Spring Test annotations such as @Autowired@DirtiesContext, and @ContextConfiguration.

JUnit 3.x (deprecated) - camel-test-spring

JUnit 4.x - camel-test-spring

TestNG - camel-test-ng

...

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}
Notice that we use @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}
This test will load a Spring XML configuration file calledFilterTestfile called 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

org.apache.camel.test.spring.DisableJmx

Class

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

org.apache.camel.test.spring.ExcludeRoutes

Class

Indicates if certain route builder classes should be excluded from discovery.  Initializes a org.apache.camel.spi.PackageScanClassResolver to exclude a set of given classes from being resolved. Typically this is used at test time to exclude certain routes, which might otherwise be just noisy, from being discovered and initialized.

Not enabled and no routes are excluded

No routes are excluded

org.apache.camel.test.spring.LazyLoadTypeConverters (Deprecated)

Class

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

org.apache.camel.test.spring.MockEndpoints

Class

Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is "*" which matches all endpoints.  See org.apache.camel.impl.InterceptSendToMockEndpointStrategy for more details on the registration of the mock endpoints.

Not enabled

All endpoints are sniffed and recorded in a mock endpoint.

org.apache.camel.test.spring.MockEndpointsAndSkip

Class

Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is "*", which matches all endpoints.  See org.apache.camel.impl.InterceptSendToMockEndpointStrategy for more details on the registration of the mock endpoints.  This annotation will also skip sending the message to matched endpoints as well.

Not enabled

All endpoints are sniffed and recorded in a mock endpoint.  The original endpoint is not invoked.

org.apache.camel.test.spring.ProvidesBreakpoint

Method

Indicates that the annotated method returns an org.apache.camel.spi.Breakpoint for use in the test.  Useful for intercepting traffic to all endpoints or simply for setting a break point in an IDE for debugging.  The method must be public, static, take no arguments, and return org.apache.camel.spi.Breakpoint.

N/A

The returned Breakpoint is registered in the CamelContext(s)

org.apache.camel.test.spring.ShutdownTimeout

Class

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

org.apache.camel.test.spring.UseAdviceWith

Class

Indicates the use of adviceWith() within the test class.  If a class is annotated with this annotation and UseAdviceWith#value() returns true, any CamelContexts bootstrapped during the test through the use of Spring Test loaded application contexts will not be started automatically. 

The test author is responsible for injecting the Camel contexts into the test and executing CamelContext#start() on them at the appropriate time after any advice has been applied to the routes in the CamelContext(s).

CamelContexts do not automatically start.

CamelContexts do not automatically start.

org.apache.camel.test.spring.UseOverridePropertiesWithPropertiesComponentMethodCamel 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

...