You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Testing is a crucial part of any development or integration work. In case you're using the Camel CDI integration for your applications, you have a number of options to ease testing.

You can use CDI for IoC and the Camel testing endpoints like DataSetMockTest and testing API like AdviceWith and NotifyBuilder to create sophisticated integration/unit tests that are easy to run and debug inside your IDE.

There are two supported approaches for testing with CDI in Camel:

NameTesting Frameworks SupportedDescription
Camel CDI Test
  • JUnit 4

The Camel CDI test module ({{camel-test-cdi}}) comes with a JUnit that you can use to delegate all

Arquillian
  • JUnit 4
  • TestNG 5
Arquillian is a testing platform that handles all the plumbing of in-container testing with support for a wide range a target runtime

Camel CDI Test

With this approach, your test classes use the JUnit runner provided in Camel CDI test. This runner manages the lifecycle of a standalone CDI container and deploys the test class as a CDI bean so that dependency injection and any CDI features is available within the test class.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-cdi</artifactId>
    <scope>test</test>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>



Arquillian


@RunWith(Arquillian.class)
public class CdiPropertiesTest {

    @Deployment
    public static Archive deployment() {
        return ShrinkWrap.create(JavaArchive.class)
            // Camel CDI
            .addPackage(CdiCamelExtension.class.getPackage())
            // Test classes
            .addPackage(Application.class.getPackage())
            // Bean archive deployment descriptor
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    }
 
    @Inject
    CamelContext context;

    @Test
    public void testContext() {
        assertThat("Camel context status is incorrect!", context.getStatus(), is(equalTo(ServiceStatus.Started)));
    }
}
  • No labels