简体   繁体   中英

Disable Wiretap during testing

I want to be able to stop my routes from sending information by Wiretap when testing. This is the method I currently use to make a route testable.

private void setupRoute(String routeId, String inputEndpoint, String outputEndpoint) throws Exception {
        camelContext.getRouteDefinition(routeId)
                .autoStartup(true)
                .adviceWith(camelContext, new AdviceWithRouteBuilder() {
                    @Override
                    public void configure() throws Exception {
                        replaceFromWith(inputEndpoint);
                        interceptSendToEndpoint(outputEndpoint)
                                .skipSendToOriginalEndpoint()
                                .to(MOCK_OUTPUT);

                        //Should stop the route from wiretapping the messages to the archiving routes.
                        if (camelContext.hasEndpoint("direct:archiver") != null) {
                            interceptSendToEndpoint("direct:archiver")
                                    .skipSendToOriginalEndpoint().stop();
                        }
                        if (camelContext.hasEndpoint("direct:elasticSearch") != null) {
                            interceptSendToEndpoint("direct:elasticSearch")
                                    .skipSendToOriginalEndpoint().stop();
                        }
                    }
                });

I figured that by checking the camelContext for these routes and then disabling them if they exist, that would solve the problem. But when debugging I noticed that both those routes are not saved as Endpoints under the camelContext, so this doesn't work.

What would be the proper way of disabling a Wiratap during testing?

Alright I've figured it out myself. Simply add this to the AdviceWithRouteBuilder:

interceptSendToEndpoint("direct:archiver")
     .skipSendToOriginalEndpoint().stop();
interceptSendToEndpoint("direct:elasticSearch")
     .skipSendToOriginalEndpoint().stop();

In my original question I checked if they exist before intercepting these endpoints, but that is apparently not necessary. If the endpoint you're trying to intercept doesn't exist it will simply do nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM