Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 65954 invoked from network); 28 Mar 2011 16:09:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Mar 2011 16:09:03 -0000 Received: (qmail 14679 invoked by uid 500); 28 Mar 2011 16:09:03 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 14649 invoked by uid 500); 28 Mar 2011 16:09:03 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 14641 invoked by uid 99); 28 Mar 2011 16:09:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Mar 2011 16:09:03 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-qy0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Mar 2011 16:08:58 +0000 Received: by qyk10 with SMTP id 10so2602901qyk.11 for ; Mon, 28 Mar 2011 09:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=Lre6+Dy6F4svpGtm/hAOLXmKQeD4uIDt6+J8YL64/RM=; b=dlSF+jcw/YRwQ57N9hrSkNkLOdQdDeubqKlWJkn1C/xmJa4Cyu6MD7rZut0Mbnu8Y6 7DNiNX1UzDDcWwwr1vTNatBKy5PR09oj7HdpH9QXsBHlilO/LCmSIvOWiqL63V9///8y ox6Ey1z4eKwlyVBBHS0NZMfFGtxEvmiJiYOvA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=qeJyA1zqIxZUpSGovaiXOQCyvXiSlGFrE3LUndb4jdcPSL2hEokg6tTqoNd/B5fYtb MeUDBjNCkzIlISg0VQWKdsXaj/QatOo/vdj5KrD5eKtDXaiU4QObHzo/dHnl32PUFHct xQpKwM9WdBPIVyNz+F95H5M3Rtab6zwtIhXxc= Received: by 10.229.102.209 with SMTP id h17mr3430566qco.102.1301328516331; Mon, 28 Mar 2011 09:08:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.247.75 with HTTP; Mon, 28 Mar 2011 09:08:16 -0700 (PDT) In-Reply-To: References: From: Claus Ibsen Date: Mon, 28 Mar 2011 18:08:16 +0200 Message-ID: Subject: Re: Problems testing Camel with Spring config To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Use =A0=A0=A0=A0=A0=A0=A0 template.sendBody("direct:start", "blah"); Instead of > =A0=A0=A0=A0=A0=A0=A0 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 wrote: > The spring-testing.html doesnt mention CamelSpringTestSupport. Im not sur= e > where to look in camel test suite. > > I tried this.. > > public class SimpleRouteTest extends CamelSpringTestSupport { > > =A0=A0=A0 @Override > =A0=A0=A0 protected AbstractXmlApplicationContext createApplicationContex= t() { > =A0=A0=A0=A0=A0=A0=A0 return new ClassPathXmlApplicationContext("/CamelRo= utesSimple.xml"); > =A0=A0=A0 } > > =A0=A0=A0 public String isMockEndpoints() { > =A0=A0=A0=A0=A0=A0=A0 return "*"; > =A0=A0=A0 } > > =A0=A0=A0 @Test > =A0=A0=A0 public void testSendMessage() throws Exception { > =A0=A0=A0=A0=A0=A0=A0 getMockEndpoint("mock:direct:end").expectedMessageC= ount(1); > =A0=A0=A0=A0=A0=A0=A0 template.sendBody("mock:direct:start", "blah"); > =A0=A0=A0=A0=A0=A0=A0 assertMockEndpointsSatisfied(); > =A0=A0=A0 } > } > > 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=A0 - Apache Camel 2.7.0 > (CamelContext: camel-1) is starting > 2011-03-28 16:46:22,976 [main] INFO > org.apache.camel.spring.SpringCamelContext=A0 - JMX enabled. Using > ManagedManagementStrategy. > 2011-03-28 16:46:23,533 [main] INFO > org.apache.camel.spring.SpringCamelContext=A0 - Route: route1 started and > consuming from: Endpoint[direct://start] > 2011-03-28 16:46:23,538 [main] INFO > org.apache.camel.spring.SpringCamelContext=A0 - Total 1 routes, of which = 1 is > started. > 2011-03-28 16:46:23,539 [main] INFO > org.apache.camel.spring.SpringCamelContext=A0 - Apache Camel 2.7.0 > (CamelContext: camel-1) started in 0.562 seconds > 2011-03-28 16:46:23,542 [main] INFO=A0 agentsmith.routes.SimpleRouteTest= =A0 - > *************************************************************************= ******* > 2011-03-28 16:46:23,543 [main] INFO=A0 agentsmith.routes.SimpleRouteTest= =A0 - > Testing: testSendMessage(agentsmith.routes.SimpleRouteTest) > 2011-03-28 16:46:23,543 [main] INFO=A0 agentsmith.routes.SimpleRouteTest= =A0 - > *************************************************************************= ******* > 2011-03-28 16:46:23,547 [main] INFO > org.apache.camel.impl.InterceptSendToMockEndpointStrategy=A0 - Adviced > endpoint [direct://start] with mock endpoint [mock:direct:start] > 2011-03-28 16:46:23,557 [main] INFO > org.apache.camel.impl.InterceptSendToMockEndpointStrategy=A0 - Adviced > endpoint [direct://end] with mock endpoint [mock:direct:end] > 2011-03-28 16:46:23,558 [main] INFO > org.apache.camel.impl.InterceptSendToMockEndpointStrategy=A0 - 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=A0 - Asserting: > Endpoint[mock://spring-event:default] is satisfied > 2011-03-28 16:46:23,577 [main] INFO > org.apache.camel.component.mock.MockEndpoint=A0 - Asserting: > Endpoint[mock://direct:end] is satisfied > > java.lang.AssertionError: mock://direct:end Received message count. > Expected: <1> but was: <0> > =A0=A0=A0 at > org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086) > .... > > > > > > > > > > > > > On Mon, Mar 28, 2011 at 4:37 PM, Claus Ibsen wrot= e: >> >> On Mon, Mar 28, 2011 at 5:34 PM, Tom Howe wrote: >> > I've read the testing page but it doesnt give any good eaxmple of usin= g >> > 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 >> > 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 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 >> >> > =A0 =A0 > >> http://camel.apache.org/schema/spring >> >> > "> >> >> > =A0 =A0 =A0 =A0 =A0 =A0 >> >> > =A0 =A0 =A0 =A0 =A0 =A0 >> >> > =A0 =A0 =A0 =A0 >> >> > >> >> > So I created CamelRoutesTest.xml containing: >> >> > >> >> > =A0 =A0 >> >> > =A0 =A0> >> > class=3D"org.apache.camel.impl.InterceptSendToMockEndpointStrategy"= /> >> >> > >> >> > but I am not sure how to create a test that both loads the spring x= ml >> >> > AND >> >> > provides access to the mock endpoints. >> >> > >> >> > If I use.. >> >> > >> >> > @ContextConfiguration( locations=3D("/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/ > > --=20 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/