Apache Camel Integration Integration Test - NotifyBuilder

I am writing integration tests to test existing routes. The recommended way to get an answer is something like this: ( โ€œ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 passes, but I get nothing. assertTrue(matches)fails after a 5 second timeout.

If I rewrote the test to look like this, I get the answer:

@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 lit up a bit around this, so can someone tell me what I'm doing wrong with the first approach? Is there something wrong with the subsequent second approach?

Thank.

UPDATE , , seda recipientList . NotifyBuilder ( ).

  • seda, ;
  • recipientList .

, :

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");
    }

}

, NotifyTest " ", , .

+3
2

"seda: getClaimListResponse" getEndpoint, , uri 100% .

+2

FWIW: , notifyBuilder seda : :

public class NotifyBuilderTest extends CamelTestSupport {

// Try these out!
// String inputURI = "seda:foo";   // Fails
// String inputURI = "direct:foo"; // Passes

@Test
public void testNotifyBuilder() {

    NotifyBuilder b = new NotifyBuilder(context).from(inputURI)
            .whenExactlyCompleted(1).create();

    assertFalse( b.matches() );
    template.sendBody(inputURI, "Test");
    assertTrue( b.matches() );

    b.reset();

    assertFalse( b.matches() );
    template.sendBody(inputURI, "Test2");
    assertTrue( b.matches() );
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(inputURI).to("mock:foo");
        }
    };
}
}
0

Source: https://habr.com/ru/post/1774211/


All Articles