camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: CAMEL-7380 Added test support for Spring ContextHierarchy
Date Wed, 11 Jun 2014 04:14:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master 0c9fbb62b -> aa9e4ce5e


CAMEL-7380 Added test support for Spring ContextHierarchy


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b4bb8fa2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b4bb8fa2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b4bb8fa2

Branch: refs/heads/master
Commit: b4bb8fa2da0625077d2118de311333ffddd29676
Parents: 0c9fbb6
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Jun 11 12:09:45 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Jun 11 12:09:45 2014 +0800

----------------------------------------------------------------------
 .../spring/CamelSpringTestContextLoader.java    | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b4bb8fa2/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
index 18fa9c3..e973b44 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
@@ -79,7 +79,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
         }
         
         try {            
-            GenericApplicationContext context = createContext(testClass);
+            GenericApplicationContext context = createContext(testClass, mergedConfig);
             context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
             loadBeanDefinitions(context, mergedConfig);
             return loadContext(context, testClass);
@@ -111,7 +111,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
         }
         
         try {
-            GenericApplicationContext context = createContext(testClass);
+            GenericApplicationContext context = createContext(testClass, null);
             loadBeanDefinitions(context, locations);
             return loadContext(context, testClass);
         } finally {
@@ -196,9 +196,15 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
      * @param testClass the test class that is being executed
      * @return the loaded Spring context
      */
-    protected GenericApplicationContext createContext(Class<?> testClass) {
+    protected GenericApplicationContext createContext(Class<?> testClass, MergedContextConfiguration
mergedConfig) {
+        ApplicationContext parentContext = null;
         GenericApplicationContext routeExcludingContext = null;
         
+        if (mergedConfig != null) {
+            parentContext = mergedConfig.getParentApplicationContext();
+
+        }
+        
         if (testClass.isAnnotationPresent(ExcludeRoutes.class)) {
             Class<?>[] excludedClasses = testClass.getAnnotation(ExcludeRoutes.class).value();
             
@@ -208,7 +214,11 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
                             + "annotation was found. Excluding [" + StringUtils.arrayToCommaDelimitedString(excludedClasses)
+ "].");
                 }
                 
-                routeExcludingContext = new GenericApplicationContext();
+                if (parentContext == null) {
+                    routeExcludingContext = new GenericApplicationContext();
+                } else {
+                    routeExcludingContext = new GenericApplicationContext(parentContext);
+                }
                 routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
                 routeExcludingContext.refresh();
                 
@@ -228,7 +238,11 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
         if (routeExcludingContext != null) {
             context = new GenericApplicationContext(routeExcludingContext);
         } else {
-            context = new GenericApplicationContext();
+            if (parentContext != null) {
+                context = new GenericApplicationContext(parentContext);
+            } else {
+                context = new GenericApplicationContext();
+            }
         }
         
         return context;


Mime
View raw message