我开始使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
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"/> …Run Code Online (Sandbox Code Playgroud)