George96
George96

Reputation: 13

Simple Camel test fails with no messages recieved

Am using Spring Boot and I have just added camel to it.

I have a simple camel route setup :

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("file://in").to("file://out");  
  }
}

When I try to create simple test for this route with :

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class MyRouteTest extends CamelTestSupport {

  @Autowired
  private CamelContext camelContext;

  @Produce(uri = "file://in")
  private ProducerTemplate producerTemplate;

  @EndpointInject(uri = "mock:file://out")
  private MockEndpoint mockEndpoint;

  @Test
  public void routeTest() throws Exception {
    mockEndpoint.expectedMessageCount(1);
    producerTemplate.sendBody("Test");
    mockEndpoint.assertIsSatisfied();
  }
}

It fails with

mock://file://out Received message count. Expected: <1> but was: <0>

Not sure what could be a problem here. I have producer template that has uri as my route from point and am mocking to endpoint with EndpointInject and the the mock uri?

Upvotes: 0

Views: 1608

Answers (3)

gogic1
gogic1

Reputation: 111

You need to add

   @Override
  public String isMockEndpoints() {
    return "*";
  }

This should mock all the enpoints and then you can use mock:file:out for example

Upvotes: 0

George96
George96

Reputation: 13

Fixed but not 100%

If I change route from real one

from("file://in").to("file://out"); 

to

from("file://in").to("mock:out"); 

And in my test override

@Override
  protected RoutesBuilder createRouteBuilder() throws Exception {
    return new MyRoute();
  }

to create specific route

and strangest of all ! Had to remove :

@SpringBootTest

and after that

private CamelContext camelContext;

And then it started working !

But unfortunately not what I need, still there are things that need to be fixed, I would like to use my real prod route !

from("file://in").to("file://out");

And if possible not use advise on route , but just mock it , tried with mock:file://out in test, but it didnt work :( and also , it does not work with @SpringBootTest ??? very strange ?!

Upvotes: 1

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

If I am not misstaken you are mocking your output endpoint yet your endpoint endpoint is a file endpoint. When you send a message you need to drop a message to whereever the file endpoint is polling. Otherwise you need to mock that as well.

Upvotes: 0

Related Questions