Author: davsclaus
Date: Wed May 18 11:36:38 2011
New Revision: 1124198
URL: http://svn.apache.org/viewvc?rev=1124198&view=rev
Log:
CAMEL-3960: Fixed camel-test junit4 spring, may start spring multiple times,
due last commit had a flaw.
Modified:
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
Modified:
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java?rev=1124198&r1=1124197&r2=1124198&view=diff
==============================================================================
---
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
(original)
+++
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
Wed May 18 11:36:38 2011
@@ -46,15 +46,13 @@ public abstract class CamelSpringTestSup
protected abstract AbstractApplicationContext createApplicationContext();
@Override
- @Before
- public void setUp() throws Exception {
+ public void doPreSetup() throws Exception {
if
(!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) {
// tell camel-spring it should not trigger starting CamelContext,
since we do that later
// after we are finished setting up the unit test
System.setProperty("maybeStartCamelContext", "false");
applicationContext = createApplicationContext();
assertNotNull("Should have created a valid spring context",
applicationContext);
- super.setUp();
System.clearProperty("maybeStartCamelContext");
} else {
log.info("Skipping starting CamelContext as system property
skipStartingCamelContext is set to be true.");
@@ -62,12 +60,6 @@ public abstract class CamelSpringTestSup
}
@Override
- public void doSetUp() throws Exception {
- applicationContext = createApplicationContext();
- super.doSetUp();
- }
-
- @Override
@After
public void tearDown() throws Exception {
super.tearDown();
Modified:
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java?rev=1124198&r1=1124197&r2=1124198&view=diff
==============================================================================
---
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
(original)
+++
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
Wed May 18 11:36:38 2011
@@ -90,6 +90,9 @@ public abstract class CamelTestSupport e
* <p/>
* <b>Important:</b> Use this with care as the {@link CamelContext} will
carry over state
* from previous tests, such as endpoints, components etc. So you cannot
use this in all your tests.
+ * <p/>
+ * Setting up {@link CamelContext} uses the {@link #doPreSetup()}, {@link
#doSetUp()}, and {@link #doPostSetup()}
+ * methods in that given order.
*
* @return <tt>true</tt> per class, <tt>false</tt> per test.
*/
@@ -131,7 +134,9 @@ public abstract class CamelTestSupport e
if (isCreateCamelContextPerClass()) {
// test is per class, so only setup once (the first time)
if (first) {
+ doPreSetup();
doSetUp();
+ doPostSetup();
} else {
// and in between tests we must do IoC and reset mocks
postProcessTest();
@@ -139,11 +144,27 @@ public abstract class CamelTestSupport e
}
} else {
// test is per test so always setup
+ doPreSetup();
doSetUp();
+ doPostSetup();
}
}
- protected void doSetUp() throws Exception {
+ /**
+ * Strategy to perform any pre setup, before {@link CamelContext} is
created
+ */
+ protected void doPreSetup() throws Exception {
+ // noop
+ }
+
+ /**
+ * Strategy to perform any post setup after {@link CamelContext} is
createt.
+ */
+ protected void doPostSetup() throws Exception {
+ // noop
+ }
+
+ private void doSetUp() throws Exception {
log.debug("setUp test");
if (!useJmx()) {
disableJMX();