[英]apache camel route testing
I have written a test case for an apache camel route below,我在下面为 apache 骆驼路线编写了一个测试用例,
I believe this only tests message transfer from SEDA send endpoint to mock endpoint, but may not test prism camel route.我相信这只测试从 SEDA 发送端点到模拟端点的消息传输,但可能不会测试棱镜骆驼路由。 want to see if how to mock the actual endpoint - if possible.
想看看如何模拟实际端点 - 如果可能的话。
package com.sams;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import com.sams.pricing.prism.data.processor.util.Endpoints;
public class CamelRouteTests extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(Endpoints.SEDA_SEND_ENDPOINT)
.to("mock:" + Endpoints.SEDA_PROCESS_ENDPOINT);
}
};
}
@Test
public void testRoute() throws Exception {
// Set up the expectations for the mock endpoint
getMockEndpoint("mock:" + Endpoints.SEDA_PROCESS_ENDPOINT).expectedMessageCount(1);
// Send a message to the seda:sendMessage endpoint
template.sendBody("seda:sendMessage", "test message");
// Verify that the mock endpoint expectations are met
assertMockEndpointsSatisfied();
}
}
// SEDA Endpoint Stage Event Driven Architecture
from(Endpoints.SEDA_SEND_ENDPOINT)
.messageHistory()
// Route Name
.routeId(Endpoints.SEDA_SEND_ENDPOINT)
.log("${body}")
// multicast
.multicast()
.parallelProcessing() // create parellel threads
.log("${body}")
// thread pool
.threads()
.executorService(executorService) // specific thread pool
.log("Camel Route Started Message Processing : - ${body}")
// content based routing
.choice()
.when(
CommonUtility
.costIQPredicate) // predicate checking based on the header value to decide the
// route
// .bean(CostIQService.class, "calculatePrice") // // rules engine call
.bean(CostIQPayloadTransformer.class, "payloadTransformer") // payload transformer
// multiple consumer
.to(
Endpoints.SEDA_PROCESS_ENDPOINT, // consumer 1
Endpoints.SEDA_PROCESS_ENDPOINT, // consumer 2
Endpoints.SEDA_PROCESS_ENDPOINT) // consumer 3
.when(CommonUtility.optimizationPredicate)
.bean(OptimizationService.class, "calculatePrice")
.bean(CostIQPayloadTransformer.class, "payloadTransformer")
.to(
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT)
.when(CommonUtility.markDownPredicate)
.bean(MarkDownService.class, "calculatePrice")
.bean(CostIQPayloadTransformer.class, "payloadTransformer")
.to(
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT)
.when(CommonUtility.pricingPredicate)
.bean(PricingService.class, "calculatePrice")
.bean(CostIQPayloadTransformer.class, "payloadTransformer")
.to(
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT,
Endpoints.SEDA_PROCESS_ENDPOINT)
.log("Final :- ${body}")
.end();
}
Where SEDA_SEND_ENDPOINT = "seda:sendMessage?blockWhenFull=true&concurrentConsumers=100"其中 SEDA_SEND_ENDPOINT = "seda:sendMessage?blockWhenFull=true&concurrentConsumers=100"
and SEDA_PROCESS_ENDPOINT = "seda:processMessage?blockWhenFull=true"和 SEDA_PROCESS_ENDPOINT = "seda:processMessage?blockWhenFull=true"
Have tried to look up mocking but could not find a solution as that would not test the actual camel route.试图查找模拟但找不到解决方案,因为这不会测试实际的骆驼路线。
I don't think you need to override createRouteBuilder()
in your Test class.我认为您不需要在 Test 类中重写
createRouteBuilder()
。 But in your test, you do need to tell Camel to mock the endpoints you're interested in:但是在您的测试中,您确实需要告诉 Camel 模拟您感兴趣的端点:
AdviceWith.adviceWith(context, Endpoints.SEDA_PROCESS_ENDPOINT, a -> {
a.mockEndpoints(Endpoints.SEDA_PROCESS_ENDPOINT));
});
Then.然后。 you could do
你可以做
getMockEndpoint("mock:" + Endpoints.SEDA_PROCESS_ENDPOINT)...
See this about mocking existing endpoints .请参阅有关模拟现有端点的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.