我是新来的Spring集成。 我用的ActiveMQ说“RESPONSEQ”。 > painResponseChannel - - >变压器 - > processResponseChannel - > beanProcessing所以当消息 'RESPONSEQ' 到达。 我有以下设置:
<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>
所以我的问题是我如何测试这个端到端的? 我怎么能断言变压器的输出或断言什么渠道呢? 我曾尝试但失败了...希望有人能帮助。
提前致谢。 GM
我测试这样的:在我的测试环境中创建一个出站通道适配器,将发起对使用testJmsQueue通道的ActiveMQ的消息。 又创造了processResponseChannel的桥梁 - > testChannel。 我期待收到()方法来给我的东西回来。 但我认为这个问题是它过快的时候它到达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>
然后在单元测试我有这样的:
@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
获得回复为空。