Camel XML路由测试(建议使用)

myzjeezk  于 2022-11-29  发布在  Apache
关注(0)|答案(1)|浏览(167)

在我的项目中,我已经声明了XML路由。我只想用adviceWith方法测试它,但是我无法加载该XML路由的路由构建器。我如何告诉Spring测试,我想测试XML路由?
XML路由定义:

<route xmlns="http://camel.apache.org/schema/spring" id="ww-inbound" streamCache="true">
    <from uri="{{ww.mail.server}}?username={{ww.mail.username}}&amp;password={{ww.mail.password}}&amp;unseen=true&amp;delay={{ww.mail.consumer.delay}}"/>
    <log message="Some entry logging"/>

    <process ref="inbound.IntegrationHeaders"/>
    <process ref="inbound.Converter"/>

    <bean ref="inbound.Translator" method="translate"/>
    <to uri="file://{{ww.incoming.fs.slug}}?fileName=${in.header.INT_MESSAGE_ID}.message.json"/>
    <removeHeaders pattern="*" excludePattern="INT_CORRELATION_ID|INT_MESSAGE_ID"/>

    <log message="Outbound AMQP Message\n
        Queue: {{amqp.main.queue}}
        Headers: ${headers}
        Sender: ${exchangeProperty.SENDER}\n
        Subject: ${exchangeProperty.MESSAGE_SUBJECT}\n
        Receivers: ${exchangeProperty.RECEIVERS}\n
        Body: ${exchangeProperty.BODY}\n
        Attachment count: ${exchangeProperty.ATTACHMENTS_COUNT}"/>
    <to pattern="InOnly" uri="rabbitmq:{{amqp.main.queue}}"/>
</route>

Spring测试如下所示:

import static org.apache.camel.builder.AdviceWith.adviceWith;

class InboundRouteTests extends CamelTestSupport {

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

    @Test
    void doTest() throws Exception {
        RouteDefinition route = context.getRouteDefinition("rot-ww-inbound");

        adviceWith(route, context,
                new AdviceWithRouteBuilder() {
                    @Override
                    public void configure() throws Exception {
                        replaceFromWith("mock:newStart");
                    }
                });

        context.start();

        template.sendBody("mock:newStart", "Some text");
    }

}
mhd8tkvw

mhd8tkvw1#

请参阅adviceWith()呼叫中的路由Id:

adviceWith(context, "ww-inbound", new AdviceWithRouteBuilder() {...});

相关问题