骆驼无法在模拟队列端点上接收消息

时间:2019-04-16 03:24:24

标签: junit apache-camel

我正在尝试测试以下骆驼路线。但是,问题是我无法收到mockQueue的任何信息,而不是收到mockQueue上的消息,而是进入实际队列。

还要注意,我正在使用队列端点的Bean intead向MQ发送消息。

我还尝试如下模拟bean。

    @EndpointInject(uri = "mock:mqService")
    private MockEndpoint mqService;
  
    

路线

  
    from("{{tp.tnc.source-endpoint}}")
    .log("Procesisng Route PortfolioTnc")
    .doTry()
        .process(portfolioTncProcessor)
        .bean(transactionManager, "beginTransaction()")
        .setHeader("txnInfo", simple("${body}"))
        .bean(clientApi, "getData")
        .setHeader("transactions", simple("${body}"))
        .setHeader("transactionSize", simple("${body.size()}"))
        .choice()
            .when(header("transactionSize").isLessThan(1))
            .log("No Transactions found.")
            .bean(transactionManager, "markSuccess")
            .stop()
        .end()
        .log("There are transactions to process.")
        .log("Audit directory logging")
        .log("{{tp.tnc.auditDir}}" + "${header.inXmlFileName}")
        .log("{{tp.tnc.auditDir}}" + "${header.inBinaryFileName}")
        .log("{{tp.tnc.auditDir}}" + "${header.outXmlFileName}")
        .log("{{tp.tnc.auditDir}}" + "${header.outBinaryFileName}")
        .wireTap("{{tp.tnc.auditDir}}" + "${header.inXmlFileName}").onPrepare(jacksonProcessor)
        .wireTap("{{tp.tnc.auditDir}}" + "${header.inBinaryFileName}").onPrepare(binaryProcessor)
        .bean(transformationService, "tranform")
        .wireTap("{{tp.tnc.auditDir}}" + "${header.outXmlFileName}").onPrepare(jacksonProcessor)
        .wireTap("{{tp.tnc.auditDir}}" + "${header.outBinaryFileName}").onPrepare(binaryProcessor)
        .process(jacksonProcessor)
        .split(xpath("/Holder/Envelope")).convertBodyTo(String.class)
        .bean(mqService, "send")
        .end()
        .bean(transactionManager, "markSuccess")
    .endDoTry()
    .doCatch(Exception.class)
        .bean(transactionManager, "markFailure")
        .log(LoggingLevel.ERROR, "EXCEPTION: ${exception.stacktrace}")
    .end();
  
    

日志

  
     INFO  g.t.processor.PortfolioTncProcessor - PortfolioTncProcessor.process()
     INFO  g.t.service.impl.CsvServiceImpl - lastSuccess 2019-04-16 00:00:00 000,2019-04-16 02:50:28 547,SUCCESS 
     INFO  route2 - There are transactions to process.
     INFO  route2 - Audit directory logging
     INFO  route2 - file:some-dir/?fileName=some_file_name-2019-04-16T02-53-05.xml
     INFO  route2 - file:some-dir/?fileName=some_file_name-2019-04-16T02-53-05.ser
     INFO  route2 - file:some-dir/?fileName=some_file_name_resp-2019-04-16T02-53-05.xml
     INFO  route2 - file:some-dir/?fileName=some_file_name_resp-2019-04-16T02-53-05.ser
     (camel-1) thread #2 - WireTap] INFO  o.a.c.i.InterceptSendToMockEndpointStrategy - Adviced endpoint [file://some-dir/?fileName=some_file_name-2019-04-16T02-53-05.xml] with mock endpoint [mock:file:some-dir/]
     (camel-1) thread #3 - WireTap] INFO  o.a.c.i.InterceptSendToMockEndpointStrategy - Adviced endpoint [file://some-dir/?fileName=some_file_name-2019-04-16T02-53-05.ser] with mock endpoint [mock:file:some-dir/]
     (camel-1) thread #4 - WireTap] INFO  o.a.c.i.InterceptSendToMockEndpointStrategy - Adviced endpoint [file://some-dir/?fileName=some_file_name_resp-2019-04-16T02-53-05.xml] with mock endpoint [mock:file:some-dir/]
     (camel-1) thread #5 - WireTap] INFO  o.a.c.i.InterceptSendToMockEndpointStrategy - Adviced endpoint [file://some-dir/?fileName=some_file_name_resp-2019-04-16T02-53-05.ser] with mock endpoint [mock:file:some-dir/]
     INFO  o.a.camel.builder.xml.XPathBuilder - Created default XPathFactory com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@30ae3c46
     INFO  g.t.service.impl.MqServiceImpl - Message sent sucessfully.
     INFO  g.t.service.impl.MqServiceImpl - Message sent sucessfully.
     INFO  g.t.service.impl.MqServiceImpl - Message sent sucessfully.
     INFO  o.a.c.component.mock.MockEndpoint - Asserting: mock://MY-Q-NAME is satisfied
     INFO  g.t.route.PortfolioTncRouteTest - ********************************************************************************
     INFO  g.t.route.PortfolioTncRouteTest - Testing done: portfolioTncRouteTest(gic.tradepublisher.route.PortfolioTncRouteTest)
     INFO  g.t.route.PortfolioTncRouteTest - Took: 15.561 seconds (15561 millis)
  
    

下面是我的Junit

  
    @ActiveProfiles("test")
    @RunWith(CamelSpringBootRunner.class)
    @SpringBootTest(classes = MainApplication.class)
    @EnableRouteCoverage
    @MockEndpoints
    public class PortfolioTncRouteTest {

        private final Logger logger = LoggerFactory.getLogger(this.getClass());

        @EndpointInject(uri = "mock:{{ibm.mq.queueName}}")
        private MockEndpoint mockQueue;

        @EndpointInject(uri = "{{tp.tnc.source-endpoint}}")
        private ProducerTemplate producerTemplate;

        @MockBean
        private ClientApiService clientApiService;

        @Test
        public void portfolioTncRouteTest() throws ParseException, IOException, InterruptedException {
            List<AgiTxn<Integer>> data = (List<AgiTxn<Integer>>) TestHelper.getObject("data/test/mock_input/ptnc_scenario_1.xml", List.class);
            Mockito.when(clientApiService.getData(Mockito.any(TxnInfo.class))).thenReturn(data);
            producerTemplate.sendBody(data);
            mockQueue.expectedMessageCount(3);
            mockQueue.assertIsSatisfied(10000);
        }
    }

1 个答案:

答案 0 :(得分:1)

@MockEndpoints会将消息发送到模拟端点和实际端点。如果您只想做前者,请使用@MockEndpointsAndSkip