Jigar Naik
Jigar Naik

Reputation: 1994

camel unable to receive message on mock queue end point

I am trying to test below camel route. However the issue is that i am not able receive anything to my mockQueue, instead of receiving message on my mockQueue it's going to actual queue.

Also note that i am sending message to MQ using Bean intead of queue end point.

I also tried to mock the bean as below.

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

Route

    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();

logs

     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)

Below is my 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);
        }
    }

Upvotes: 1

Views: 449

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

@MockEndpoints will send the message to the mock endpoint & the actual endpoint. If you want to only do the former, then use @MockEndpointsAndSkip

Upvotes: 1

Related Questions