[ 
https://issues.apache.org/jira/browse/CAMEL-3578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12985313#action_12985313
 ] 

Claus Ibsen commented on CAMEL-3578:
------------------------------------

I got the following experimental working.

Notice we use an {{AdviceWithRouteBuilder}} which has extended features such as 
the {{mockEndpoints()}} which tell Camel to mock all endpoints.
The mocks will have the naming scheme {{mock:uri}} here {{uri}} was the real 
endpoint uri. 

Notice the example only has one mock endpoint in the route from the start, 
which is {{"mock:result"}}.
We could in fact remove it and the route would not have any mocks from the 
start.

{code}
    // START SNIPPET: e1
    public void testAdvisedMockEndpoints() throws Exception {
        // advice the first route using the inlined AdviceWith route builder
        // which has extended capabilities than the regular route builder
        context.getRouteDefinitions().get(0).adviceWith(context, new 
AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                // mock all endpoints
                mockEndpoints();
            }
        });

        getMockEndpoint("mock:direct://start").expectedBodiesReceived("Hello 
World");
        getMockEndpoint("mock:direct://foo").expectedBodiesReceived("Hello 
World");
        getMockEndpoint("mock:log://foo").expectedBodiesReceived("Bye World");
        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

        template.sendBody("direct:start", "Hello World");

        assertMockEndpointsSatisfied();
    }
    // END SNIPPET: e1

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                
from("direct:start").to("direct:foo").to("log:foo").to("mock:result");

                from("direct:foo").transform(constant("Bye World"));
            }
        };
    }
{code}

> MockEndpoint - Add feature to mock any endpoint
> -----------------------------------------------
>
>                 Key: CAMEL-3578
>                 URL: https://issues.apache.org/jira/browse/CAMEL-3578
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 2.5.0
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>             Fix For: 2.7.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/Unit-Testing-Route-td3284803.html
> The idea is to be able to mock any endpoint on a route and thus be able to 
> set expectations.
> In the 2.x architecture we will have to implement this using the adviceWith 
> as the route must be {{re-processed}} so we can add the interceptor logic to 
> mock
> any endpoints.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to