Author: davsclaus
Date: Thu May 12 08:19:36 2011
New Revision: 1102200

URL: http://svn.apache.org/viewvc?rev=1102200&view=rev
Log:
CAMEL-3960: camel-testng now also supports create camel context per class. And 
aligned the code from camel-test to camel-testng.

Modified:
    
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
    
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java

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=1102200&r1=1102199&r2=1102200&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
 Thu May 12 08:19:36 2011
@@ -78,6 +78,10 @@ public abstract class CamelTestSupport e
         return useRouteBuilder;
     }
 
+    public void setUseRouteBuilder(boolean useRouteBuilder) {
+        this.useRouteBuilder = useRouteBuilder;
+    }
+
     /**
      * Override to control whether {@link CamelContext} should be setup per 
test or per class.
      * <p/>
@@ -104,10 +108,6 @@ public abstract class CamelTestSupport e
         return null;
     }
 
-    public void setUseRouteBuilder(boolean useRouteBuilder) {
-        this.useRouteBuilder = useRouteBuilder;
-    }
-
     public Service getCamelContextService() {
         return camelContextService;
     }

Modified: 
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java?rev=1102200&r1=1102199&r2=1102200&view=diff
==============================================================================
--- 
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
 (original)
+++ 
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
 Thu May 12 08:19:36 2011
@@ -30,42 +30,44 @@ import org.apache.camel.impl.scan.Invert
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
+import org.junit.AfterClass;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
 import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
 
 /**
  * @version $Revision$
  */
 public abstract class CamelSpringTestSupport extends CamelTestSupport {
-    protected AbstractApplicationContext applicationContext;
+    protected static AbstractApplicationContext applicationContext;
     protected abstract AbstractApplicationContext createApplicationContext();
 
     @Override
-    @BeforeTest
-    public void setUp() 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(applicationContext, "Should have created a valid 
spring context");
-            super.setUp();
-            System.clearProperty("maybeStartCamelContext");
-        } else {
-            log.info("Skipping starting CamelContext as system property 
skipStartingCamelContext is set to be true.");
-        }
+    public void doSetUp() throws Exception {
+        applicationContext = createApplicationContext();
+        super.doSetUp();
     }
 
     @Override
     @AfterTest
     public void tearDown() throws Exception {
         super.tearDown();
+
+        if (!isCreateCamelContextPerClass()) {
+            if (applicationContext != null) {
+                applicationContext.destroy();
+                applicationContext = null;
+            }
+        }
+    }
+
+    @AfterClass
+    public static void tearSpringDownAfterClass() throws Exception {
         if (applicationContext != null) {
             applicationContext.destroy();
+            applicationContext = null;
         }
     }
 


Reply via email to