Versions Compared

Key

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

...

Code Block
languagejava
public class Application {

    @ContextName("camel-test-cdi")
    static class Hello extends RouteBuilder {

        @Override
        public void configure() {
            from("direct:in").bean("bean").to("direct:out");
        }
    }
}

And the corresponding bean:

...

It is recommended to only advice routes which are not started already. To meet that requirement, you can use the CamelContextStartingEvent event by declaring an observer method in which you use adviceWith to add a mock endpoint at the end of your Camel route, e.g.:

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
public class CamelCdiTest {
 
    void advice(@Observes CamelContextStartingEvent event,
                @Uri("mock:test") MockEndpoint messages,
                ModelCamelContext context) throws Exception {

        context.getRouteDefinition("route")
            .adviceWith(context, new AdviceWithRouteBuilder() {
                @Override
                public void configure() {
                    weaveAddLast().to("mock:test");
                }
            });
    }
}

JUnit rules

Camel CDI test starts the CDI container after all the JUnit class rules have executed.

...