【发布时间】:2022-11-28 10:27:53
【问题描述】:
在我的项目中,我声明了 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}}&password={{ww.mail.password}}&unseen=true&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");
}
}
【问题讨论】:
标签: java xml spring apache-camel