且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

测试休息端点 - Camel 3 + Spring Boot

更新时间:2023-01-15 11:39:26

如果你想在 Camel 路由测试中模拟这个调用,你可以使用 AdviceWith.

If you want to mock this call in a Camel route test, you can use AdviceWith.

1) 向要模拟的路线步骤添加标识符/标记

1) Add an identifier/marker to the route step you want to mock

.toD("{{my.applications.url}}?throwExceptionOnFailure=false").id("RequestToMock")

2) 然后使用 AdviceWith 用别的东西替换标记的步骤

2) Then use AdviceWith to replace the marked step with something else

context.getRouteDefinition("yourRouteId").adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveById("RequestToMock") // <-- same identifier
                    .replace()
                    .setBody(simple("resource:classpath:TestResponse.json"));
        }
    });

3) 告诉 Camel 您的测试使用 AdviceWith(取决于您的测试类型)

3) Tell Camel that your test uses AdviceWith (depending what type of test you have)

@UseAdviceWith // for Spring Boot tests

@Override
public boolean isUseAdviceWith() { // for CamelTestSupport
    return true;
}