title: How to check-if or wait-for message processing completion?
body: <p>I want to perform JUnit test for application using Spring-Integration framework. What I want to test is:</p>
  
  <ul>
  <li>If the message was properly processed by service activator connected to the channel I am sending</li>
  <li>If there was a proper message error handling procedure invoked in case of any errors</li>
  </ul>
  
  <p>I am using JMocikt to verify if expected methods are called. I start the test by calling <code>send</code> on a message channel.</p>
  
  <p>The problem is: <em>How do I wait for message processing to end?</em> Spring integration spawns several threads and sending on message channel returns immediately. What I have already tried is:</p>
  
  <ul>
  <li>Using <code>IntegrationMBeanExporter.stopActiveComponents(false, 0)</code> - it fails because of thread interruption</li>
  <li>Trying to chain service activators (first: the actual call, second: notification of completion) - it fails because the service activator under test returns <code>null</code> in which case, it cannot be chained. Also, I do not like it, because I have to alter SI configuration under test.</li>
  </ul>
  
  <p>Any clues?</p>
  
  <p>Please do not comment on not performing real unit, but integration testing etc. I know what I am doing.</p>