title: How to test Spring Integration
body: <p>I am new to Spring Integration. I have ActiveMQ with say a 'responseQ'. So when a message arrives on 'responseQ' -> painResponseChannel -> transformer -> processResponseChannel -> beanProcessing. I have following setup:</p>
  
  <pre><code>    &lt;jms:message-driven-channel-adapter  extract-payload="true"
                                       channel="painResponseChannel"
                                       connection-factory="connectionFactory"
                                       destination-name="responseQ"/&gt;
  
      &lt;integration:channel id="painResponseChannel" /&gt;
  
      &lt;integration-xml:unmarshalling-transformer
          id="defaultUnmarshaller"
          input-channel="painResponseChannel"
          output-channel="processResponseChannel"
          unmarshaller="marshaller"/&gt;
  
      &lt;integration:channel id="processResponseChannel" /&gt;
  
      &lt;integration:service-activator
          input-channel="processResponseChannel"
          ref="processResponseActivator"/&gt;
  
      &lt;bean id="processResponseActivator" class="com.messaging.processor.PainResponseProcessor"/&gt;
  
  
      &lt;bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
        &lt;property name="classesToBeBound"&gt;
          &lt;list&gt;
              &lt;value&gt;com.domain.pain.Document&lt;/value&gt;
          &lt;/list&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>So my question is HOW CAN I TEST THIS END TO END? How can I assert the output of the transformer or assert whats on the channel? I have tried but failed... Hope someone can help.</p>
  
  <p>Thanks in advance.
  GM</p>
  
  <p>I was testing like this: In my test-context created a outbound-channel-adapter which initiates putting a message on the activeMQ using the testJmsQueue channel. And also created a BRIDGE for the processResponseChannel -> testChannel. I was expecting the receive() method to give me something back. But I think the issue is that it too fast and by the time it gets to the receive() method the pipeline has ended. </p>
  
  <p>The test-context looks like this:</p>
  
  <p></p>
  
  <pre><code>&lt;integration:bridge input-channel="processResponseChannel" output-channel="testChannel"/&gt;
  
  &lt;jms:outbound-channel-adapter id="jmsOut" destination-name="responseQ" channel="testJmsQueue"/&gt;
  
  &lt;integration:channel id="testJmsQueue"/&gt;
  
  &lt;integration:channel id="testChannel"&gt;
      &lt;integration:queue/&gt;
  &lt;/integration:channel&gt;
  </code></pre>
  
  <p>and then in the unit test I have this:</p>
  
  <pre><code>@ContextConfiguration(locations = "classpath*:PainResponseTest-context.xml")
  @RunWith(SpringJUnit4ClassRunner.class)
  public class PainResponseTest {
  
  private String painResponseXML;
  
  @Autowired
  MessageChannel testJmsQueue;
  @Autowired
  QueueChannel testChannel;
  
  @Before
  public void setup() throws Exception {
  
      ClassPathResource cpr = new ClassPathResource("painResponse.xml");
      InputStream is = cpr.getInputStream();
      StringWriter writer = new StringWriter();
      IOUtils.copy(is, writer, "UTF-8");
      painResponseXML = writer.toString();
  }
  
  @Test
  @SuppressWarnings("unchecked")
  public void shouldDoSomething() throws InterruptedException {
  
      testJmsQueue.send(MessageBuilder.withPayload(painResponseXML).build());
  
      Message&lt;String&gt; reply = (Message&lt;String&gt;) testChannel.receive(0);
      Assert.assertNotNull("reply should not be null", reply);
      String out = reply.getPayload();
      System.out.println(out);
  }
  }
  
  ==================== TEST OUTPUT =====================
  java.lang.AssertionError: reply should not be null
  </code></pre>
  
  <p>Getting reply as null.</p>