How to test Spring integration

I am new to spring integration. I have ActiveMQ, say "responseQ". Therefore, when a message arrives at responseQ → painResponseChannel → transformer → processResponseChannel → beanProcessing. I have the following settings:

<jms:message-driven-channel-adapter extract-payload="true" channel="painResponseChannel" connection-factory="connectionFactory" destination-name="responseQ"/> <integration:channel id="painResponseChannel" /> <integration-xml:unmarshalling-transformer id="defaultUnmarshaller" input-channel="painResponseChannel" output-channel="processResponseChannel" unmarshaller="marshaller"/> <integration:channel id="processResponseChannel" /> <integration:service-activator input-channel="processResponseChannel" ref="processResponseActivator"/> <bean id="processResponseActivator" class="com.messaging.processor.PainResponseProcessor"/> <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> <value>com.domain.pain.Document</value> </list> </property> </bean> 

So my question is: HOW CAN I CHECK THIS END? How can I claim the output of a transformer or claim to be on a channel? I tried, but could not ... I hope someone can help.

Thanks in advance. GM

I tested like this: in my test context, an outbound channel adapter was created that initiates the placement of a message in activeMQ using the testJmsQueue channel. And also created a MOST for processResponseChannel -> testChannel. I expected the receive () method to return something to me. But I think the problem is that it is too fast, and by the time it receives the receive () method, the pipeline has already ended.

The test context looks like this:

 <integration:bridge input-channel="processResponseChannel" output-channel="testChannel"/> <jms:outbound-channel-adapter id="jmsOut" destination-name="responseQ" channel="testJmsQueue"/> <integration:channel id="testJmsQueue"/> <integration:channel id="testChannel"> <integration:queue/> </integration:channel> 

and then in the unit test I have this:

 @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<String> reply = (Message<String>) 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 

Getting the answer as zero.

+7
source share
1 answer

For end-to-end testing, you can do the following;

  • use activemq in embedded configuration to send JMS message
  • embed channel interceptor in processResponseChannel
  • enable DEBUG level - Spring Integration provides very good and useful logs that track messages to and from service channels and activators
+1
source

All Articles