ID on bean after wire tap issue?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ID on bean after wire tap issue?

Sebastian Czort
Hi,

Is there an issue when calling id() after a bean() call after a wireTap()
call when configuring routes?

It looks like the ID gets set on the WireTapDefinition instead of on the
BeanDefinition, which is illustrated by the failing test below.

Is there a preferred workaround for mocking a bean out in a test under this
scenario?

public class WeaveByIdTest extends CamelTestSupport {

    @Override
    public boolean isUseAdviceWith() {
        // remember to override this method and return true to tell Camel
that we are using advice-with in the routes
        return true;
    }

    @Test
    public void testWeaveById() throws Exception {
        RouteDefinition route = context.getRouteDefinition("quotes");
        route.adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                // select the route node with the id=transform
                // and then replace it with the following route parts
                weaveById("transform").replace()
                    .transform().simple("${body.toUpperCase()}");

                // and add at the end of the route to route to this mock
endpoint
                weaveAddLast().to("mock:result");
            }
        });

        context.start();

        // we have replaced the bean transformer call with a simple
expression that
        // performs an upper case
        getMockEndpoint("mock:result").expectedBodiesReceived("HELLO
CAMEL");

        template.sendBody("seda:quotes", "Hello Camel");

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RoutesBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("seda:quotes").routeId("quotes")
                        // wire tap appears to get id == "transform" rather
than bean
                        .wireTap("direct:null")
                        .bean("transformer").id("transform")
                        .to("seda:lower");

                from("direct:null")
                        .log("null");
            }
        };
    }
}