title: Integration testing of JMS
body: <p>I have a suite of integration tests, which creates a full Spring context for my application, mocks out the end points towards other application and runs tests, for instance calling a REST-service and then check the result in the database, that other web/REST-services has been called, and so on.</p>
  
  <p>On of the cases I would like to test is consumation of JMS messages, using Spring Integration. For these test cases, I create an in-memory ActiveMQ broker, place a message on it, and check that the consumation of the message has the desired the result. This approach has a problem that I can't find a good solution for.</p>
  
  <p>Since the message processing happens in thread separate from my test exection, I have to wait for some time before verifying the behaviour. Right now I do this by <code>Thread.sleep</code>, but I'm not really happy about it. First, it adds build time, and secondly it is prone to random errors if set too low. This results in each of these tests sleeping for 2 seconds just to be sure.</p>
  
  <p>Is there a way I can control whether a message has been processed? A way to check the ActiveMQ broker through JmsTemplate perhaps?</p>