You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Davis Ford <df...@axeda.com> on 2011/09/23 21:20:12 UTC
testing camel proxy with a mock camel endpoint?
Hi, I'm using the camel proxy feature to inject a proxy interface into my class for remoting.
Example:
<!-- camel JMS Producer: can send messages to ActiveMQ server -->
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${camel.broker.url}" />
</bean>
<bean id="myBean" name="myBean" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
<property name="serviceUrl" value="jms:queue:incoming" />
<property name="serviceInterface" value="com.example.MyBeanInterface" />
</bean>
So, in deployment the server will be on a remote node. I can wire up a test case like this:
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTest {
@Resource(name="myBean") MyBeanInterface bean;
@Test
public void test() throws Exception {
String retval = bean.callSomeMethod();
}
}
So, this all works if the AMQ JMS server is up and running, but what I want to do is have it test instead against the camel mock endpoint, but it isn't clear to me exactly how I can do this. The examples I've seen don't tend to talk about the CamelProxyFactoryBean so much.
What I'd like to do is when my test calls:
String retval = bean.callSomeMethod();
I want it to go against the camel mock endpoint and then return a value I specify (this is using the JMS InOut pattern).
Can someone show me a clean way to accomplish that?
Re: testing camel proxy with a mock camel endpoint?
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 23, 2011 at 11:08 PM, Davis Ford <df...@axeda.com> 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:dford@axeda.com]
> Sent: Friday, September 23, 2011 4:39 PM
> To: users@camel.apache.org
> 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:dford@axeda.com]
> Sent: Friday, September 23, 2011 3:20 PM
> To: users@camel.apache.org
> Subject: testing camel proxy with a mock camel endpoint?
>
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
RE: testing camel proxy with a mock camel endpoint?
Posted by Davis Ford <df...@axeda.com>.
Removing the subclass for CamelTestSupport and instead doing
mockEndpoint = camelContext.getEndpoint("mock:queue.incoming");
fixes the issue.
-----Original Message-----
From: Davis Ford [mailto:dford@axeda.com]
Sent: Friday, September 23, 2011 4:39 PM
To: users@camel.apache.org
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:dford@axeda.com]
Sent: Friday, September 23, 2011 3:20 PM
To: users@camel.apache.org
Subject: testing camel proxy with a mock camel endpoint?
RE: testing camel proxy with a mock camel endpoint?
Posted by Davis Ford <df...@axeda.com>.
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:dford@axeda.com]
Sent: Friday, September 23, 2011 3:20 PM
To: users@camel.apache.org
Subject: testing camel proxy with a mock camel endpoint?