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