Hi Anton,

The Camel context beans managed by Camel CDI are automatically instantiated and 
started when the container is bootstrapped. Hence all the routes bound to them 
are started by default as well. And that’s the behaviour you get with the Camel 
CDI test runner as well.

If your need is to have your application routes (non-test routes) not started 
by default, one alternative is to customise the Camel context by setting the 
autoStartup property to false, e.g.:


@ApplicationScoped
public class ManualStartupCamelContext extends DefaultCamelContext {

    @PostConstruct
    void postConstruct() {
        setAutoStartup(false);
    }
}

If your need is to be able to perform some testing logic before the routes have 
started in your test class, to add some advices for example, you could declare 
an observer method in your test class for the CamelContextStartingEvent, e.g.:

void advice(@Observes CamelContextStartingEvent event, ModelCamelContext 
context) throws Exception {
        context.getRouteDefinition("route")
            .adviceWith(context, new AdviceWithRouteBuilder() {
                @Override
                public void configure() {
                    weaveAddLast().to("mock:messages");
                }
            });
    }

So that depends on what exactly is your need for not having your application 
routes started.

Let me know if that does not meet your need.

Antonin

> On 31 May 2016, at 20:07, Anton <[email protected]> wrote:
> 
> Hello
> 
> I have several unit tests that are annotated
> with @RunWith(org.apache.camel.test.cdi.CamelCdiRunner.class) and also
> inject
> 
> @Inject
> @ContextName("camel-test-cdi")
> CamelContext context;
> 
> I do not inject any non-test routes, yet, when I run the tests the routes
> start.
> 
> How is it possible to run the tests without the non test routes from
> starting?
> 
> Thanks

Reply via email to