Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Integration: tests methods fail if executed together
    primarykey
    data
    text
    <p>The workflow of my application is adding a message header, then routing the message depending on another header and sending the message further downstream. My tests for this workflow succeed individually but not when executed together, although it seems that I have reset all relevant objects.</p> <p>The spring integration workflow:</p> <pre><code>&lt;int:header-enricher input-channel="workflowStart" output-channel="headerEnriched"&gt; &lt;int:header name="correlationId" expression="headers.id.toString()" /&gt; &lt;/int:header-enricher&gt; &lt;int:header-value-router input-channel="headerEnriched" header-name="messageType"&gt; &lt;int:mapping value="stp" channel="stpChannel" /&gt; &lt;int:mapping value="nonStp" channel="nonStpChannel" /&gt; &lt;/int:header-value-router&gt; &lt;int:publish-subscribe-channel id="nonStpChannel" /&gt; &lt;int:publish-subscribe-channel id="stpChannel" apply-sequence="true"/&gt; &lt;int:chain input-channel="nonStpChannel" output-channel="systemChannel1" id="nonStpChainBlockA"&gt; &lt;!-- do something --&gt; &lt;/int:chain&gt; &lt;int:chain input-channel="stpChannel" output-channel="systemChannel3" id="stpChainBlockA"&gt; &lt;!-- do something --&gt; &lt;/int:chain&gt; </code></pre> <p>The Java test class:</p> <pre><code>@Autowired private MessageChannel workflowStart; @Autowired private MessageHandler systemChannel1OutputHandler; @Autowired private MessageHandler systemChannel3OutputHandler; @Value("/xml/tradeStp.xml") private Resource stpMessageResource; private String stpMessage; @Value("/xml/tradeNonStp.xml") private Resource nonStpMessageResource; private String nonStpMessage; @Before public void setup() throws Exception { reset(systemChannel1OutputHandler); reset(systemChannel3OutputHandler); stpMessage = IOUtils.toString(stpMessageResource.getInputStream()); nonStpMessage = IOUtils.toString(nonStpMessageResource.getInputStream()); } @Test public void nonStpMessageWorkflow1Test() { Message&lt;String&gt; m = MessageBuilder .withPayload(nonStpMessage) .setHeaderIfAbsent("messageType", "nonStp") .build(); workflowStart.send(m); verify(systemChannel1OutputHandler, times(1)).handleMessage(any(Message.class)); } @Test public void stpMessageWorkflow2Test() { Message&lt;String&gt; m = MessageBuilder .withPayload(stpMessage) .setHeaderIfAbsent("messageType", "stp") .build(); workflowStart.send(m); verify(systemChannel3OutputHandler, times(1)).handleMessage(any(Message.class)); } </code></pre> <p>And the test context:</p> <pre><code>&lt;import resource="classpath:/spring/workflow.xml"/&gt; &lt;int:outbound-channel-adapter channel="systemChannel1" ref="systemChannel1OutputHandler" method="handleMessage"/&gt; &lt;bean id="systemChannel1OutputHandler" class="org.mockito.Mockito" factory-method="mock"&gt; &lt;constructor-arg value="org.springframework.integration.core.MessageHandler"/&gt; &lt;/bean&gt; &lt;int:outbound-channel-adapter channel="systemChannel3" ref="systemChannel3OutputHandler" method="handleMessage"/&gt; &lt;bean id="systemChannel3OutputHandler" class="org.mockito.Mockito" factory-method="mock"&gt; &lt;constructor-arg value="org.springframework.integration.core.MessageHandler"/&gt; &lt;/bean&gt; &lt;int:outbound-channel-adapter channel="headerEnriched" ref="headerEnricherOutputHandler" method="handleMessage"/&gt; &lt;bean id="headerEnricherOutputHandler" class="org.mockito.Mockito" factory-method="mock"&gt; &lt;constructor-arg value="org.springframework.integration.core.MessageHandler"/&gt; &lt;/bean&gt; </code></pre> <p>If I run both tests together, the first test succeeds, while the second one fails with the message:</p> <pre><code> Wanted but not invoked: messageHandler.handleMessage(&lt;any&gt;); -&gt; at com.company.integration.com.company.export.config.InterfaceTest.stpMessageWorkflow2Test(InterfaceTest.java:81) Actually, there were zero interactions with this mock. </code></pre> <p>I have tried to debug in various ways. The problem seems to be just after the header-value-router and before the chain. The last debug output for the second test is a "postSend" on the headerEnriched channel. Any advice is very welcome. </p> <p>UPDATE: I failed to include an additional outputHandler that I have in my context for another test, which I have included now. By removing the headerEnricherOutputHandler all tests run fine. However, I still don't understand the reason why this causes problems when tests are being run together. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload