
package org.apache.camel.processor.interceptor;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.reifier.RouteReifier;
import org.junit.Test;

public class AdviceWithRecipientListMockEndpointsTest extends ContextTestSupport {

    @Test
    public void testAdvisedMockEndpoints() throws Exception {
        // advice the second route using the inlined AdviceWith route builder
        // which has extended capabilities than the regular route builder
        RouteReifier.adviceWith(context.getRouteDefinitions().get(1), context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                // mock all endpoints
                mockEndpoints("log*");
            }
        });

        // log:bar is a dynamic endpoint created on-the-fly (eg not in the route)
        getMockEndpoint("mock:log:bar").expectedMessageCount(1);
        // log:foo is in the route
        getMockEndpoint("mock:log:foo").expectedMessageCount(1);
        getMockEndpoint("mock:result").expectedMessageCount(1);

        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "log:bar,direct:foo");

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start").recipientList(header("foo"));

                from("direct:foo").to("log:foo").to("mock:result");
            }
        };
    }
}
