Skip to content
Advertisement

Camel : integration tests of asynchronous routes

I have an application using apache camel which has a full coverage of unit tests using the great camel testing support. These tests cover each parts of camel routes and work perfectly.

I now want to write integration tests that do not mocks endpoints called by Camel. For example, I want to test a part of the application that behaves like this:

  1. Receive a request on a rest endpoint and reply 202
  2. Transform the message and publish it on activemq
  3. Read the message from activemq, transform it and push it to a rest endpoint

The test look like this

// start activemq, applications, etc...
WebTarget target = //initialize a JAX RS webtarget
DTO data = // generate some datas
Response r = target .path("url").request(MediaType.APPLICATION_JSON).post(Entity.json(data));
Assert.assertEquals(r.getStatus(), 202);
// stop activemq, applications, etc...

This part works great.

Now the thing is : if the endpoint replies with a 500 code, I log the error in a mongo database. I want my integration test to check this.

I tried this :

// start activemq, applications, etc...
WebTarget target = //initialize a JAX RS webtarget
DTO data = // generate some datas that generate an error
Response r = target .path("url").request(MediaType.APPLICATION_JSON).post(Entity.json(data));
Assert.assertEquals(r.getStatus(), 202);
Thread.sleep(1000);
assertErrors(1); // check in mongo if error is written
// stop activemq, applications, etc...

I don’t like the Thread.sleep(1000).

My questions are :

  1. Is there a way to know if Camel have finished processing all the messages ?
  2. Does it make sense to test the mongo result in this case as it is already covered by a unit test on the portion of the route ?

Thanks for advice.

Advertisement

Answer

As mdnghtblue mention in comment, NotifyBuilder is the right answer

http://camel.apache.org/notifybuilder.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement