Hi Christian,

I just played with your test case with Camel trunk code.
I found the test can be passed when you remove the route instead of stop the route.

Please update the setUp() code like this

    context.removeRoute(Route2.class.getName());


On 8/23/11 4:36 AM, Christian Müller wrote:
Hello all!

I'm using Camel 2.6.0 (I got the same result with Camel 2.8.0).

I have a Camel context with two simple routes:

public class Route1 extends RouteBuilder {
     @Override
     public void configure() throws Exception {

from("file://src/test/data?noop=true&initialDelay=5000").routeId(Route1.class.getName())
             .split(body().tokenize(",")) // the content is
1,2,3,4,5,6,7,8,9,0
                 .to("activemq:queue:foo")
             .end();
     }
}

public class Route2 extends RouteBuilder {
     @Override
     public void configure() throws Exception {
         from("activemq:queue:foo").routeId(Route2.class.getName())
             .to("activemq:queue:bar");
     }
}

My Camel context look as following:

<?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:camel="http://camel.apache.org/schema/spring";
     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="route1" class="org.apache.cmueller.test.Route1" />

<bean id="route2" class="org.apache.cmueller.test.Route2" />

<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory" />
</bean>

<bean id="connectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory">
<constructor-arg
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
</bean>

<camel:camelContext trace="true">
<camel:routeBuilder ref="route1" />
<camel:routeBuilder ref="route2" />
</camel:camelContext>
</beans>


I would like to test my Route1 implementation in isolation (without
Route2). Because of this, I need to stop Route2. But it doesn't work for
my with the following code:

public class Route1Test extends CamelSpringTestSupport {

     @EndpointInject(uri = "mock:foo")
     private MockEndpoint mockEndpointFoo;

     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();

         DefaultRoute route2 = (DefaultRoute)
context.getRoute(Route2.class.getName());
         route2.stop();

         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 from("activemq:queue:foo")
                     .to(mockEndpointFoo);
             }
         });
     }

     @Test
     public void test() throws Exception {
         mockEndpointFoo.expectedBodiesReceived("1", "2", "3", "4", "5",
"6", "7", "8", "9", "0");

         mockEndpointFoo.assertIsSatisfied();
     }

     @Override
     protected AbstractApplicationContext createApplicationContext() {
         return new
ClassPathXmlApplicationContext("META-INF/spring/bundle-context.xml");
     }
}

Does have anybody an idea what I did wrong?

I attached my Eclipse sample project for convenience.

Best,
Christian


--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Reply via email to