Author: ningjiang
Date: Fri Dec  9 08:27:23 2011
New Revision: 1212276

URL: http://svn.apache.org/viewvc?rev=1212276&view=rev
Log:
CAMEL-4756 Fixed the NPE error of when setting the system property of 
skipStartingCamelContext to be true

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

Modified: 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=1212276&r1=1212275&r2=1212276&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
 Fri Dec  9 08:27:23 2011
@@ -83,10 +83,12 @@ public class SpringCamelContext extends 
     }
     
     public static SpringCamelContext springCamelContext(ApplicationContext 
applicationContext, boolean maybeStart) throws Exception {
-        // lets try and look up a configured camel context in the context
-        String[] names = 
applicationContext.getBeanNamesForType(SpringCamelContext.class);
-        if (names.length == 1) {
-            return (SpringCamelContext)applicationContext.getBean(names[0], 
SpringCamelContext.class);
+        if (applicationContext != null) {
+            // lets try and look up a configured camel context in the context
+            String[] names = 
applicationContext.getBeanNamesForType(SpringCamelContext.class);
+            if (names.length == 1) {
+                return 
(SpringCamelContext)applicationContext.getBean(names[0], 
SpringCamelContext.class);
+            }
         }
         SpringCamelContext answer = new SpringCamelContext();
         answer.setApplicationContext(applicationContext);

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=1212276&r1=1212275&r2=1212276&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
 Fri Dec  9 08:27:23 2011
@@ -185,14 +185,15 @@ public abstract class CamelSpringTestSup
     @Override
     protected void assertValidContext(CamelContext context) {
         super.assertValidContext(context);
-
-        List<Route> routes = context.getRoutes();
-        int routeCount = getExpectedRouteCount();
-        if (routeCount > 0) {
-            assertNotNull("Should have some routes defined", routes);
-            assertTrue("Should have at least one route", routes.size() >= 
routeCount);
+        if 
(!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) {
+            List<Route> routes = context.getRoutes();
+            int routeCount = getExpectedRouteCount();
+            if (routeCount > 0) {
+                assertNotNull("Should have some routes defined", routes);
+                assertTrue("Should have at least one route", routes.size() >= 
routeCount);
+            }
+            log.debug("Camel Routes: " + routes);
         }
-        log.debug("Camel Routes: " + routes);
     }
 
     protected int getExpectedRouteCount() {


Reply via email to