Apache Camel测试expectedBodiesReceived检查body是否为空?

问题描述 投票:0回答:1

我有一个路由,一个处理器会消耗消息并将body设置为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);         
    }
}

在测试中,我向该路由发送消息,我想测试消息是否被发送,body是否为空。

    @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));
    }
java apache-camel
1个回答
1
投票

试着用一些类似的东西(从我的头顶打字)

thirdPartyEndpoin.message(0).body().isNull();
© www.soinside.com 2019 - 2024. All rights reserved.