[英]Camel Spring Boot CXF endpoint testing
我有以下端点和路由。
@Bean
public CxfEndpoint requestEndpoint() {
CxfEndpoint endpoint = new CxfEndpoint();
endpoint.setAddress(SERVICE_ADDRESS);
endpoint.setServiceClass(Service.class);
endpoint.setWsdlURL(WSDL_LOCATION);
endpoint.setBus(bus);
endpoint.setProperties(endpointProperties);
return endpoint;
}
和
from("cxf:bean:requestEndpoint")
//Custom logic with various outbound routes
.choice()
....
.to("direct:route1")
....
.to("direct:route2")
我要测试一下。 各种输入数据应路由到各种路由。
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints
@Configuration
public class RequestRouteTest extends CamelTestSupport {
@Autowired
private ProducerTemplate producerTemplate;
@EndpointInject(uri = "mock:direct:route1")
private MockEndpoint mockCamel;
@Test
public void myTest() throws Exception {
mockCamel.expectedMessageCount(1);
producerTemplate.sendBody("cxf:bean:requestEndpoint", bodyForRoute1);
mockCamel.assertIsSatisfied();
}
}
但是在这种情况下,我有以下错误:
由以下原因引起:java.net.ConnectException:调用http:// myurl的 ConnectException:连接被拒绝(连接被拒绝)
这是合乎逻辑的,我没有运行该应用程序。
然后,我尝试替换cxf端点进行模拟:
MockEndpoint mockEndpoint = getMockEndpoint("mock:cxf:bean:requestEndpoint");
producerTemplate.sendBody(mockEndpoint, bodyForRoute1);
我得到了
声明:满足模拟://直接:route1-失败
和异常(java.lang.AssertionError:mock:// direct:route1收到的消息数。应为:<1>,但为:<0>),因为未调用我的路由代码。
如何正确测试路线? 我想尝试两种有趣的方法:
1)使用真实的http端点进行测试(这使您可以测试请求的早期阶段-例如-带有无效xml的请求)
2)当POJO有效负载在消息正文中时,进行隔离测试。
如果能解决我的问题,我将不胜感激
您所质疑的路线测试使用Camel测试套件 。 这是对您的骆驼路线(即问题2)进行“单元测试”的好工具。
在这些测试中,由于要测试消息的正确路由,因此通常使用AdviceWith用模拟 代替真实的终结点 。
请参阅@Bedlas注释中的链接答案,以将CXF端点替换为直接端点以使测试正常进行。
如果您想使用真实的端点 (即问题的#1)进行测试,则应考虑使用Citrus之类的集成测试框架。
使用此类框架,您可以针对正在运行的应用程序实例编写测试。 在您的情况下,您将针对正在运行的应用程序的真实CXF端点发送HTTP或SOAP请求,并且根据应用程序的工作,您将有大量的可能性来验证结果(检查JMS队列,数据库条目等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.