camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Problems testing Camel with Spring config
Date Mon, 28 Mar 2011 16:08:16 GMT
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 <tomhowe@artcore.com> 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 <claus.ibsen@gmail.com> wrote:
>>
>> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe <tomhowe@artcore.com> 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 <claus.ibsen@gmail.com>
>> > 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 <tomhowe@artcore.com> 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: cibsen@fusesource.com
>> >> 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: cibsen@fusesource.com
>> 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: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message