Versions Compared

Key

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

...

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
public class CamelCdiRunnerTestCamelCdiTest {

    @Inject
    CamelContext context;

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

...

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
public class CamelCdiRunnerTestCamelCdiTest {

    @Test
    public void test(@Uri("direct:foo") ProducerTemplate producer) {
        producer.sendBody("bar");
    }
}

...

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
public class CamelCdiRunnerTestCamelCdiTest {
 
    @Test
    @Order(1)
    public void firstTestMethod() {
    }
 
    @Test
    @Order(2)
    public void secondTestMethod() {
    }
}

...

Code Block
languagejava
@ApplicationScoped
@RunWith(CamelCdiRunner.class)
public class CamelCdiRunnerTestCamelCdiTest {
 
    int counter;

    @Test
    @Order(1)
    public void firstTestMethod() {
        counter++;
    }
 
    @Test
    @Order(2)
    public void secondTestMethod() {
        assertEquals(counter, 1);
    }
}

 

In case you need to add additional test beans, you can use the @Beans annotation provided by Camel CDI test. For example, if you need to add a route to your Camel context, instead of declaring a RouteBuilder bean with a nested class, you can declare a managed bean, e.g.:

Code Block
languagejava
class TestRoute extends RouteBuilder {

    @Override
    public void configure() {
        from("direct:foo").to("mock:bar");
    }
}

And add it with the @Beans annotation, e.g.:

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
@Beans(classes = TestRoute.class)
public class CamelCdiTest {

}

Arquillian

With this approach, you use the JUnit runner or TestNG support provided by Arquillian to delegate the bootstrap of the CDI container. You need to declare a @Deployment method to create your application configuration to be deployed in the container using ShrinkWrap descriptors, e.g.:

...