/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.component.mock;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;

/**
 * @version $Revision$
 */
public class MockAsBeanTest extends ContextTestSupport {

    private MockEndpoint bean = new MockEndpoint();

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry jndi = super.createRegistry();
        jndi.bind("foo", bean);
        return jndi;
    }

    public void testMockAsBean() throws Exception {
        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

        bean.whenAnyExchangeReceived(new Processor() {
            public void process(Exchange exchange) throws Exception {
                String in = exchange.getIn().getBody(String.class);
                exchange.getIn().setBody("Bye " + in);
            }
        });

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

        assertMockEndpointsSatisfied();
    }

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


}

@@ -1131,16 +1131,58 @@
 port %7B%0A%0A
+    // create foo bean as a mock endpoint%0A
     priv
@@ -1198,20 +1198,19 @@
 ndpoint 
-bean
+foo
  = new M
@@ -1379,20 +1379,19 @@
 (%22foo%22, 
-bean
+foo
 );%0A     
@@ -1409,24 +1409,49 @@
 ndi;%0A    %7D%0A%0A
+    // START SNIPPET: e1%0A
     public v
@@ -1482,32 +1482,95 @@
 ows Exception %7B%0A
+        // we should expect to receive the transformed message%0A
         getMockE
@@ -1638,20 +1638,123 @@
         
-bean
+// the foo bean is a MockEndpoint which we use in this test to transform%0A        // the message%0A        foo
 .whenAny
@@ -2107,30 +2107,78 @@
 ;%0A    %7D%0A
-%0A    @Override
+    // END SNIPPET: e1%0A%0A    @Override%0A    // START SNIPPET: e2
 %0A    pro
@@ -2390,23 +2390,152 @@
 rt%22)
-.beanRef(%22foo%22)
+%0A                    // send to foo bean%0A                    .beanRef(%22foo%22)%0A                    // and then to result mock%0A                    
 .to(
@@ -2581,12 +2581,34 @@
 ;%0A    %7D%0A
+    // END SNIPPET: e2
 %0A%0A%7D%0A

Allow a MockEndpoint to act as a bean which can be leveraged in unit testing