[英]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.