为什么我的Apache Camel模拟端点无法在测试中工作?

时间:2018-10-29 10:59:12

标签: java unit-testing apache-camel

我想测试我的阿帕奇骆驼溃败。我有测试课:

public class RequestTest extends CamelTestSupport {
  @Override
  protected CamelContext createCamelContext() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
    return applicationContext.getBean(CamelContext.class);
  }
  @Test
  public void testDeliveryPush() throws Exception {
    context.addRoutes(new RouteBuilder() {
      @Override
      public void configure() throws Exception {
        from("direct:start")
          .to("activemq:is2.request?requestTimeout=30s");    
        from("activemq:is2.messages")
          .to("mock:result");
      }
    });

    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.setExpectedMessageCount(1);

    String req = "body";  
    String result = template.requestBodyAndHeader("direct:start", req, RequestProcessor.AGENT_ID, 1003, String.class);
    Thread.sleep(30000);
    endpoint.assertIsSatisfied();
  }
}

我不明白为什么测试失败,但是我的activeMq队列中有消息。为什么消息不会出现在模拟:结果端点中? 该消息在is2.messages中 enter image description here

我得到了: java.lang.AssertionError: mock://result Received message count. Expected: <1> but was: <0> Expected :<1> Actual :<0>

1 个答案:

答案 0 :(得分:0)

您将邮件发送到一个队列(is2.request),但听另一个队列is2.messages)。第二条路线无法正常工作,因此Mock端点永远不会收到消息。还是您的问题中的错字?

并且在您的屏幕截图中没有消息。队列为空。 消息(消息已入队),但已被使用(消息已出队)。