我已经为下面的apache camel路径编写了一个测试用例,
我相信这只测试从SEDA发送端点到模拟端点的消息传输,但可能不会测试棱镜 Camel 路由。想看看是否如何模拟实际端点-如果可能的话。
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();
}
其中,SEDA_SEND_ENDPOINT ="seda:发送消息?块满时=真且并发使用者= 100"
并且SEDA_PROCESS_ENDPOINT ="已满时,seda:处理消息?块=真"
曾试图查找嘲笑,但无法找到解决方案,因为这不会测试实际的 Camel 路线。
1条答案
按热度按时间mitkmikd1#
我认为您不需要在Test类中覆盖
createRouteBuilder()
,但在测试中,您需要让Camel模拟您感兴趣的端点:那你可以
请参阅有关模拟现有端点的内容。