Repository: camel Updated Branches: refs/heads/master 04fa8fe52 -> 9ac4768ee
Fix for CAMEL-10279 - Can't use @ImportResource and configure() in the same SB app. This assumes there is always a RouteBuilder in a SB app. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9ac4768e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9ac4768e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9ac4768e Branch: refs/heads/master Commit: 9ac4768eedacd7ec89cbf7faf80dab35f3154481 Parents: 04fa8fe Author: Hiram Chirino <[email protected]> Authored: Wed Aug 31 11:48:09 2016 -0400 Committer: Hiram Chirino <[email protected]> Committed: Wed Aug 31 13:43:58 2016 -0400 ---------------------------------------------------------------------- components/camel-spring-boot/pom.xml | 13 +++++++++++++ .../camel/spring/boot/CamelAutoConfiguration.java | 1 + .../fatjarroutertests/JUnitFatJarRouterTest.java | 13 ++++++++++++- .../StandaloneFatJarRouterTest.java | 14 +++++++++++++- .../boot/fatjarroutertests/TestFatJarRouter.java | 2 ++ .../src/test/resources/test-camel-context.xml | 17 +++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/pom.xml b/components/camel-spring-boot/pom.xml index 4ce1580..86097d4 100644 --- a/components/camel-spring-boot/pom.xml +++ b/components/camel-spring-boot/pom.xml @@ -106,4 +106,17 @@ </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkCount>1</forkCount> + <reuseForks>false</reuseForks> + </configuration> + </plugin> + </plugins> + </build> + </project> http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index d9ed0a0..4ae9308 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -185,6 +185,7 @@ public class CamelAutoConfiguration { @Bean CamelSpringBootApplicationController applicationController(ApplicationContext applicationContext, CamelContext camelContext) { + SpringCamelContext.setNoStart(true); return new CamelSpringBootApplicationController(applicationContext, camelContext); } http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/JUnitFatJarRouterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/JUnitFatJarRouterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/JUnitFatJarRouterTest.java index 2c1611c..828bc72 100644 --- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/JUnitFatJarRouterTest.java +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/JUnitFatJarRouterTest.java @@ -17,7 +17,9 @@ package org.apache.camel.spring.boot.fatjarroutertests; import java.io.IOException; +import java.lang.management.ManagementFactory; import java.net.URL; +import java.util.Set; import org.apache.commons.io.IOUtils; import org.junit.Assert; @@ -28,6 +30,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + @RunWith(SpringRunner.class) @SpringBootTest(classes = TestFatJarRouter.class, properties = "spring.main.sources=org.apache.camel.spring.boot.fatjarroutertests") public class JUnitFatJarRouterTest extends Assert { @@ -40,10 +46,15 @@ public class JUnitFatJarRouterTest extends Assert { } @Test - public void shouldStartCamelRoute() throws InterruptedException, IOException { + public void shouldStartCamelRoute() throws InterruptedException, IOException, MalformedObjectNameException { String response = IOUtils.toString(new URL("http://localhost:" + port)); assertEquals("stringBean", response); + + // There should be 3 routes running.. + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + Set<ObjectName> objectNames = mbs.queryNames(new ObjectName("org.apache.camel:type=routes,*"), null); + assertEquals(3, objectNames.size()); } } http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java index 5c6394d..79f3c9e 100644 --- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java @@ -17,8 +17,10 @@ package org.apache.camel.spring.boot.fatjarroutertests; import java.io.IOException; +import java.lang.management.ManagementFactory; import java.net.ConnectException; import java.net.URL; +import java.util.Set; import java.util.concurrent.Callable; import static java.util.concurrent.TimeUnit.MINUTES; @@ -30,12 +32,17 @@ import org.junit.Assert; import org.junit.Test; import org.springframework.util.SocketUtils; +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + import static com.jayway.awaitility.Awaitility.await; public class StandaloneFatJarRouterTest extends Assert { @Test - public void shouldStartCamelRoute() throws InterruptedException, IOException { + public void shouldStartCamelRoute() throws InterruptedException, IOException, MalformedObjectNameException { // Given final int port = SocketUtils.findAvailableTcpPort(20000); final URL httpEndpoint = new URL("http://localhost:" + port); @@ -62,6 +69,11 @@ public class StandaloneFatJarRouterTest extends Assert { // Then assertEquals("stringBean", response); + + // There should be 3 routes running.. + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + Set<ObjectName> objectNames = mbs.queryNames(new ObjectName("org.apache.camel:type=routes,*"), null); + assertEquals(3, objectNames.size()); } } http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/TestFatJarRouter.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/TestFatJarRouter.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/TestFatJarRouter.java index ed44d5c..1609f49 100644 --- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/TestFatJarRouter.java +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/TestFatJarRouter.java @@ -19,8 +19,10 @@ package org.apache.camel.spring.boot.fatjarroutertests; import org.apache.camel.spring.boot.FatJarRouter; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportResource; @SpringBootApplication +@ImportResource({"classpath:test-camel-context.xml"}) public class TestFatJarRouter extends FatJarRouter { @Override http://git-wip-us.apache.org/repos/asf/camel/blob/9ac4768e/components/camel-spring-boot/src/test/resources/test-camel-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/test/resources/test-camel-context.xml b/components/camel-spring-boot/src/test/resources/test-camel-context.xml new file mode 100644 index 0000000..a21e380 --- /dev/null +++ b/components/camel-spring-boot/src/test/resources/test-camel-context.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <!-- Camel Route --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="timer://foo?period=1000"/> + <setBody><simple>Hello World from camel-contex.xml</simple></setBody> + <log message=">>> ${body}"/> + </route> + </camelContext> + +</beans>
