Poorya Hosseini
Poorya Hosseini

Reputation: 222

Apache Camel test expectedBodiesReceived check if the body is null?

I have a route that a processor consumes the message and set the body to null.

public class KafkaRedirect implements Processor {
    @Override
    public void process(final Exchange exchange) throws Exception {

        ... some logic to send to another party

        /**
        * This is added   to consume the message
        */
        exchange.getIn().setBody(null);         
    }
}

In the test I send message to the route and I want to test if the message is sent and the body is null.

    @Test
    public void testMyRoute() throws Exception {
        final MockEndpoint thirdPartyEndpoin = getMandatoryEndpoint("mock://myRoute", MockEndpoint.class);
        context().getRouteDefinition("myRouteId")
            .adviceWith(context(), new AdviceWithRouteBuilder() {

                @Override
                public void configure() throws Exception {
                    weaveById("myProcessId").after().to(thirdPartyEndpoin);
                }
            });

        startCamelContext();

        thirdPartyEndpoin.expectedMessageCount(1);

        /* I NEED TO TEST IF THE BODY IS NULL*/
        thirdPartyEndpoin.expectedBodiesReceived(null);

        template.sendBody(ROUTE_DIRECT_START, "{\"foo\":\"foo\"}");
        thirdPartyEndpoin.assertIsSatisfied(TimeUnit.SECONDS.toMillis(EXPECTED_TIMEOUT_SECONDS));
    }

Upvotes: 1

Views: 823

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55750

Try with something like (typed from top of my head)

thirdPartyEndpoin.message(0).body().isNull();

Upvotes: 1

Related Questions