Quantcast

Problems testing Camel with Spring config

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problems testing Camel with Spring config

Tom Howe
I have a routes defined in CamelRoutes.xml and I would like to test them by
using the wrapping technique described at the bottom of
http://camel.apache.org/mock.html.

My CamelRoutes.xml
     <route autoStartup="true"  xmlns="http://camel.apache.org/schema/spring
">
            <from uri="direct:start"/>
            <to uri="direct:end"/>
        </route>

So I created CamelRoutesTest.xml containing:

    <import resource="CamelRoutes.xml"/>
    <bean id="mockAllEndpoints"
class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>

but I am not sure how to create a test that both loads the spring xml AND
provides access to the mock endpoints.

If I use..

@ContextConfiguration( locations=("/CamelRoutesTest"))
public class CamelTest extends AbstractJUnit38SpringContextTests

}

then I have no idea how to *get* the mock endpoints

If I use..

public class CamelTest extends CamelTestSupport

}

then I dont know how to load my camel context..


I can't seem to find an example test on the website that uses
CamelTestSupport AND loads routes from spring xml.

thanks, Tom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Claus Ibsen-2
Hi

Check out this page
http://camel.apache.org/testing

You can then use any IoC means to inject the mocks, such as
@EndpointInjected or any of the Spring or the new @Resource from JDK6
etc.

Also you can extend CamelSpringTestSupport which allows you to load a
Spring XML file.
Thats often what we do to test Camel as CamelXXTestSupport is easy to
get mocks, producer template and whatnot without having to IoC them.


On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]> wrote:

> I have a routes defined in CamelRoutes.xml and I would like to test them by
> using the wrapping technique described at the bottom of
> http://camel.apache.org/mock.html.
>
> My CamelRoutes.xml
>     <route autoStartup="true"  xmlns="http://camel.apache.org/schema/spring
> ">
>            <from uri="direct:start"/>
>            <to uri="direct:end"/>
>        </route>
>
> So I created CamelRoutesTest.xml containing:
>
>    <import resource="CamelRoutes.xml"/>
>    <bean id="mockAllEndpoints"
> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>
> but I am not sure how to create a test that both loads the spring xml AND
> provides access to the mock endpoints.
>
> If I use..
>
> @ContextConfiguration( locations=("/CamelRoutesTest"))
> public class CamelTest extends AbstractJUnit38SpringContextTests
>
> }
>
> then I have no idea how to *get* the mock endpoints
>
> If I use..
>
> public class CamelTest extends CamelTestSupport
>
> }
>
> then I dont know how to load my camel context..
>
>
> I can't seem to find an example test on the website that uses
> CamelTestSupport AND loads routes from spring xml.
>
> thanks, Tom
>



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
I've read the testing page but it doesnt give any good eaxmple of using
spring xml routes

Can you point me to an example of CamelSpringTestSupport ? I cant see any
docs on it's usage?

Thanks, Tom

On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]> wrote:

> Hi
>
> Check out this page
> http://camel.apache.org/testing
>
> You can then use any IoC means to inject the mocks, such as
> @EndpointInjected or any of the Spring or the new @Resource from JDK6
> etc.
>
> Also you can extend CamelSpringTestSupport which allows you to load a
> Spring XML file.
> Thats often what we do to test Camel as CamelXXTestSupport is easy to
> get mocks, producer template and whatnot without having to IoC them.
>
>
> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]> wrote:
> > I have a routes defined in CamelRoutes.xml and I would like to test them
> by
> > using the wrapping technique described at the bottom of
> > http://camel.apache.org/mock.html.
> >
> > My CamelRoutes.xml
> >     <route autoStartup="true"  xmlns="
> http://camel.apache.org/schema/spring
> > ">
> >            <from uri="direct:start"/>
> >            <to uri="direct:end"/>
> >        </route>
> >
> > So I created CamelRoutesTest.xml containing:
> >
> >    <import resource="CamelRoutes.xml"/>
> >    <bean id="mockAllEndpoints"
> > class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
> >
> > but I am not sure how to create a test that both loads the spring xml AND
> > provides access to the mock endpoints.
> >
> > If I use..
> >
> > @ContextConfiguration( locations=("/CamelRoutesTest"))
> > public class CamelTest extends AbstractJUnit38SpringContextTests
> >
> > }
> >
> > then I have no idea how to *get* the mock endpoints
> >
> > If I use..
> >
> > public class CamelTest extends CamelTestSupport
> >
> > }
> >
> > then I dont know how to load my camel context..
> >
> >
> > I can't seem to find an example test on the website that uses
> > CamelTestSupport AND loads routes from spring xml.
> >
> > thanks, Tom
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [hidden email]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Claus Ibsen-2
On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]> wrote:
> I've read the testing page but it doesnt give any good eaxmple of using
> spring xml routes
>

There is more here
http://camel.apache.org/spring-testing.html


> Can you point me to an example of CamelSpringTestSupport ? I cant see any
> docs on it's usage?
>

Just try to extend this class and it forces you to implement a method
where you load the Spring XML file.
There are many examples in the source code, eg in camel-spring module.
https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/


Btw the Camel in Action book chapter 6 covers all about testing.




> Thanks, Tom
>
> On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]> wrote:
>
>> Hi
>>
>> Check out this page
>> http://camel.apache.org/testing
>>
>> You can then use any IoC means to inject the mocks, such as
>> @EndpointInjected or any of the Spring or the new @Resource from JDK6
>> etc.
>>
>> Also you can extend CamelSpringTestSupport which allows you to load a
>> Spring XML file.
>> Thats often what we do to test Camel as CamelXXTestSupport is easy to
>> get mocks, producer template and whatnot without having to IoC them.
>>
>>
>> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]> wrote:
>> > I have a routes defined in CamelRoutes.xml and I would like to test them
>> by
>> > using the wrapping technique described at the bottom of
>> > http://camel.apache.org/mock.html.
>> >
>> > My CamelRoutes.xml
>> >     <route autoStartup="true"  xmlns="
>> http://camel.apache.org/schema/spring
>> > ">
>> >            <from uri="direct:start"/>
>> >            <to uri="direct:end"/>
>> >        </route>
>> >
>> > So I created CamelRoutesTest.xml containing:
>> >
>> >    <import resource="CamelRoutes.xml"/>
>> >    <bean id="mockAllEndpoints"
>> > class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>> >
>> > but I am not sure how to create a test that both loads the spring xml AND
>> > provides access to the mock endpoints.
>> >
>> > If I use..
>> >
>> > @ContextConfiguration( locations=("/CamelRoutesTest"))
>> > public class CamelTest extends AbstractJUnit38SpringContextTests
>> >
>> > }
>> >
>> > then I have no idea how to *get* the mock endpoints
>> >
>> > If I use..
>> >
>> > public class CamelTest extends CamelTestSupport
>> >
>> > }
>> >
>> > then I dont know how to load my camel context..
>> >
>> >
>> > I can't seem to find an example test on the website that uses
>> > CamelTestSupport AND loads routes from spring xml.
>> >
>> > thanks, Tom
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
The spring-testing.html doesnt mention CamelSpringTestSupport. Im not sure
where to look in camel test suite.

I tried this..

public class SimpleRouteTest extends CamelSpringTestSupport {

    @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
    }

    public String isMockEndpoints() {
        return "*";
    }

    @Test
    public void testSendMessage() throws Exception {
        getMockEndpoint("mock:direct:end").expectedMessageCount(1);
        template.sendBody("mock:direct:start", "blah");
        assertMockEndpointsSatisfied();
    }
}

It doesnt work though...

From the log it looks like my route is started but then a fresh camel
context without route is started for the tests.

2011-03-28 16:46:22,976 [main] INFO
org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
(CamelContext: camel-1) is starting
2011-03-28 16:46:22,976 [main] INFO
org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
ManagedManagementStrategy.
2011-03-28 16:46:23,533 [main] INFO
org.apache.camel.spring.SpringCamelContext  - Route: route1 started and
consuming from: Endpoint[direct://start]
2011-03-28 16:46:23,538 [main] INFO
org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which 1 is
started.
2011-03-28 16:46:23,539 [main] INFO
org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
(CamelContext: camel-1) started in 0.562 seconds
2011-03-28 16:46:23,542 [main] INFO  agentsmith.routes.SimpleRouteTest  -
********************************************************************************
2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
********************************************************************************
2011-03-28 16:46:23,547 [main] INFO
org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
endpoint [direct://start] with mock endpoint [mock:direct:start]
2011-03-28 16:46:23,557 [main] INFO
org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
endpoint [direct://end] with mock endpoint [mock:direct:end]
2011-03-28 16:46:23,558 [main] INFO
org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
endpoint [spring-event://default] with mock endpoint
[mock:spring-event:default]
2011-03-28 16:46:23,577 [main] INFO
org.apache.camel.component.mock.MockEndpoint  - Asserting:
Endpoint[mock://spring-event:default] is satisfied
2011-03-28 16:46:23,577 [main] INFO
org.apache.camel.component.mock.MockEndpoint  - Asserting:
Endpoint[mock://direct:end] is satisfied

java.lang.AssertionError: mock://direct:end Received message count.
Expected: <1> but was: <0>
    at
org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
....












On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]> wrote:

> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]> wrote:
> > I've read the testing page but it doesnt give any good eaxmple of using
> > spring xml routes
> >
>
> There is more here
> http://camel.apache.org/spring-testing.html
>
>
> > Can you point me to an example of CamelSpringTestSupport ? I cant see any
> > docs on it's usage?
> >
>
> Just try to extend this class and it forces you to implement a method
> where you load the Spring XML file.
> There are many examples in the source code, eg in camel-spring module.
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
>
>
> Btw the Camel in Action book chapter 6 covers all about testing.
>
>
>
>
> > Thanks, Tom
> >
> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]>
> wrote:
> >
> >> Hi
> >>
> >> Check out this page
> >> http://camel.apache.org/testing
> >>
> >> You can then use any IoC means to inject the mocks, such as
> >> @EndpointInjected or any of the Spring or the new @Resource from JDK6
> >> etc.
> >>
> >> Also you can extend CamelSpringTestSupport which allows you to load a
> >> Spring XML file.
> >> Thats often what we do to test Camel as CamelXXTestSupport is easy to
> >> get mocks, producer template and whatnot without having to IoC them.
> >>
> >>
> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]> wrote:
> >> > I have a routes defined in CamelRoutes.xml and I would like to test
> them
> >> by
> >> > using the wrapping technique described at the bottom of
> >> > http://camel.apache.org/mock.html.
> >> >
> >> > My CamelRoutes.xml
> >> >     <route autoStartup="true"  xmlns="
> >> http://camel.apache.org/schema/spring
> >> > ">
> >> >            <from uri="direct:start"/>
> >> >            <to uri="direct:end"/>
> >> >        </route>
> >> >
> >> > So I created CamelRoutesTest.xml containing:
> >> >
> >> >    <import resource="CamelRoutes.xml"/>
> >> >    <bean id="mockAllEndpoints"
> >> > class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
> >> >
> >> > but I am not sure how to create a test that both loads the spring xml
> AND
> >> > provides access to the mock endpoints.
> >> >
> >> > If I use..
> >> >
> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
> >> >
> >> > }
> >> >
> >> > then I have no idea how to *get* the mock endpoints
> >> >
> >> > If I use..
> >> >
> >> > public class CamelTest extends CamelTestSupport
> >> >
> >> > }
> >> >
> >> > then I dont know how to load my camel context..
> >> >
> >> >
> >> > I can't seem to find an example test on the website that uses
> >> > CamelTestSupport AND loads routes from spring xml.
> >> >
> >> > thanks, Tom
> >> >
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> FuseSource
> >> Email: [hidden email]
> >> Web: http://fusesource.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >>
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [hidden email]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Claus Ibsen-2
Use
         template.sendBody("direct:start", "blah");

Instead of
>         template.sendBody("mock:direct:start", "blah");


And mind that the test your picked is using the new auto mock feature
(mock existing endpoints) from Camel 2.7
http://camel.apache.org/mock.html




On Mon, Mar 28, 2011 at 5:50 PM, Tom Howe <[hidden email]> wrote:

> The spring-testing.html doesnt mention CamelSpringTestSupport. Im not sure
> where to look in camel test suite.
>
> I tried this..
>
> public class SimpleRouteTest extends CamelSpringTestSupport {
>
>     @Override
>     protected AbstractXmlApplicationContext createApplicationContext() {
>         return new ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
>     }
>
>     public String isMockEndpoints() {
>         return "*";
>     }
>
>     @Test
>     public void testSendMessage() throws Exception {
>         getMockEndpoint("mock:direct:end").expectedMessageCount(1);
>         template.sendBody("mock:direct:start", "blah");
>         assertMockEndpointsSatisfied();
>     }
> }
>
> It doesnt work though...
>
> From the log it looks like my route is started but then a fresh camel
> context without route is started for the tests.
>
> 2011-03-28 16:46:22,976 [main] INFO
> org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
> (CamelContext: camel-1) is starting
> 2011-03-28 16:46:22,976 [main] INFO
> org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
> ManagedManagementStrategy.
> 2011-03-28 16:46:23,533 [main] INFO
> org.apache.camel.spring.SpringCamelContext  - Route: route1 started and
> consuming from: Endpoint[direct://start]
> 2011-03-28 16:46:23,538 [main] INFO
> org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which 1 is
> started.
> 2011-03-28 16:46:23,539 [main] INFO
> org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
> (CamelContext: camel-1) started in 0.562 seconds
> 2011-03-28 16:46:23,542 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> ********************************************************************************
> 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
> 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> ********************************************************************************
> 2011-03-28 16:46:23,547 [main] INFO
> org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> endpoint [direct://start] with mock endpoint [mock:direct:start]
> 2011-03-28 16:46:23,557 [main] INFO
> org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> endpoint [direct://end] with mock endpoint [mock:direct:end]
> 2011-03-28 16:46:23,558 [main] INFO
> org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> endpoint [spring-event://default] with mock endpoint
> [mock:spring-event:default]
> 2011-03-28 16:46:23,577 [main] INFO
> org.apache.camel.component.mock.MockEndpoint  - Asserting:
> Endpoint[mock://spring-event:default] is satisfied
> 2011-03-28 16:46:23,577 [main] INFO
> org.apache.camel.component.mock.MockEndpoint  - Asserting:
> Endpoint[mock://direct:end] is satisfied
>
> java.lang.AssertionError: mock://direct:end Received message count.
> Expected: <1> but was: <0>
>     at
> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
> ....
>
>
>
>
>
>
>
>
>
>
>
>
> On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]> wrote:
>>
>> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]> wrote:
>> > I've read the testing page but it doesnt give any good eaxmple of using
>> > spring xml routes
>> >
>>
>> There is more here
>> http://camel.apache.org/spring-testing.html
>>
>>
>> > Can you point me to an example of CamelSpringTestSupport ? I cant see
>> > any
>> > docs on it's usage?
>> >
>>
>> Just try to extend this class and it forces you to implement a method
>> where you load the Spring XML file.
>> There are many examples in the source code, eg in camel-spring module.
>> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
>>
>>
>> Btw the Camel in Action book chapter 6 covers all about testing.
>>
>>
>>
>>
>> > Thanks, Tom
>> >
>> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]>
>> > wrote:
>> >
>> >> Hi
>> >>
>> >> Check out this page
>> >> http://camel.apache.org/testing
>> >>
>> >> You can then use any IoC means to inject the mocks, such as
>> >> @EndpointInjected or any of the Spring or the new @Resource from JDK6
>> >> etc.
>> >>
>> >> Also you can extend CamelSpringTestSupport which allows you to load a
>> >> Spring XML file.
>> >> Thats often what we do to test Camel as CamelXXTestSupport is easy to
>> >> get mocks, producer template and whatnot without having to IoC them.
>> >>
>> >>
>> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]> wrote:
>> >> > I have a routes defined in CamelRoutes.xml and I would like to test
>> >> > them
>> >> by
>> >> > using the wrapping technique described at the bottom of
>> >> > http://camel.apache.org/mock.html.
>> >> >
>> >> > My CamelRoutes.xml
>> >> >     <route autoStartup="true"  xmlns="
>> >> http://camel.apache.org/schema/spring
>> >> > ">
>> >> >            <from uri="direct:start"/>
>> >> >            <to uri="direct:end"/>
>> >> >        </route>
>> >> >
>> >> > So I created CamelRoutesTest.xml containing:
>> >> >
>> >> >    <import resource="CamelRoutes.xml"/>
>> >> >    <bean id="mockAllEndpoints"
>> >> > class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>> >> >
>> >> > but I am not sure how to create a test that both loads the spring xml
>> >> > AND
>> >> > provides access to the mock endpoints.
>> >> >
>> >> > If I use..
>> >> >
>> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
>> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
>> >> >
>> >> > }
>> >> >
>> >> > then I have no idea how to *get* the mock endpoints
>> >> >
>> >> > If I use..
>> >> >
>> >> > public class CamelTest extends CamelTestSupport
>> >> >
>> >> > }
>> >> >
>> >> > then I dont know how to load my camel context..
>> >> >
>> >> >
>> >> > I can't seem to find an example test on the website that uses
>> >> > CamelTestSupport AND loads routes from spring xml.
>> >> >
>> >> > thanks, Tom
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> FuseSource
>> >> Email: [hidden email]
>> >> Web: http://fusesource.com
>> >> Twitter: davsclaus
>> >> Blog: http://davsclaus.blogspot.com/
>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >>
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>
>



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
ok, I have copied the test from

https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java

and got that working by changing from SpringTestSupport to
CamelSpringTestSupport.

Then I tried to reduce it down to my example and found that when I remove
the route that consumes from direct:foo, the test fails with:

org.apache.camel.CamelExchangeException: No consumers available on endpoint:
Endpoint[direct://foo]. Exchange[Message: Hello World]

Why is this? Do you have to have a consumer for every endpoint you wish to
mock?





On Mon, Mar 28, 2011 at 5:08 PM, Claus Ibsen <[hidden email]> wrote:

> Use
>          template.sendBody("direct:start", "blah");
>
> Instead of
> >         template.sendBody("mock:direct:start", "blah");
>
>
> And mind that the test your picked is using the new auto mock feature
> (mock existing endpoints) from Camel 2.7
> http://camel.apache.org/mock.html
>
>
>
>
> On Mon, Mar 28, 2011 at 5:50 PM, Tom Howe <[hidden email]> wrote:
> > The spring-testing.html doesnt mention CamelSpringTestSupport. Im not
> sure
> > where to look in camel test suite.
> >
> > I tried this..
> >
> > public class SimpleRouteTest extends CamelSpringTestSupport {
> >
> >     @Override
> >     protected AbstractXmlApplicationContext createApplicationContext() {
> >         return new
> ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
> >     }
> >
> >     public String isMockEndpoints() {
> >         return "*";
> >     }
> >
> >     @Test
> >     public void testSendMessage() throws Exception {
> >         getMockEndpoint("mock:direct:end").expectedMessageCount(1);
> >         template.sendBody("mock:direct:start", "blah");
> >         assertMockEndpointsSatisfied();
> >     }
> > }
> >
> > It doesnt work though...
> >
> > From the log it looks like my route is started but then a fresh camel
> > context without route is started for the tests.
> >
> > 2011-03-28 16:46:22,976 [main] INFO
> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
> > (CamelContext: camel-1) is starting
> > 2011-03-28 16:46:22,976 [main] INFO
> > org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
> > ManagedManagementStrategy.
> > 2011-03-28 16:46:23,533 [main] INFO
> > org.apache.camel.spring.SpringCamelContext  - Route: route1 started and
> > consuming from: Endpoint[direct://start]
> > 2011-03-28 16:46:23,538 [main] INFO
> > org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which 1
> is
> > started.
> > 2011-03-28 16:46:23,539 [main] INFO
> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
> > (CamelContext: camel-1) started in 0.562 seconds
> > 2011-03-28 16:46:23,542 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> >
> ********************************************************************************
> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> > Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest  -
> >
> ********************************************************************************
> > 2011-03-28 16:46:23,547 [main] INFO
> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> > endpoint [direct://start] with mock endpoint [mock:direct:start]
> > 2011-03-28 16:46:23,557 [main] INFO
> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> > endpoint [direct://end] with mock endpoint [mock:direct:end]
> > 2011-03-28 16:46:23,558 [main] INFO
> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
> > endpoint [spring-event://default] with mock endpoint
> > [mock:spring-event:default]
> > 2011-03-28 16:46:23,577 [main] INFO
> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
> > Endpoint[mock://spring-event:default] is satisfied
> > 2011-03-28 16:46:23,577 [main] INFO
> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
> > Endpoint[mock://direct:end] is satisfied
> >
> > java.lang.AssertionError: mock://direct:end Received message count.
> > Expected: <1> but was: <0>
> >     at
> > org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
> > ....
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]>
> wrote:
> >>
> >> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]> wrote:
> >> > I've read the testing page but it doesnt give any good eaxmple of
> using
> >> > spring xml routes
> >> >
> >>
> >> There is more here
> >> http://camel.apache.org/spring-testing.html
> >>
> >>
> >> > Can you point me to an example of CamelSpringTestSupport ? I cant see
> >> > any
> >> > docs on it's usage?
> >> >
> >>
> >> Just try to extend this class and it forces you to implement a method
> >> where you load the Spring XML file.
> >> There are many examples in the source code, eg in camel-spring module.
> >> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
> >>
> >>
> >> Btw the Camel in Action book chapter 6 covers all about testing.
> >>
> >>
> >>
> >>
> >> > Thanks, Tom
> >> >
> >> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]>
> >> > wrote:
> >> >
> >> >> Hi
> >> >>
> >> >> Check out this page
> >> >> http://camel.apache.org/testing
> >> >>
> >> >> You can then use any IoC means to inject the mocks, such as
> >> >> @EndpointInjected or any of the Spring or the new @Resource from JDK6
> >> >> etc.
> >> >>
> >> >> Also you can extend CamelSpringTestSupport which allows you to load a
> >> >> Spring XML file.
> >> >> Thats often what we do to test Camel as CamelXXTestSupport is easy to
> >> >> get mocks, producer template and whatnot without having to IoC them.
> >> >>
> >> >>
> >> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]>
> wrote:
> >> >> > I have a routes defined in CamelRoutes.xml and I would like to test
> >> >> > them
> >> >> by
> >> >> > using the wrapping technique described at the bottom of
> >> >> > http://camel.apache.org/mock.html.
> >> >> >
> >> >> > My CamelRoutes.xml
> >> >> >     <route autoStartup="true"  xmlns="
> >> >> http://camel.apache.org/schema/spring
> >> >> > ">
> >> >> >            <from uri="direct:start"/>
> >> >> >            <to uri="direct:end"/>
> >> >> >        </route>
> >> >> >
> >> >> > So I created CamelRoutesTest.xml containing:
> >> >> >
> >> >> >    <import resource="CamelRoutes.xml"/>
> >> >> >    <bean id="mockAllEndpoints"
> >> >> > class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
> >> >> >
> >> >> > but I am not sure how to create a test that both loads the spring
> xml
> >> >> > AND
> >> >> > provides access to the mock endpoints.
> >> >> >
> >> >> > If I use..
> >> >> >
> >> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
> >> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
> >> >> >
> >> >> > }
> >> >> >
> >> >> > then I have no idea how to *get* the mock endpoints
> >> >> >
> >> >> > If I use..
> >> >> >
> >> >> > public class CamelTest extends CamelTestSupport
> >> >> >
> >> >> > }
> >> >> >
> >> >> > then I dont know how to load my camel context..
> >> >> >
> >> >> >
> >> >> > I can't seem to find an example test on the website that uses
> >> >> > CamelTestSupport AND loads routes from spring xml.
> >> >> >
> >> >> > thanks, Tom
> >> >> >
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Claus Ibsen
> >> >> -----------------
> >> >> FuseSource
> >> >> Email: [hidden email]
> >> >> Web: http://fusesource.com
> >> >> Twitter: davsclaus
> >> >> Blog: http://davsclaus.blogspot.com/
> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >> >>
> >> >
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> FuseSource
> >> Email: [hidden email]
> >> Web: http://fusesource.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [hidden email]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
Also - if I change the test xml to

        <route>
            <from uri="direct:start"/>
            <to uri="activemq:blah"/>
        </route>

and the test to :

  public void testAdvisedMockEndpoints() throws Exception {
        getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello
World");
        template.sendBody("direct:start", "Hello World");
        assertMockEndpointsSatisfied();
 }

the test hangs.. - and never completes.



On Mon, Mar 28, 2011 at 5:29 PM, Tom Howe <[hidden email]> wrote:

> ok, I have copied the test from
>
>
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java
>
> and got that working by changing from SpringTestSupport to
> CamelSpringTestSupport.
>
> Then I tried to reduce it down to my example and found that when I remove
> the route that consumes from direct:foo, the test fails with:
>
> org.apache.camel.CamelExchangeException: No consumers available on
> endpoint: Endpoint[direct://foo]. Exchange[Message: Hello World]
>
> Why is this? Do you have to have a consumer for every endpoint you wish to
> mock?
>
>
>
>
>
>
> On Mon, Mar 28, 2011 at 5:08 PM, Claus Ibsen <[hidden email]>wrote:
>
>> Use
>>          template.sendBody("direct:start", "blah");
>>
>> Instead of
>> >         template.sendBody("mock:direct:start", "blah");
>>
>>
>> And mind that the test your picked is using the new auto mock feature
>> (mock existing endpoints) from Camel 2.7
>> http://camel.apache.org/mock.html
>>
>>
>>
>>
>> On Mon, Mar 28, 2011 at 5:50 PM, Tom Howe <[hidden email]> wrote:
>> > The spring-testing.html doesnt mention CamelSpringTestSupport. Im not
>> sure
>> > where to look in camel test suite.
>> >
>> > I tried this..
>> >
>> > public class SimpleRouteTest extends CamelSpringTestSupport {
>> >
>> >     @Override
>> >     protected AbstractXmlApplicationContext createApplicationContext() {
>> >         return new
>> ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
>> >     }
>> >
>> >     public String isMockEndpoints() {
>> >         return "*";
>> >     }
>> >
>> >     @Test
>> >     public void testSendMessage() throws Exception {
>> >         getMockEndpoint("mock:direct:end").expectedMessageCount(1);
>> >         template.sendBody("mock:direct:start", "blah");
>> >         assertMockEndpointsSatisfied();
>> >     }
>> > }
>> >
>> > It doesnt work though...
>> >
>> > From the log it looks like my route is started but then a fresh camel
>> > context without route is started for the tests.
>> >
>> > 2011-03-28 16:46:22,976 [main] INFO
>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>> > (CamelContext: camel-1) is starting
>> > 2011-03-28 16:46:22,976 [main] INFO
>> > org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
>> > ManagedManagementStrategy.
>> > 2011-03-28 16:46:23,533 [main] INFO
>> > org.apache.camel.spring.SpringCamelContext  - Route: route1 started and
>> > consuming from: Endpoint[direct://start]
>> > 2011-03-28 16:46:23,538 [main] INFO
>> > org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which 1
>> is
>> > started.
>> > 2011-03-28 16:46:23,539 [main] INFO
>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>> > (CamelContext: camel-1) started in 0.562 seconds
>> > 2011-03-28 16:46:23,542 [main] INFO  agentsmith.routes.SimpleRouteTest
>> -
>> >
>> ********************************************************************************
>> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest
>> -
>> > Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
>> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest
>> -
>> >
>> ********************************************************************************
>> > 2011-03-28 16:46:23,547 [main] INFO
>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>> > endpoint [direct://start] with mock endpoint [mock:direct:start]
>> > 2011-03-28 16:46:23,557 [main] INFO
>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>> > endpoint [direct://end] with mock endpoint [mock:direct:end]
>> > 2011-03-28 16:46:23,558 [main] INFO
>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>> > endpoint [spring-event://default] with mock endpoint
>> > [mock:spring-event:default]
>> > 2011-03-28 16:46:23,577 [main] INFO
>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>> > Endpoint[mock://spring-event:default] is satisfied
>> > 2011-03-28 16:46:23,577 [main] INFO
>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>> > Endpoint[mock://direct:end] is satisfied
>> >
>> > java.lang.AssertionError: mock://direct:end Received message count.
>> > Expected: <1> but was: <0>
>> >     at
>> >
>> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
>> > ....
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]>
>> wrote:
>> >>
>> >> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]> wrote:
>> >> > I've read the testing page but it doesnt give any good eaxmple of
>> using
>> >> > spring xml routes
>> >> >
>> >>
>> >> There is more here
>> >> http://camel.apache.org/spring-testing.html
>> >>
>> >>
>> >> > Can you point me to an example of CamelSpringTestSupport ? I cant see
>> >> > any
>> >> > docs on it's usage?
>> >> >
>> >>
>> >> Just try to extend this class and it forces you to implement a method
>> >> where you load the Spring XML file.
>> >> There are many examples in the source code, eg in camel-spring module.
>> >> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
>> >>
>> >>
>> >> Btw the Camel in Action book chapter 6 covers all about testing.
>> >>
>> >>
>> >>
>> >>
>> >> > Thanks, Tom
>> >> >
>> >> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]>
>> >> > wrote:
>> >> >
>> >> >> Hi
>> >> >>
>> >> >> Check out this page
>> >> >> http://camel.apache.org/testing
>> >> >>
>> >> >> You can then use any IoC means to inject the mocks, such as
>> >> >> @EndpointInjected or any of the Spring or the new @Resource from
>> JDK6
>> >> >> etc.
>> >> >>
>> >> >> Also you can extend CamelSpringTestSupport which allows you to load
>> a
>> >> >> Spring XML file.
>> >> >> Thats often what we do to test Camel as CamelXXTestSupport is easy
>> to
>> >> >> get mocks, producer template and whatnot without having to IoC them.
>> >> >>
>> >> >>
>> >> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]>
>> wrote:
>> >> >> > I have a routes defined in CamelRoutes.xml and I would like to
>> test
>> >> >> > them
>> >> >> by
>> >> >> > using the wrapping technique described at the bottom of
>> >> >> > http://camel.apache.org/mock.html.
>> >> >> >
>> >> >> > My CamelRoutes.xml
>> >> >> >     <route autoStartup="true"  xmlns="
>> >> >> http://camel.apache.org/schema/spring
>> >> >> > ">
>> >> >> >            <from uri="direct:start"/>
>> >> >> >            <to uri="direct:end"/>
>> >> >> >        </route>
>> >> >> >
>> >> >> > So I created CamelRoutesTest.xml containing:
>> >> >> >
>> >> >> >    <import resource="CamelRoutes.xml"/>
>> >> >> >    <bean id="mockAllEndpoints"
>> >> >> >
>> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>> >> >> >
>> >> >> > but I am not sure how to create a test that both loads the spring
>> xml
>> >> >> > AND
>> >> >> > provides access to the mock endpoints.
>> >> >> >
>> >> >> > If I use..
>> >> >> >
>> >> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
>> >> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
>> >> >> >
>> >> >> > }
>> >> >> >
>> >> >> > then I have no idea how to *get* the mock endpoints
>> >> >> >
>> >> >> > If I use..
>> >> >> >
>> >> >> > public class CamelTest extends CamelTestSupport
>> >> >> >
>> >> >> > }
>> >> >> >
>> >> >> > then I dont know how to load my camel context..
>> >> >> >
>> >> >> >
>> >> >> > I can't seem to find an example test on the website that uses
>> >> >> > CamelTestSupport AND loads routes from spring xml.
>> >> >> >
>> >> >> > thanks, Tom
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Claus Ibsen
>> >> >> -----------------
>> >> >> FuseSource
>> >> >> Email: [hidden email]
>> >> >> Web: http://fusesource.com
>> >> >> Twitter: davsclaus
>> >> >> Blog: http://davsclaus.blogspot.com/
>> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >> >>
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> FuseSource
>> >> Email: [hidden email]
>> >> Web: http://fusesource.com
>> >> Twitter: davsclaus
>> >> Blog: http://davsclaus.blogspot.com/
>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
I seem to have got it working by changing activemq to a DirectComponent for
the test..  is this considered good practice?


  <!-- the Camel route is defined in another XML file -->
    <import resource="CamelRoutes.xml"/>

    <bean id="activemq"
class="org.apache.camel.component.direct.DirectComponent" />

    <!-- bean which enables mocking all endpoints -->
    <bean id="mockAllEndpoints"
class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>







On Mon, Mar 28, 2011 at 5:32 PM, Tom Howe <[hidden email]> wrote:

> Also - if I change the test xml to
>
>         <route>
>             <from uri="direct:start"/>
>             <to uri="activemq:blah"/>
>         </route>
>
> and the test to :
>
>   public void testAdvisedMockEndpoints() throws Exception {
>         getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello
> World");
>         template.sendBody("direct:start", "Hello World");
>         assertMockEndpointsSatisfied();
>  }
>
> the test hangs.. - and never completes.
>
>
>
>
> On Mon, Mar 28, 2011 at 5:29 PM, Tom Howe <[hidden email]> wrote:
>
>> ok, I have copied the test from
>>
>>
>> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java
>>
>> and got that working by changing from SpringTestSupport to
>> CamelSpringTestSupport.
>>
>> Then I tried to reduce it down to my example and found that when I remove
>> the route that consumes from direct:foo, the test fails with:
>>
>> org.apache.camel.CamelExchangeException: No consumers available on
>> endpoint: Endpoint[direct://foo]. Exchange[Message: Hello World]
>>
>> Why is this? Do you have to have a consumer for every endpoint you wish to
>> mock?
>>
>>
>>
>>
>>
>>
>> On Mon, Mar 28, 2011 at 5:08 PM, Claus Ibsen <[hidden email]>wrote:
>>
>>> Use
>>>          template.sendBody("direct:start", "blah");
>>>
>>> Instead of
>>> >         template.sendBody("mock:direct:start", "blah");
>>>
>>>
>>> And mind that the test your picked is using the new auto mock feature
>>> (mock existing endpoints) from Camel 2.7
>>> http://camel.apache.org/mock.html
>>>
>>>
>>>
>>>
>>> On Mon, Mar 28, 2011 at 5:50 PM, Tom Howe <[hidden email]> wrote:
>>> > The spring-testing.html doesnt mention CamelSpringTestSupport. Im not
>>> sure
>>> > where to look in camel test suite.
>>> >
>>> > I tried this..
>>> >
>>> > public class SimpleRouteTest extends CamelSpringTestSupport {
>>> >
>>> >     @Override
>>> >     protected AbstractXmlApplicationContext createApplicationContext()
>>> {
>>> >         return new
>>> ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
>>> >     }
>>> >
>>> >     public String isMockEndpoints() {
>>> >         return "*";
>>> >     }
>>> >
>>> >     @Test
>>> >     public void testSendMessage() throws Exception {
>>> >         getMockEndpoint("mock:direct:end").expectedMessageCount(1);
>>> >         template.sendBody("mock:direct:start", "blah");
>>> >         assertMockEndpointsSatisfied();
>>> >     }
>>> > }
>>> >
>>> > It doesnt work though...
>>> >
>>> > From the log it looks like my route is started but then a fresh camel
>>> > context without route is started for the tests.
>>> >
>>> > 2011-03-28 16:46:22,976 [main] INFO
>>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>>> > (CamelContext: camel-1) is starting
>>> > 2011-03-28 16:46:22,976 [main] INFO
>>> > org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
>>> > ManagedManagementStrategy.
>>> > 2011-03-28 16:46:23,533 [main] INFO
>>> > org.apache.camel.spring.SpringCamelContext  - Route: route1 started and
>>> > consuming from: Endpoint[direct://start]
>>> > 2011-03-28 16:46:23,538 [main] INFO
>>> > org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which
>>> 1 is
>>> > started.
>>> > 2011-03-28 16:46:23,539 [main] INFO
>>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>>> > (CamelContext: camel-1) started in 0.562 seconds
>>> > 2011-03-28 16:46:23,542 [main] INFO  agentsmith.routes.SimpleRouteTest
>>> -
>>> >
>>> ********************************************************************************
>>> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest
>>> -
>>> > Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
>>> > 2011-03-28 16:46:23,543 [main] INFO  agentsmith.routes.SimpleRouteTest
>>> -
>>> >
>>> ********************************************************************************
>>> > 2011-03-28 16:46:23,547 [main] INFO
>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>> > endpoint [direct://start] with mock endpoint [mock:direct:start]
>>> > 2011-03-28 16:46:23,557 [main] INFO
>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>> > endpoint [direct://end] with mock endpoint [mock:direct:end]
>>> > 2011-03-28 16:46:23,558 [main] INFO
>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>> > endpoint [spring-event://default] with mock endpoint
>>> > [mock:spring-event:default]
>>> > 2011-03-28 16:46:23,577 [main] INFO
>>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>>> > Endpoint[mock://spring-event:default] is satisfied
>>> > 2011-03-28 16:46:23,577 [main] INFO
>>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>>> > Endpoint[mock://direct:end] is satisfied
>>> >
>>> > java.lang.AssertionError: mock://direct:end Received message count.
>>> > Expected: <1> but was: <0>
>>> >     at
>>> >
>>> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
>>> > ....
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]>
>>> wrote:
>>> >>
>>> >> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]>
>>> wrote:
>>> >> > I've read the testing page but it doesnt give any good eaxmple of
>>> using
>>> >> > spring xml routes
>>> >> >
>>> >>
>>> >> There is more here
>>> >> http://camel.apache.org/spring-testing.html
>>> >>
>>> >>
>>> >> > Can you point me to an example of CamelSpringTestSupport ? I cant
>>> see
>>> >> > any
>>> >> > docs on it's usage?
>>> >> >
>>> >>
>>> >> Just try to extend this class and it forces you to implement a method
>>> >> where you load the Spring XML file.
>>> >> There are many examples in the source code, eg in camel-spring module.
>>> >> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
>>> >>
>>> >>
>>> >> Btw the Camel in Action book chapter 6 covers all about testing.
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> > Thanks, Tom
>>> >> >
>>> >> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <[hidden email]
>>> >
>>> >> > wrote:
>>> >> >
>>> >> >> Hi
>>> >> >>
>>> >> >> Check out this page
>>> >> >> http://camel.apache.org/testing
>>> >> >>
>>> >> >> You can then use any IoC means to inject the mocks, such as
>>> >> >> @EndpointInjected or any of the Spring or the new @Resource from
>>> JDK6
>>> >> >> etc.
>>> >> >>
>>> >> >> Also you can extend CamelSpringTestSupport which allows you to load
>>> a
>>> >> >> Spring XML file.
>>> >> >> Thats often what we do to test Camel as CamelXXTestSupport is easy
>>> to
>>> >> >> get mocks, producer template and whatnot without having to IoC
>>> them.
>>> >> >>
>>> >> >>
>>> >> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]>
>>> wrote:
>>> >> >> > I have a routes defined in CamelRoutes.xml and I would like to
>>> test
>>> >> >> > them
>>> >> >> by
>>> >> >> > using the wrapping technique described at the bottom of
>>> >> >> > http://camel.apache.org/mock.html.
>>> >> >> >
>>> >> >> > My CamelRoutes.xml
>>> >> >> >     <route autoStartup="true"  xmlns="
>>> >> >> http://camel.apache.org/schema/spring
>>> >> >> > ">
>>> >> >> >            <from uri="direct:start"/>
>>> >> >> >            <to uri="direct:end"/>
>>> >> >> >        </route>
>>> >> >> >
>>> >> >> > So I created CamelRoutesTest.xml containing:
>>> >> >> >
>>> >> >> >    <import resource="CamelRoutes.xml"/>
>>> >> >> >    <bean id="mockAllEndpoints"
>>> >> >> >
>>> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>>> >> >> >
>>> >> >> > but I am not sure how to create a test that both loads the spring
>>> xml
>>> >> >> > AND
>>> >> >> > provides access to the mock endpoints.
>>> >> >> >
>>> >> >> > If I use..
>>> >> >> >
>>> >> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
>>> >> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
>>> >> >> >
>>> >> >> > }
>>> >> >> >
>>> >> >> > then I have no idea how to *get* the mock endpoints
>>> >> >> >
>>> >> >> > If I use..
>>> >> >> >
>>> >> >> > public class CamelTest extends CamelTestSupport
>>> >> >> >
>>> >> >> > }
>>> >> >> >
>>> >> >> > then I dont know how to load my camel context..
>>> >> >> >
>>> >> >> >
>>> >> >> > I can't seem to find an example test on the website that uses
>>> >> >> > CamelTestSupport AND loads routes from spring xml.
>>> >> >> >
>>> >> >> > thanks, Tom
>>> >> >> >
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Claus Ibsen
>>> >> >> -----------------
>>> >> >> FuseSource
>>> >> >> Email: [hidden email]
>>> >> >> Web: http://fusesource.com
>>> >> >> Twitter: davsclaus
>>> >> >> Blog: http://davsclaus.blogspot.com/
>>> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
>>> >> >>
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Claus Ibsen
>>> >> -----------------
>>> >> FuseSource
>>> >> Email: [hidden email]
>>> >> Web: http://fusesource.com
>>> >> Twitter: davsclaus
>>> >> Blog: http://davsclaus.blogspot.com/
>>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> FuseSource
>>> Email: [hidden email]
>>> Web: http://fusesource.com
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.blogspot.com/
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems testing Camel with Spring config

Tom Howe
Hm, my other endpoints - mina, rest etc are still being activated.
How do I properly mock those out so they do not try to connect to external
systems?


On Mon, Mar 28, 2011 at 5:49 PM, Tom Howe <[hidden email]> wrote:

> I seem to have got it working by changing activemq to a DirectComponent for
> the test..  is this considered good practice?
>
>
>   <!-- the Camel route is defined in another XML file -->
>     <import resource="CamelRoutes.xml"/>
>
>     <bean id="activemq"
> class="org.apache.camel.component.direct.DirectComponent" />
>
>     <!-- bean which enables mocking all endpoints -->
>
>     <bean id="mockAllEndpoints"
> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>
>
>
>
>
>
>
> On Mon, Mar 28, 2011 at 5:32 PM, Tom Howe <[hidden email]> wrote:
>
>> Also - if I change the test xml to
>>
>>         <route>
>>             <from uri="direct:start"/>
>>             <to uri="activemq:blah"/>
>>         </route>
>>
>> and the test to :
>>
>>   public void testAdvisedMockEndpoints() throws Exception {
>>         getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello
>> World");
>>         template.sendBody("direct:start", "Hello World");
>>         assertMockEndpointsSatisfied();
>>  }
>>
>> the test hangs.. - and never completes.
>>
>>
>>
>>
>> On Mon, Mar 28, 2011 at 5:29 PM, Tom Howe <[hidden email]> wrote:
>>
>>> ok, I have copied the test from
>>>
>>>
>>> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java
>>>
>>> and got that working by changing from SpringTestSupport to
>>> CamelSpringTestSupport.
>>>
>>> Then I tried to reduce it down to my example and found that when I remove
>>> the route that consumes from direct:foo, the test fails with:
>>>
>>> org.apache.camel.CamelExchangeException: No consumers available on
>>> endpoint: Endpoint[direct://foo]. Exchange[Message: Hello World]
>>>
>>> Why is this? Do you have to have a consumer for every endpoint you wish
>>> to mock?
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Mar 28, 2011 at 5:08 PM, Claus Ibsen <[hidden email]>wrote:
>>>
>>>> Use
>>>>          template.sendBody("direct:start", "blah");
>>>>
>>>> Instead of
>>>> >         template.sendBody("mock:direct:start", "blah");
>>>>
>>>>
>>>> And mind that the test your picked is using the new auto mock feature
>>>> (mock existing endpoints) from Camel 2.7
>>>> http://camel.apache.org/mock.html
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, Mar 28, 2011 at 5:50 PM, Tom Howe <[hidden email]> wrote:
>>>> > The spring-testing.html doesnt mention CamelSpringTestSupport. Im not
>>>> sure
>>>> > where to look in camel test suite.
>>>> >
>>>> > I tried this..
>>>> >
>>>> > public class SimpleRouteTest extends CamelSpringTestSupport {
>>>> >
>>>> >     @Override
>>>> >     protected AbstractXmlApplicationContext createApplicationContext()
>>>> {
>>>> >         return new
>>>> ClassPathXmlApplicationContext("/CamelRoutesSimple.xml");
>>>> >     }
>>>> >
>>>> >     public String isMockEndpoints() {
>>>> >         return "*";
>>>> >     }
>>>> >
>>>> >     @Test
>>>> >     public void testSendMessage() throws Exception {
>>>> >         getMockEndpoint("mock:direct:end").expectedMessageCount(1);
>>>> >         template.sendBody("mock:direct:start", "blah");
>>>> >         assertMockEndpointsSatisfied();
>>>> >     }
>>>> > }
>>>> >
>>>> > It doesnt work though...
>>>> >
>>>> > From the log it looks like my route is started but then a fresh camel
>>>> > context without route is started for the tests.
>>>> >
>>>> > 2011-03-28 16:46:22,976 [main] INFO
>>>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>>>> > (CamelContext: camel-1) is starting
>>>> > 2011-03-28 16:46:22,976 [main] INFO
>>>> > org.apache.camel.spring.SpringCamelContext  - JMX enabled. Using
>>>> > ManagedManagementStrategy.
>>>> > 2011-03-28 16:46:23,533 [main] INFO
>>>> > org.apache.camel.spring.SpringCamelContext  - Route: route1 started
>>>> and
>>>> > consuming from: Endpoint[direct://start]
>>>> > 2011-03-28 16:46:23,538 [main] INFO
>>>> > org.apache.camel.spring.SpringCamelContext  - Total 1 routes, of which
>>>> 1 is
>>>> > started.
>>>> > 2011-03-28 16:46:23,539 [main] INFO
>>>> > org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.7.0
>>>> > (CamelContext: camel-1) started in 0.562 seconds
>>>> > 2011-03-28 16:46:23,542 [main] INFO
>>>> agentsmith.routes.SimpleRouteTest  -
>>>> >
>>>> ********************************************************************************
>>>> > 2011-03-28 16:46:23,543 [main] INFO
>>>> agentsmith.routes.SimpleRouteTest  -
>>>> > Testing: testSendMessage(agentsmith.routes.SimpleRouteTest)
>>>> > 2011-03-28 16:46:23,543 [main] INFO
>>>> agentsmith.routes.SimpleRouteTest  -
>>>> >
>>>> ********************************************************************************
>>>> > 2011-03-28 16:46:23,547 [main] INFO
>>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>>> > endpoint [direct://start] with mock endpoint [mock:direct:start]
>>>> > 2011-03-28 16:46:23,557 [main] INFO
>>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>>> > endpoint [direct://end] with mock endpoint [mock:direct:end]
>>>> > 2011-03-28 16:46:23,558 [main] INFO
>>>> > org.apache.camel.impl.InterceptSendToMockEndpointStrategy  - Adviced
>>>> > endpoint [spring-event://default] with mock endpoint
>>>> > [mock:spring-event:default]
>>>> > 2011-03-28 16:46:23,577 [main] INFO
>>>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>>>> > Endpoint[mock://spring-event:default] is satisfied
>>>> > 2011-03-28 16:46:23,577 [main] INFO
>>>> > org.apache.camel.component.mock.MockEndpoint  - Asserting:
>>>> > Endpoint[mock://direct:end] is satisfied
>>>> >
>>>> > java.lang.AssertionError: mock://direct:end Received message count.
>>>> > Expected: <1> but was: <0>
>>>> >     at
>>>> >
>>>> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
>>>> > ....
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen <[hidden email]>
>>>> wrote:
>>>> >>
>>>> >> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <[hidden email]>
>>>> wrote:
>>>> >> > I've read the testing page but it doesnt give any good eaxmple of
>>>> using
>>>> >> > spring xml routes
>>>> >> >
>>>> >>
>>>> >> There is more here
>>>> >> http://camel.apache.org/spring-testing.html
>>>> >>
>>>> >>
>>>> >> > Can you point me to an example of CamelSpringTestSupport ? I cant
>>>> see
>>>> >> > any
>>>> >> > docs on it's usage?
>>>> >> >
>>>> >>
>>>> >> Just try to extend this class and it forces you to implement a method
>>>> >> where you load the Spring XML file.
>>>> >> There are many examples in the source code, eg in camel-spring
>>>> module.
>>>> >>
>>>> https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/
>>>> >>
>>>> >>
>>>> >> Btw the Camel in Action book chapter 6 covers all about testing.
>>>> >>
>>>> >>
>>>> >>
>>>> >>
>>>> >> > Thanks, Tom
>>>> >> >
>>>> >> > On Mon, Mar 28, 2011 at 4:27 PM, Claus Ibsen <
>>>> [hidden email]>
>>>> >> > wrote:
>>>> >> >
>>>> >> >> Hi
>>>> >> >>
>>>> >> >> Check out this page
>>>> >> >> http://camel.apache.org/testing
>>>> >> >>
>>>> >> >> You can then use any IoC means to inject the mocks, such as
>>>> >> >> @EndpointInjected or any of the Spring or the new @Resource from
>>>> JDK6
>>>> >> >> etc.
>>>> >> >>
>>>> >> >> Also you can extend CamelSpringTestSupport which allows you to
>>>> load a
>>>> >> >> Spring XML file.
>>>> >> >> Thats often what we do to test Camel as CamelXXTestSupport is easy
>>>> to
>>>> >> >> get mocks, producer template and whatnot without having to IoC
>>>> them.
>>>> >> >>
>>>> >> >>
>>>> >> >> On Mon, Mar 28, 2011 at 5:11 PM, Tom Howe <[hidden email]>
>>>> wrote:
>>>> >> >> > I have a routes defined in CamelRoutes.xml and I would like to
>>>> test
>>>> >> >> > them
>>>> >> >> by
>>>> >> >> > using the wrapping technique described at the bottom of
>>>> >> >> > http://camel.apache.org/mock.html.
>>>> >> >> >
>>>> >> >> > My CamelRoutes.xml
>>>> >> >> >     <route autoStartup="true"  xmlns="
>>>> >> >> http://camel.apache.org/schema/spring
>>>> >> >> > ">
>>>> >> >> >            <from uri="direct:start"/>
>>>> >> >> >            <to uri="direct:end"/>
>>>> >> >> >        </route>
>>>> >> >> >
>>>> >> >> > So I created CamelRoutesTest.xml containing:
>>>> >> >> >
>>>> >> >> >    <import resource="CamelRoutes.xml"/>
>>>> >> >> >    <bean id="mockAllEndpoints"
>>>> >> >> >
>>>> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>>>> >> >> >
>>>> >> >> > but I am not sure how to create a test that both loads the
>>>> spring xml
>>>> >> >> > AND
>>>> >> >> > provides access to the mock endpoints.
>>>> >> >> >
>>>> >> >> > If I use..
>>>> >> >> >
>>>> >> >> > @ContextConfiguration( locations=("/CamelRoutesTest"))
>>>> >> >> > public class CamelTest extends AbstractJUnit38SpringContextTests
>>>> >> >> >
>>>> >> >> > }
>>>> >> >> >
>>>> >> >> > then I have no idea how to *get* the mock endpoints
>>>> >> >> >
>>>> >> >> > If I use..
>>>> >> >> >
>>>> >> >> > public class CamelTest extends CamelTestSupport
>>>> >> >> >
>>>> >> >> > }
>>>> >> >> >
>>>> >> >> > then I dont know how to load my camel context..
>>>> >> >> >
>>>> >> >> >
>>>> >> >> > I can't seem to find an example test on the website that uses
>>>> >> >> > CamelTestSupport AND loads routes from spring xml.
>>>> >> >> >
>>>> >> >> > thanks, Tom
>>>> >> >> >
>>>> >> >>
>>>> >> >>
>>>> >> >>
>>>> >> >> --
>>>> >> >> Claus Ibsen
>>>> >> >> -----------------
>>>> >> >> FuseSource
>>>> >> >> Email: [hidden email]
>>>> >> >> Web: http://fusesource.com
>>>> >> >> Twitter: davsclaus
>>>> >> >> Blog: http://davsclaus.blogspot.com/
>>>> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
>>>> >> >>
>>>> >> >
>>>> >>
>>>> >>
>>>> >>
>>>> >> --
>>>> >> Claus Ibsen
>>>> >> -----------------
>>>> >> FuseSource
>>>> >> Email: [hidden email]
>>>> >> Web: http://fusesource.com
>>>> >> Twitter: davsclaus
>>>> >> Blog: http://davsclaus.blogspot.com/
>>>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>>>> >
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> -----------------
>>>> FuseSource
>>>> Email: [hidden email]
>>>> Web: http://fusesource.com
>>>> Twitter: davsclaus
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>>
>>>
>>>
>>
>
Loading...