Reputation: 691
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:
<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 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.
Thanks in advance. GM
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.
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 reply as null.
Upvotes: 8
Views: 21593
Reputation: 2137
For end-to-end testing, you can do the following;
DEBUG
level - Spring Integration gives very good and helpful logs tracing messages in and out of channels and service activatorsUpvotes: 1