-
1. Re: Want to stop then start Spring ApplicationContext
davsclaus Sep 13, 2012 2:28 AM (in response to marc.blomquist)If you restart the spring app ctx in an unit test you would need to lookup the mock endpoint again after the start, to set its expectations, and as well to create a new producer template etc.
As the built-in from the CamelTestSupport class is from the first CamelContext that was loaded, before you restart the spring app ctx manually.
-
2. Re: Want to stop then start Spring ApplicationContext
marc.blomquist Sep 13, 2012 11:25 AM (in response to davsclaus)davsclaus I tried to do what you said but still have issues. I'm extending org.apache.camel.test.junit4.CamelTestSupport for the test case class. So I dug through CamelTestSupport class to figure out how everything is initialized and I found the setUp() function.
public void setUp() throws Exception {
applicationContext = createApplicationContext();
assertNotNull("Should have created a valid spring context", applicationContext);
supper.setUp();
}
I decided not to use this function because I don't want to create the application context again, which would defeat the purpose of what I'm trying to do. Instead I decided to use CamelTestSupport's setUp function. So I copy pasted CamelTestSupport's function into my class, renamed it to reSetUp() and tried to run the test again. The error I get this time round is the following exception, "Should have at least one route."
This is coming directly from the following two lines in CamelTestSupport.setUp()
context = createCamelContext();
assertValidContext(context);
The createCamelContext() function is invoking the following function from CamelSpringTestSupport
protected CamelContext createCamelContext() throws Exception {
return SpringCamelContext.springCamelContext(applicationContext);
}
Am I to assume that once I stop a Spring ApplicationContext that all the camel routes are destroyed?
I've attached my code because this is starting to get a little too complicated to just provide snippets.
-
SimpleRoute.xml 800 bytes
-
SimpleRouteTest.java 4.4 KB
-
-
3. Re: Want to stop then start Spring ApplicationContext
davsclaus Sep 14, 2012 1:39 AM (in response to marc.blomquist)Yes if you use a Spring XML file to embed Camel, eg in the XML file you have then the lifecycle of Spring will also start|stop Camel and all its routes/components etc.
-
4. Re: Want to stop then start Spring ApplicationContext
marc.blomquist Sep 17, 2012 9:41 AM (in response to davsclaus)I'm confused by your choice of words. You say "start/stop" but the error message I'm getting makes it sound like the route is "destroyed". If the CamelContext and all its routes have only been stopped as you say then why can't I start them again? Why is org.apache.camel.test.junit4.CamelTestSupport setup function failing with the error message "Should have at least one route." ?
-
5. Re: Want to stop then start Spring ApplicationContext
davsclaus Sep 17, 2012 11:19 AM (in response to marc.blomquist)The CamelSpringTestSupport class is based on loading a spring xml file, which contains a single CamelContext.
If you want to test multiple camel contexts and re-load the files etc. Then it may be easier with a plain TestCase and do it yourself.
That last error message is because the CamelSpringTestSupport expects to be at least 1 route. There is a method you can override and return 0. This check has been removed in newer Camel releases where you dont need this anymore.
-
6. Re: Want to stop then start Spring ApplicationContext
marc.blomquist Sep 17, 2012 1:37 PM (in response to davsclaus)That is unfortunate. I'll create my own test case.