camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [09/12] camel git commit: CAMEL-9161 Change for dealing with parent contexts
Date Wed, 11 Nov 2015 07:16:32 GMT
CAMEL-9161 Change for dealing with parent contexts


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

Branch: refs/heads/camel-2.15.x
Commit: cc6d569fe049828e5d79bbfdc62a29b85ae92157
Parents: 71af845
Author: Nick Stuart <nick@portlandwebworks.com>
Authored: Tue Nov 10 09:19:07 2015 -0500
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Nov 11 08:19:29 2015 +0100

----------------------------------------------------------------------
 .../camel/spring/boot/RoutesCollector.java      |  5 +-
 .../parent/SpringBootRefreshContextTest.java    | 57 ++++++++++++++++++++
 .../parent/SpringBootWithParentContextTest.java | 51 ------------------
 3 files changed, 60 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cc6d569f/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
index 2b0a050..4aaa05d 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.model.RoutesDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,8 +52,8 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
         ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
-        if (applicationContext.getParent() == null) {
-            CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
+		CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
+        if (camelContext.getStatus() == ServiceStatus.Stopped) {
             LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
             for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class).values())
{
                 try {

http://git-wip-us.apache.org/repos/asf/camel/blob/cc6d569f/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootRefreshContextTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootRefreshContextTest.java
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootRefreshContextTest.java
new file mode 100644
index 0000000..dd2dc3b
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootRefreshContextTest.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.boot.parent;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.boot.RoutesCollector;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.context.support.GenericApplicationContext;
+
+public class SpringBootRefreshContextTest {
+
+    @Test
+    public void shouldOnlyCollectRoutesOnce() {
+        GenericApplicationContext parent = new GenericApplicationContext();
+        parent.refresh();
+		ConfigurableApplicationContext context = new SpringApplicationBuilder(Configuration.class).web(false).parent(parent).run();
+		ContextRefreshedEvent refreshEvent = new ContextRefreshedEvent(context);
+		RoutesCollector collector = context.getBean(RoutesCollector.class);
+		collector.onApplicationEvent(refreshEvent); //no changes should happen here
+    }
+
+}
+
+@SpringBootApplication
+class Configuration {
+
+    @Bean
+    RoutesBuilder routes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:test").to("mock:test");
+            }
+        };
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/cc6d569f/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootWithParentContextTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootWithParentContextTest.java
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootWithParentContextTest.java
deleted file mode 100644
index 6a1c16a..0000000
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/parent/SpringBootWithParentContextTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.spring.boot.parent;
-
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.support.GenericApplicationContext;
-
-public class SpringBootWithParentContextTest {
-
-    @Test
-    public void shouldCollectRoutesOnlyInRootContext() {
-        GenericApplicationContext parent = new GenericApplicationContext();
-        parent.refresh();
-        new SpringApplicationBuilder(Configuration.class).web(false).parent(parent).run();
-    }
-
-}
-
-@SpringBootApplication
-class Configuration {
-
-    @Bean
-    RoutesBuilder routes() {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("seda:test").to("mock:test");
-            }
-        };
-    }
-
-}
\ No newline at end of file


Mime
View raw message