Camel: integration tests for asynchronous routes
I have an application using apache camel that has full unit test coverage using excellent camel testing support. These tests cover every part of the camel routes and work great.
Now I want to write integration tests that don't fool the endpoints called by Camel. For example, I want to test a part of the application that behaves like this:
- Receive request for rest endpoint and reply 202
- Convert the post and post it to activemq
- Read post from activemq, convert it and click on rest endpoint
The test looks 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 point is, if the endpoint responds with a code of 500, then I log the error to the mongo database. I want my integration test to check this.
I've 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 it Thread.sleep(1000)
.
My questions:
- Is there a way to tell if Camel has finished processing all messages?
- Does it make sense to check the mongo result in this case, since it is already covered by the unit test on the route leg?
Thanks for the advice.
+3
source to share