use*_*337 7 spring spring-integration
我是Spring Integration的新手.我让ActiveMQ说'responseQ'.所以当消息到达'responseQ' - > painResponseChannel - > transformer - > processResponseChannel - > beanProcessing时.我有以下设置:
<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>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我该如何测试结束?如何断言变压器的输出或断言通道上的什么?我尝试但失败了......希望有人可以提供帮助.
提前致谢.GM
我是这样测试的:在我的测试环境中创建了一个出站通道适配器,它使用testJmsQueue通道启动在activeMQ上发送消息.并且还为processResponseChannel - > testChannel创建了一个BRIDGE.我期待receive()方法能给我回馈一些东西.但我认为问题在于它太快了,当它到达receive()方法时,管道已经结束.
测试上下文如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
然后在单元测试中我有这个:
@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
Run Code Online (Sandbox Code Playgroud)
}
<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>
Run Code Online (Sandbox Code Playgroud)
获得回复为null.
对于端到端测试,您可以执行以下操作;
DEBUG
级别 - Spring Integration 提供了非常好的和有用的日志,跟踪通道和服务激活器进出的消息 归档时间: |
|
查看次数: |
19107 次 |
最近记录: |