我需要为 Apache 骆驼路线编写 JUNIT
I need to write JUNIT for Apache camel route
我有如下骆驼路线
public class IncomingBatchFileRoute extends RouteBuilder {
@Value(CCS_PROCESSING_INCOMING_DIRECTORY)
private String source;
@Override
public void configure() throws Exception {
from(sourceLocation)).autoStartup(false).to("encryptionEndPoint");
}
}
我需要为上面的骆驼路线编写一个 JUNIT,我是新手,并创建了如下结构
public class IncomingBatchFileRouteTest extends CamelTestSupport{
@Override
public RoutesBuilder createRouteBuilder() throws Exception {
return new IncomingBatchFileRoute();
}
@Test
public void sampleMockTest() {
}
}
不确定如何完成。请你帮我解决这个问题
您需要模拟您的 encryptionEndPoint 并使用 producerTemplate 开始您的路由
@Produce(uri = CCS_PROCESSING_INCOMING_DIRECTORY)
protected ProducerTemplate template;
@EndpointInject(uri = "encryptionEndPoint")
protected MockEndpoint resultEndpoint;
@Test
public void sampleMockTest() {
// GIVEN
this.resultEndpoint.expectedMessageCount(1);
// WHEN
this.template.sendBody("Hey");
// THEN
this.resultEndpoint.assertIsSatisfied();
}
我有如下骆驼路线
public class IncomingBatchFileRoute extends RouteBuilder {
@Value(CCS_PROCESSING_INCOMING_DIRECTORY)
private String source;
@Override
public void configure() throws Exception {
from(sourceLocation)).autoStartup(false).to("encryptionEndPoint");
}
}
我需要为上面的骆驼路线编写一个 JUNIT,我是新手,并创建了如下结构
public class IncomingBatchFileRouteTest extends CamelTestSupport{
@Override
public RoutesBuilder createRouteBuilder() throws Exception {
return new IncomingBatchFileRoute();
}
@Test
public void sampleMockTest() {
}
}
不确定如何完成。请你帮我解决这个问题
您需要模拟您的 encryptionEndPoint 并使用 producerTemplate 开始您的路由
@Produce(uri = CCS_PROCESSING_INCOMING_DIRECTORY)
protected ProducerTemplate template;
@EndpointInject(uri = "encryptionEndPoint")
protected MockEndpoint resultEndpoint;
@Test
public void sampleMockTest() {
// GIVEN
this.resultEndpoint.expectedMessageCount(1);
// WHEN
this.template.sendBody("Hey");
// THEN
this.resultEndpoint.assertIsSatisfied();
}