Reputation: 1420
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:
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 :
Thanks for advice.
Upvotes: 3
Views: 1918
Reputation: 1420
As mdnghtblue mention in comment, NotifyBuilder is the right answer
http://camel.apache.org/notifybuilder.html
Upvotes: 1