mardi 14 juillet 2020

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?

Aucun commentaire:

Enregistrer un commentaire