Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel Integration Test - NotifyBuilder

I am writing integration tests to test existing Routes. The recommended way of getting the response looks something like this (via Camel In Action section 6.4.1):

public class TestGetClaim extends CamelTestSupport {

    @Produce(uri = "seda:getClaimListStart")
    protected ProducerTemplate producer;

    @Test
    public void testNormalClient() {
        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

        producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
        boolean matches = notify.matches(5, TimeUnit.SECONDS);
        assertTrue(matches);

        BrowsableEndpoint be = context.getEndpoint("seda:getClaimListResponse", BrowsableEndpoint.class);
        List<Exchange> list = be.getExchanges();
        assertEquals(1, list.size());
        System.out.println("***RESPONSE is type "+list.get(0).getIn().getBody().getClass().getName());
    }
}

The test runs but I get nothing back. The assertTrue(matches) fails after the 5 second timeout.

If I rewrite the test to look like this I get a response:

@Test
public void testNormalClient() {
    producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
    Object resp = context.createConsumerTemplate().receiveBody("seda:getClaimListResponse");
    System.out.println("***RESPONSE is type "+resp.getClass().getName());
}

The documentation is a little light around this so can anyone tell me what I am doing wrong with the first approach? Is there anything wrong with following the second approach instead?

Thanks.

UPDATE I have broken this down and it looks like the problem is with the mix of seda as the start endpoint in combination with the use of a recipientList in the Route. I've also changed the construction of the NotifyBuilder (I had the wrong endpoint specified).

  • If I change the start endpoint to direct instead of seda then the test will work; or
  • If I comment out the recipientList then the test will work.

Here's a stripped down version of my Route that reproduces this issue:

public class TestRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
//      from("direct:start")    //works
        from("seda:start")  //doesn't work
        .recipientList(simple("exec:GetClaimList.bat?useStderrOnEmptyStdout=true&args=${body.client}"))
        .to("seda:finish");
    }

}

Note that if I change the source code of the NotifyTest from the "Camel In Action" source to have a route builder like this then it also fails.

like image 892
Damo Avatar asked Apr 19 '26 05:04

Damo


1 Answers

Try to use "seda:getClaimListResponse" in the getEndpoint to be sure the endpoint uri is 100% correct

like image 108
Claus Ibsen Avatar answered Apr 22 '26 00:04

Claus Ibsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!