On Fri, Sep 23, 2011 at 11:08 PM, Davis Ford <[email protected]> wrote: > Removing the subclass for CamelTestSupport and instead doing > > mockEndpoint = camelContext.getEndpoint("mock:queue.incoming"); >
Ah you are using Spring Testing (eg those two @ annotations) on your class. And therefore you need to IoC the stuff you need. Alternatively there is a CamelSpringTestSupport that is suitable for testing with Camel + Spring. > fixes the issue. > > -----Original Message----- > From: Davis Ford [mailto:[email protected]] > Sent: Friday, September 23, 2011 4:39 PM > To: [email protected] > Subject: RE: testing camel proxy with a mock camel endpoint? > > Let me try a different approach to this question. I'm now injecting a > mock:url into the endpoints so this seems like it should work but it > doesn't... > > <bean id="myBean" name="myBean" > class="org.apache.camel.spring.remoting.CamelProxyFactoryBean"> > <property name="serviceUrl" value="mock:queue.incoming" /> > <property name="serviceInterface" value="com.example.MyBeanInterface" > /> > </bean> > > @ContextConfiguration(locations={"classpath:applicationContext.xml"}) > @RunWith(SpringJUnit4ClassRunner.class) > public class MyTest extends CamelTestSupport { > > @Resource(name="myBean") MyBeanInterface bean; > > MockEndpoint mockEndpoint; > > @Before > public void setUp() throws Exception { > super.setUp(); > mockEndpoint = getMockEndpoint("mock:queue.incoming"); > mockEndpoint.expectedMessageCount(1); > } > > @Test > public void test() throws Exception { > String retval = bean.callSomeMethod(); > mockEndpoint.assertIsSatisfied(); > } > } > > The test fails indicating that 1 message was expected but zero were received. > I'm not 100% certain why that is -- perhaps it has to do with the test > subclassing CamelTestSupport but using spring's JUnit 4 test runner, so maybe > they are two different camel context's ? i.e. one loaded in spring, and the > other instantiated by CamelTestSupport itself? > > Any ideas? > > -----Original Message----- > From: Davis Ford [mailto:[email protected]] > Sent: Friday, September 23, 2011 3:20 PM > To: [email protected] > Subject: testing camel proxy with a mock camel endpoint? > > -- Claus Ibsen ----------------- FuseSource Email: [email protected] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
