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.
Tom you already posted this on the Camel mailing list. I suggest that you write this when you post a Q here as well.
The answer is already posted here http://camel.465427.n5.nabble.com/Problems-testing-Camel-with-Spring-config-tp4267754p4267754.html
Solved using:
public class CamelTest extends CamelSpringTestSupport {
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("/CamelRoutesTest.xml");
}
@Test
@DirtiesContext
public void discover() throws Exception {
getMockEndpoint("mock:my.route.out").expectedMessageCount(1);
template.sendBody("direct:my.route.in", FileUtils.slurpClassPathFile("/samples/sample.data.xml"));
assertMockEndpointsSatisfied();
}
}
Thanks for this solution, @Tom !
I also had a hard time getting Camel to work with my Spring-powered JUnit tests, problem is the suggested CamelSpringJUnit4ClassRunner has now moved from camel-spring.jar to a separate module, camel-spring-test.jar, which is not available in the standard camel-distribution as of 2.9.2.
So I cannot use @RunWith but had to resort to the manual method described in the solution...
精彩评论