我对apache骆驼不熟悉,因此我仍在努力编写骆驼测试用例。
我在下面定义了路线
from("direct:routeToTest")
.id(ROUTE_ID)
.to(LOOK_UP_ROUTE)
.choice()
.when(some-condition)
.choice()
.when(condition)
.to(CREATE_ROUTE)
.otherwise().process(exchange -> exchange.getIn().setBody(prepareResponse(""))
.endChoice()
.otherwise()
.log("Some Issue")
.process(exchange -> unknownError(exchange))
.endChoice();
}
在测试时,我试图拦截我的路线中定义的 to 并对此设置一些模拟响应。因此,经过一些搜索,我发现使用 adviceWith 是实现此目标的正确方法。
所以我的测试如下。测试的结果是,它仍将使用Look_up_route(direct:lookUpRoute,定义的另一条路由)处理通过的数据,但是期望代码将其跳过并将响应设置为“ MockResponse”
@SpringBootTest
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@RunWith(CamelSpringBootRunner.class)
@UseAdviceWith
@MockEndpoints
@DisableJmx(false)
public class RouteTest {
@Autowired
private ProducerTemplate producerTemplate;
@Autowired
private CamelContext context;
@Test
public void testResponseToJSON() throws Exception {
SomeObject someObject = getObject();
context.getRouteDefinition(ROUTE_ID).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint(LOOK_UP_ROUTE)
.skipSendToOriginalEndpoint()
.transform("MockOutput");
}
);
context.start();
Object object = producerTemplate.requestBody(direct:routeToTest, someObject);
}
}
我想知道如何跳过.to(LOOK_UP_ROUTE)并将其设置为micResponse。
答案 0 :(得分:0)
您的intercept陈述一见钟情。但是,请查看此答案以找到另一种方法。
您必须
id