I have following endpoints and route.
@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;
}
And
from("cxf:bean:requestEndpoint")
//Custom logic with various outbound routes
.choice()
....
.to("direct:route1")
....
.to("direct:route2")
I want to test it. Various input data should be routed to various route.
@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();
}
}
But in this case i have following error:
Caused by: java.net.ConnectException: ConnectException invoking http://myurl: Connection refused (Connection refused)
this is logical, I did not run the application.
Then i try to replace cxf endpoint to mock:
MockEndpoint mockEndpoint = getMockEndpoint("mock:cxf:bean:requestEndpoint");
producerTemplate.sendBody(mockEndpoint, bodyForRoute1);
And i got
Asserting: mock://direct:route1 is satisfied - FAILED
and exception (java.lang.AssertionError: mock://direct:route1 Received message count. Expected: <1> but was: <0> ), because my route code was not invoked.
How to properly test the route? I would like to try two interesting ways:
1) Test with real http endpoint (this allows you to test the early phases of request - for example - requests with invalid xml)
2) Isolated test when the POJO payload is in the message body.
I would be grateful if there was a solution to my problem