You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by riddellg <gr...@libertymutual.com> on 2015/12/10 16:52:10 UTC

JUnit, Interceptors and Notifys in a webapp

I love the Interceptors and Notifys when running a Spring DSL camel
application standalone under JUnit. However our operational deployment model
is as a war/webapp rather than a standalone Spring app. I am trying to
figure out how to attach Interceptors and Notifiers from a JUnit test onto a
route that is running in a webapp.

I can start Tomcat from the JUnit setup() and publish my war into it, and
the route starts up. (I'm using the CamelTestSpringSupport for JUnit, and
using the "tomcat-embed-core" dependency to start Tomcat from JUnit). 
However in my JUnit test class I have to instantiate an
AbstractXMLApplicationContext which starts a new CamelContext, even though I
am referencing the same camel config file. So my JUnit client is not
actually hitting the code running in the webapp. Is it possible to get a
handle from the JUnit test code to the CamelContext that is running under
Tomcat? And pass that back in the "createApplicationContext". 

As far as I can tell the Tomcat that is started is in the same JVM, and the
camel route is auto-assigned a name ("camel-1") and then "camel-3" for the
JUnit one, so it seems that the CamelContexts might be aware of each other.

Some code below showing what I'm trying to do. Anyone know if this is
possible?



public class TestEmailServiceIntercept extends CamelSpringTestSupport {

    @Override
    protected AbstractXmlApplicationContext createApplicationContext() 
    {
    	return new ClassPathXmlApplicationContext("camel-config.xml");
    }

    @Test
    public void testCloudantException() throws Exception 
    {
	RouteDefinition route = context.getRouteDefinition("main");
    	route.adviceWith(context, new RouteBuilder()
	{
		public void configure() throws Exception
		{
		interceptSendToEndpoint("bean:cloudantClient?method=storeToCloudant")
			.process(new SimulateCloudantResponseProcessor("EXCEPTION"));
		}
	});

thanks for any help,



--
View this message in context: http://camel.465427.n5.nabble.com/JUnit-Interceptors-and-Notifys-in-a-webapp-tp5774946.html
Sent from the Camel - Users mailing list archive at Nabble.com.