Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot and camel testing with @SpringBootTest

I have spring boot app, with spring boot of version 1.5.8 and there camel 2.20.1

Simple route :

@Component
public class MyRoute extends RouteBuilder {

  public static final String IN = "file://in";

  public static final String OUT = "file://out";

  @Override
  public void configure() throws Exception {
    from(IN).routeId("myId").to(OUT);
  }
}

Und simple test :

//@SpringBootTest
public class MyRouteTest extends CamelTestSupport {


      @Produce(uri = MyRoute.IN)
      private ProducerTemplate producerTemplate;

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

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

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

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

    }

When I run this test it runs fine and I get one message and the endpoint is satisfied. If I add @SpringBootTest annotation, the test fails? Why ? Also without annotation when I run maven clean install it also fails :(

Anyone have any idea what is this annotation does to camel test, or how can I adjust it so that it works?

Thx

like image 943
bijesanu Avatar asked Dec 13 '17 15:12

bijesanu


1 Answers

Here is what worked at the end :

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints
public class MyRouteTest2 {

  @Autowired
  private ProducerTemplate producerTemplate;

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

  @Test
  public void test() throws InterruptedException {
    String body = "Camel";
    mockCamel.expectedMessageCount(1);

    producerTemplate.sendBody("file:in", body);

    mockCamel.assertIsSatisfied();
  }
}
like image 168
bijesanu Avatar answered Oct 29 '22 15:10

bijesanu