[英]how start a route in a Camel test with mocked Endpoints
我从Camel开始,在编写测试时遇到一些问题。 我的用例与cfx代理示例完全相同。 除了我不需要“ RealWebservice”。 现在,我尝试使用注释方法编写一个单元测试(而不是示例中包含的集成测试):
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:application-context.xml" })
@MockEndpointsAndSkip
public class RoutesTest {
@Autowired
CamelContext camelContext;
@EndpointInject(uri = "mock:cxf:bean:cxfEndpoint", context = "camelContext")
MockEndpoint cxfEndpoint;
@EndpointInject(uri = "mock:log:input", context = "camelContext")
MockEndpoint logInputEndpoint;
@EndpointInject(uri = "mock:http:realhostname:8211/service", context = "camelContext")
MockEndpoint realEndpoint;
@EndpointInject(uri = "mock:cxf:bean:cxfEndpoint")
ProducerTemplate producer;
@Test
public void testLeleuxMifidRoute() throws InterruptedException {
String body = "<blah/>";
cxfEndpoint.expectedBodiesReceived(body);
logInputEndpoint.expectedBodiesReceived(body);
realEndpoint.expectedBodiesReceived(body);
producer.sendBody(body);
MockEndpoint.assertIsSatisfied(camelContext);
}
}
cxfEndpoint接收到该消息, 但其他端点未收到。
路由如下所示(当我运行它并使用SoapUI发送消息时,它可以工作,显然,在此示例中,我混淆了ips和beannames):
<endpoint id="callRealWebService" uri="http://realhostname:8211/service?throwExceptionOnFailure=true" />
<route>
<from uri="cxf:bean:cxfEndpoint?dataFormat=MESSAGE"/>
<to uri="log:input?showStreams=true"/>
<to ref="callRealWebService"/>
<to uri="log:output"/>
</route>
我究竟做错了什么? 我发现的所有示例和其他问题似乎都使用“ direct:start”或更改生产路线。
我们成功使用的一种方法是为测试执行和主代码提供不同的属性文件。
我们在骆驼上下文中定义属性
<propertyPlaceholder id="properties"
location="classpath:META-INF/uri.properties" xmlns="http://camel.apache.org/schema/spring" />
在文件夹/src/main/resources/META-INF/
我们有uri.properties文件用于主代码,在/src/test/resources/META-INF/
我们具有uri.properties用于测试执行。
必须使用符号{{properties.name}}
使用属性占位符而不是实际uri值来重写路由。
<route>
<from uri="{{cxf.bean.cxfEndpoint}}"/>
</route>
主要的uri.properties将是
cxf.bean.cxfEndpoint=cxf:bean:cxfEndpoint?dataFormat=MESSAGE
测试uri.properties将是
cxf.bean.cxfEndpoint=direct:start
使用此配置,您将能够轻松测试您的路线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.