It also works if I do this:

                from("direct:a")
                .bean(foo, "doA");
//                .to("log:A");

                from("direct:b")
                .bean(foo, "doB");
//                .to("log:B");

On 03.05.2011 13:49, Claus Straube wrote:
Ok - Ichsan :)

This works for me in 2.8-SNAPSHOT. I think this is pretty close to that you want to do (except the spring stuff).

public class CamelTestRoutingSlip extends CamelTestSupport {

    @EndpointInject(uri = "mock:result")
    protected MockEndpoint resultEndpoint;


    public void testRoutingSlip() throws InterruptedException{
        // Expected: headers contain them
        resultEndpoint.expectedHeaderReceived("a", "_a");
        resultEndpoint.expectedHeaderReceived("b", "_b");

        template.sendBody("direct:foo", "foo");

        // Then: we meet the expectation
        resultEndpoint.assertIsSatisfied();

    }

     protected RouteBuilder createRouteBuilder() throws Exception {

        final Foo foo = new Foo();

        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                from("direct:foo")
                .setHeader("routing", constant("direct:a,direct:b"))
                .routingSlip("routing")
                .to("mock:result");

                from("direct:a")
                .bean(foo, "doA")
                .to("log:A");

                from("direct:b")
                .bean(foo, "doB")
                .to("log:B");

            }
        };
    }

    public class Foo {

        public void doA(Message msg){
            msg.setHeader("a", "_a");
        }

        public void doB(Message msg){
            msg.setHeader("b", "_b");
        }

    }

}

Best regards - Claus

On 03.05.2011 13:35, Muhammad Ichsan wrote:
On Tue, May 3, 2011 at 3:49 PM, Claus Straube<claus.stra...@catify.com> wrote:
Hi Muhammad,
Ichsan please :D

I think the error must be in your iMessageUtil class. This route works as
you would expect:
IMHO, I think it's a bug in Camel. Please look at my testing artifacts:

Java code:

====================================================================================

import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/TestRoutingSlipWithJustBean.xml"})
public class TestRoutingSlipWithJustBean {
    @EndpointInject(uri = "mock:result")
    protected MockEndpoint resultEndpoint;

    @Produce(uri = "direct:foo")
     protected ProducerTemplate template;

    @DirtiesContext
    @Test
    public void testRoutingSlip() throws Exception {
        // Expected: headers contain them
        resultEndpoint.expectedHeaderReceived("a", "_a");
        resultEndpoint.expectedHeaderReceived("b", "_b");

        // When: a message is sent
        template.sendBody("Hello");

        // Then: we meet the expectation
        resultEndpoint.assertIsSatisfied();
    }
}

while iMessageUtil methods are:

    public void invokeA(Exchange x) {
        x.getIn().setHeader("a", "_a");
        LOGGER.debug("invokeA is called");
    }

    public void invokeB(Exchange x) {
        x.getIn().setHeader("b", "_b");
        LOGGER.debug("invokeB is called");
    }

and my context file:
==================


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:p="http://www.springframework.org/schema/p";
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring
     http://camel.apache.org/schema/spring/camel-spring.xsd";>

<bean id="iMessageUtil" class="my.EmptyImpl" />

<camelContext xmlns="http://camel.apache.org/schema/spring";>
<route>
<from uri="direct:foo" />
<setHeader headerName="routing">
<constant>activemq:a,activemq:b</constant>
</setHeader>
<setExchangePattern pattern="InOut" />
<routingSlip>
<header>routing</header>
</routingSlip>
<to uri="mock:result" />
</route>

<route>
<from uri="activemq:a" />
<to uri="bean:iMessageUtil?method=invokeA" />
<to uri="log:a" /> <!-- IF THIS line is removed, the test will be failed -->
</route>

<route>
<from uri="activemq:b" />
<to uri="bean:iMessageUtil?method=invokeB" />
<to uri="log:b" /> <!-- IF THIS line is removed, the test will be failed -->
</route>

</camelContext>

<!-- ActiveMQ component -->
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
        p:configuration-ref="jmsConfig" />

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:transacted="false"
        p:concurrentConsumers="50" />

<bean id="jmsConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory"
        p:targetConnectionFactory-ref="nakedConnectionFactory"
        p:sessionCacheSize="20" />

<bean id="nakedConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
        p:brokerURL="vm://localhost?broker.persistent=false" />

</beans>



Thanks





Reply via email to