gpt4 book ai didi

java - 测试 Camel quartz 路线

转载 作者:行者123 更新时间:2023-11-30 07:50:32 25 4
gpt4 key购买 nike

我尝试对 apache Camel 路线进行 junit 测试。像这样:

@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
loader = CamelSpringDelegatingTestContextLoader.class
)
public class MyExportRouteBuilderIT extends CamelTestSupport {
@Test
public void test() {
// trigger and check the files made by route builder processor
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new MyExportRouteBuilder();
}
}

构建器类是这样定义的

from("quartz2://exportJob?cron=" + cronTrigger)
.setHeader(FILE_NAME, expression(FILE_NAME_FORMAT))
.process(myExportRouteProcessor)
.marshal(new BindyCsvDataFormat(MyExportData.class))
.to("file:///destination);

“myExportRouteProcessor”类只是从 JPA 存储库中获取一些数据并将结果放入路由。我想要的是在测试类中触发这个路由来检查整个过程是否正确完成。当前,处理器未被解雇。我还应该做什么?

最佳答案

您可以直接使用 AdviceWithRouteBuilder#replaceFromWith 替换测试中的 quartz2 组件.

@Test
public void test() throws Exception{
//mock input route (replace quartz with direct)
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:triggerQuartz");
}
});

//trigger endpoint
sendBody("direct:triggerQuartz", null);

//do some assertions
}

关于java - 测试 Camel quartz 路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47759037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com