I am trying to get a sample setup doing a unit test on a very basic route and all the entries I've tried so far do not get me the CamelContext to be auto wired.
I have this for my route and following is the unit test.
public class SampleRouter1 extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:start") // a real entry will be jms:queue:testqueue
.log("Direct Start Init")
.process(new SampleProcessor1())
.to("mock:output");
}
}
unit test
@RunWith(CamelSpringBootRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
public class SampleRouter1Test1 {
@Autowired
protected CamelContext camelContext; // never gets wired in
edited to add that i am autowiring the context in UT.
Exception on running unit test is: qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
also question is, is this meant to test the SampleRouter or do you just unit test the process class and any other supporting classes? or do you use the following to change it so you can pass a message to the fake direct queue?
AdviceWith.adviceWith(camelContext, "jms:queue:testqueue", a -> { a.replaceFromWith("direct:start"); });