So with the link that was suggested to me i got the unit testing working with the following:
Spring boot 2.4.2 / Apache Camel 3.7.2
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>3.7.2</version>
</dependency>
Unit Testing annotations i needed:
@CamelSpringBootTest
@SpringBootTest // (webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestPropertySource
// TODO: Might need the dirty context here . I have not ran into that issue just yet.
class SampleRouter1Test {
@Autowired
private CamelContext camelContext;
@BeforeEach
public void setUp() throws Exception {
// This is to allow you to test JMS queues by replacing their JMS:Queue: entry
// Also the "Test Router 1" is what ever you named your router via .id().
// AdviceWith.adviceWith(camelContext, "Test Router 1", a -> {
// a.replaceFromWith("direct:start2");
// });
}
@Produce("direct:start")
private ProducerTemplate template;
@EndpointInject("mock:output")
private MockEndpoint mockDone;
@Test
public void t1() throws Exception {
template.sendBodyAndHeaders("Testing", new HashMap<>());
mockDone.expectedMessageCount(1);
}
}
I didn't need anything else to autowire spring beans with the above. Also noticed if you have more JMS Routes, you will probably need to change their entries to keep from having to enable ActiveMQ (or which ever jms client).
Sample Router:
@Component
public class SampleRouter1 extends RouteBuilder {
@Autowired
private SampleProcessor1 sampleProcessor1;
@Override
public void configure() throws Exception {
from("direct:start")
.id("Test Router 1")
.log("Direct Start Init")
.process(sampleProcessor1)
.to("mock:output");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…