首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何测试Spring集成

如何测试Spring集成
EN

Stack Overflow用户
提问于 2013-04-25 16:03:17
回答 1查看 21.1K关注 0票数 8

我是春季集成的新手。我让ActiveMQ说一个“响应Q”。因此,当消息到达'responseQ‘-> painResponseChannel -> transformer -> processResponseChannel -> beanProcessing时。我有以下设置:

代码语言:javascript
复制
    <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>

所以,我的问题是,我怎样才能最终测试这个问题呢?如何断言转换器的输出或断言通道上的内容?我试过但失败了..。希望有人能帮忙。

提前谢谢。通用汽车

我进行了这样的测试:在我的测试上下文中创建了一个出站通道适配器,它启动使用activeMQ通道在testJmsQueue上放置消息。并为processResponseChannel -> testChannel创建了一座桥梁。我原以为接收()方法会还给我一些东西。但是我认为问题在于它太快了,当它到达接收()方法的时候,管道已经结束了。

测试上下文如下所示:

代码语言:javascript
复制
<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>

然后在单元测试中,我得到了这个:

代码语言:javascript
复制
@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

得到的回复为空。

EN

回答 1

Stack Overflow用户

发布于 2013-04-25 16:26:11

对于端到端的测试,您可以执行以下操作;

  • 在嵌入式配置中使用activemq发送JMS消息
  • 在processResponseChannel上注入一个通道拦截器
  • 启用DEBUG级别- Spring集成提供了非常好的和有用的日志跟踪消息进出通道和服务激活器。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16219589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档