You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/09/09 14:18:56 UTC
[03/14] camel git commit: CAMEL-11756: camel-spring-boot2 - Work in
progress
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/CustomShutdownStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/CustomShutdownStrategyTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/CustomShutdownStrategyTest.java
new file mode 100644
index 0000000..bdf8d80
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/CustomShutdownStrategyTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultShutdownStrategy;
+import org.apache.camel.spi.RouteStartupOrder;
+import org.apache.camel.spi.ShutdownStrategy;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(classes = CustomShutdownStrategyTest.class)
+public class CustomShutdownStrategyTest extends Assert {
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Configuration
+ @EnableAutoConfiguration
+ public static class Config extends SpringRouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo").to("mock:foo");
+ }
+
+ @Bean
+ public ShutdownStrategy shutdownStrategy() {
+ ShutdownStrategy strat = new MyShutdown();
+ strat.setTimeout(60000);
+ return strat;
+ }
+
+ }
+
+ @Test
+ public void testCustomShutdown() throws Exception {
+ ShutdownStrategy stat = camelContext.getShutdownStrategy();
+ assertEquals(60000, stat.getTimeout());
+ assertTrue(stat instanceof MyShutdown);
+
+ camelContext.stop();
+
+ assertTrue(((MyShutdown)stat).isInvoked());
+ }
+
+ private static class MyShutdown extends DefaultShutdownStrategy {
+
+ private boolean invoked;
+
+ @Override
+ protected boolean doShutdown(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit,
+ boolean suspendOnly, boolean abortAfterTimeout, boolean forceShutdown) throws Exception {
+ invoked = true;
+ return super.doShutdown(context, routes, timeout, timeUnit, suspendOnly, abortAfterTimeout, forceShutdown);
+ }
+
+ boolean isInvoked() {
+ return invoked;
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java
new file mode 100644
index 0000000..4137954
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.support.DefaultConversionService;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(classes = ExistingConversionServiceTest.TestConfig.class)
+public class ExistingConversionServiceTest extends Assert {
+
+ @Autowired
+ @Qualifier("myService")
+ ConversionService conversionService;
+
+ @Test
+ public void shouldUseProvidedConversionService() {
+ assertSame(TestConfig.CONVERSION_SERVICE, conversionService);
+ }
+
+ @Configuration
+ public static class TestConfig {
+ static final ConversionService CONVERSION_SERVICE = new DefaultConversionService();
+
+ @Bean(name = "myService")
+ ConversionService providedConversionService() {
+ return CONVERSION_SERVICE;
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedBootAndXmlConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedBootAndXmlConfigurationTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedBootAndXmlConfigurationTest.java
new file mode 100644
index 0000000..6cfdc12
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedBootAndXmlConfigurationTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+ properties = {
+ "camel.springboot.name = camel-spring-boot",
+ "camel.springboot.shutdownTimeout = 5"
+ }
+)
+public class MixedBootAndXmlConfigurationTest {
+
+ @Autowired
+ private CamelContext camel;
+
+ @Test
+ public void thereShouldBeAutoConfiguredFromSpringBoot() {
+ Assert.assertEquals("camel-spring-boot", camel.getName());
+ Assert.assertEquals(5, camel.getShutdownStrategy().getTimeout());
+ }
+
+ @Configuration
+ @EnableAutoConfiguration
+ @ImportResource("classpath:mixed-camel-context.xml")
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedJavaDslAndXmlTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedJavaDslAndXmlTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedJavaDslAndXmlTest.java
new file mode 100644
index 0000000..1dbe394
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/MixedJavaDslAndXmlTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultRoute;
+import org.assertj.core.api.Condition;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class MixedJavaDslAndXmlTest {
+
+ @Configuration
+ @EnableAutoConfiguration
+ @ImportResource("classpath:test-camel-context.xml")
+ public static class JavaDslConfiguration {
+
+ @Bean
+ public RouteBuilder javaDsl() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:project?period=1s").id("java").setBody().constant("Hello World from Java Route")
+ .log(">>> ${body}");
+ }
+ };
+ }
+
+ }
+
+ @Autowired
+ private CamelContext camel;
+
+ @Test
+ public void thereShouldBeTwoRoutesConfigured() {
+ final List<Route> routes = camel.getRoutes();
+ assertThat(routes).as("There should be two routes configured, one from Java DSL and one from XML").hasSize(3);
+ final List<String> routeIds = routes.stream().map(Route::getId).collect(Collectors.toList());
+ assertThat(routeIds).as("Should contain routes from Java DSL, XML and auto-loaded XML").containsOnly("java",
+ "xml", "xmlAutoLoading");
+ assertThat(routes).as("All routes should be started").are(new Condition<Route>() {
+ @Override
+ public boolean matches(final Route route) {
+ return ((DefaultRoute) route).isStarted();
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/NoConvertersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/NoConvertersTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/NoConvertersTest.java
new file mode 100644
index 0000000..06a7b53
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/NoConvertersTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+import org.apache.camel.TypeConverter;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(classes = NoConvertersTest.class, properties = "camel.springboot.typeConversion=false")
+public class NoConvertersTest extends Assert {
+
+ @Autowired
+ ApplicationContext applicationContext;
+
+ @Test(expected = NoSuchBeanDefinitionException.class)
+ public void shouldNotProvideConverter() {
+ applicationContext.getBean(TypeConverter.class);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/PlainTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/PlainTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/PlainTest.java
new file mode 100644
index 0000000..004c8a4
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/PlainTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class PlainTest {
+
+ @Autowired
+ ApplicationContext applicationContext;
+
+ @Autowired(required = false)
+ CamelContext camelContext;
+
+ // turn off Camel auto configuration which should not inject a CamelContext
+ @Configuration
+ @EnableAutoConfiguration(exclude = CamelAutoConfiguration.class)
+ public static class MyConfiguration {
+ // empty
+ }
+
+ @Test
+ public void testPlain() {
+ Assert.assertNull("Should not auto configure CamelContext", camelContext);
+ Assert.assertEquals("Should not auto configure CamelAutoConfiguration", 0, applicationContext.getBeanNamesForType(CamelAutoConfiguration.class).length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/RouteConfigWithCamelContextInjected.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/RouteConfigWithCamelContextInjected.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/RouteConfigWithCamelContextInjected.java
new file mode 100644
index 0000000..042f7a8
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/RouteConfigWithCamelContextInjected.java
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.Assert;
+
+@Configuration
+public class RouteConfigWithCamelContextInjected {
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @Bean
+ public RoutesBuilder routeCreatedWithInjectedCamelContext() {
+ Assert.notNull(camelContext, "camelContext must not be null");
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("seda:test").to("seda:test");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
new file mode 100644
index 0000000..83c3332
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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;
+
+import org.apache.camel.TypeConverter;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(classes = SpringConverterDelegationTest.class, properties = "camel.springboot.typeConversion=true")
+public class SpringConverterDelegationTest extends Assert {
+
+ @Autowired
+ TypeConverter typeConverter;
+
+ @Test
+ public void shouldConvertUsingSpringConverter() {
+ String result = typeConverter.convertTo(String.class, new Convertable());
+ assertEquals("converted!", result);
+ }
+
+ @Configuration
+ public static class Config {
+ @Bean
+ ConvertableConverter convertableConverter() {
+ return new ConvertableConverter();
+ }
+
+ }
+
+ public static class Convertable {
+ }
+
+ public static class ConvertableConverter implements Converter<Convertable, String> {
+ @Override
+ public String convert(Convertable source) {
+ return "converted!";
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
new file mode 100644
index 0000000..5e14200
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.ConversionFailedException;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.ConverterNotFoundException;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.support.DefaultConversionService;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(classes = SpringTypeConverterTest.SpringTypeConversionConfiguration.class)
+public class SpringTypeConverterTest {
+ @Autowired
+ @Qualifier("camelSpringConversionService")
+ ConversionService conversionService;
+
+ @Autowired
+ @Qualifier("camelSpringTypeConverter")
+ SpringTypeConverter converter;
+
+ @Test
+ public void testConversionService() {
+ Collection<?> source = Arrays.asList(new Person("Name", 30));
+
+ Assert.assertFalse(conversionService.canConvert(Person.class, String.class));
+ Assert.assertTrue(conversionService.canConvert(source.getClass(), String.class));
+
+ try {
+ conversionService.convert(source, String.class);
+ } catch (ConversionFailedException e) {
+ // Expected as Person can't be converted to a string according to
+ // Spring's FallbackObjectToStringConverter, see javadoc for:
+ //
+ // org.springframework.core.convert.support.FallbackObjectToStringConverter
+ //
+ Assert.assertTrue(e.getCause() instanceof ConverterNotFoundException);
+ }
+
+
+ Assert.assertNull(converter.convertTo(String.class, source));
+ }
+
+ public static class Person {
+ private String name;
+ private int age;
+
+ public Person(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ @Override
+ public String toString() {
+ return "Person{"
+ + "name='" + name + '\''
+ + ", age=" + age
+ + '}';
+ }
+ }
+
+ @Configuration
+ public static class SpringTypeConversionConfiguration {
+ @Bean
+ ConversionService camelSpringConversionService(ApplicationContext applicationContext) {
+ DefaultConversionService service = new DefaultConversionService();
+ for (Converter converter : applicationContext.getBeansOfType(Converter.class).values()) {
+ service.addConverter(converter);
+ }
+
+ return service;
+ }
+ @Bean
+ SpringTypeConverter camelSpringTypeConverter(List<ConversionService> conversionServices) {
+ return new SpringTypeConverter(conversionServices);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
new file mode 100644
index 0000000..3884147
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
@@ -0,0 +1,238 @@
+/**
+ * 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;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.support.ServiceSupport;
+import org.junit.Test;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.Lifecycle;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class StartupShutdownOrderTest {
+
+ static class AutoCloseableBean implements AutoCloseable, TestState {
+
+ boolean closed;
+
+ private final ApplicationContext context;
+
+ public AutoCloseableBean(final ApplicationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void assertValid() {
+ assertThat(closed).as("AutoCloseable bean should be closed").isTrue();
+ }
+
+ @Override
+ public void close() {
+ assertThat(camelIsStopped(context)).as("AutoCloseable bean should be stopped after Camel").isTrue();
+ closed = true;
+ }
+ }
+
+ static class Beans {
+
+ @Bean
+ AutoCloseableBean autoCloseableBean(final ApplicationContext context) {
+ return new AutoCloseableBean(context);
+ }
+
+ @Bean
+ BeanWithShutdownMethod beanWithCloseMethod(final ApplicationContext context) {
+ return new BeanWithShutdownMethod(context);
+ }
+
+ @Bean
+ DisposeBean disposedBean(final ApplicationContext context) {
+ return new DisposeBean(context);
+ }
+
+ @Bean
+ InitBean initBean(final ApplicationContext context) {
+ return new InitBean(context);
+ }
+
+ @Bean
+ Lifecycle lifecycleBean(final ApplicationContext context) {
+ return new LifecycleBean(context);
+ }
+ }
+
+ static class BeanWithShutdownMethod implements TestState {
+
+ boolean shutdown;
+
+ private final ApplicationContext context;
+
+ public BeanWithShutdownMethod(final ApplicationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void assertValid() {
+ assertThat(shutdown).as("Bean with shutdown method should be shutdown").isTrue();
+ }
+
+ public void shutdown() {
+ assertThat(camelIsStopped(context)).as("@Bean with close() method should be stopped after Camel").isTrue();
+ shutdown = true;
+ }
+ }
+
+ static class DisposeBean implements DisposableBean, TestState {
+
+ boolean disposed;
+
+ private final ApplicationContext context;
+
+ public DisposeBean(final ApplicationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void assertValid() {
+ assertThat(disposed).as("DisposableBean should be disposed").isTrue();
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ assertThat(camelIsStopped(context)).as("DisposableBean should be stopped after Camel").isTrue();
+ disposed = true;
+ }
+ }
+
+ static class InitBean implements InitializingBean, TestState {
+
+ ApplicationContext context;
+
+ boolean initialized;
+
+ @Autowired
+ public InitBean(final ApplicationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ assertThat(camelIsStopped(context)).as("initializing bean should be started before Camel").isTrue();
+ initialized = true;
+ }
+
+ @Override
+ public void assertValid() {
+ assertThat(initialized).as("InitializingBean should be initialized").isTrue();
+ }
+ }
+
+ static class LifecycleBean implements SmartLifecycle, TestState {
+
+ ApplicationContext context;
+
+ boolean started;
+
+ boolean stopped;
+
+ @Autowired
+ public LifecycleBean(final ApplicationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void assertValid() {
+ assertThat(started).as("Lifecycle should have been started").isTrue();
+ assertThat(stopped).as("Lifecycle should be stopped").isTrue();
+ }
+
+ @Override
+ public int getPhase() {
+ return 0;
+ }
+
+ @Override
+ public boolean isAutoStartup() {
+ return true;
+ }
+
+ @Override
+ public boolean isRunning() {
+ return started;
+ }
+
+ @Override
+ public void start() {
+ assertThat(camelIsStopped(context)).as("lifecycle bean should be started before Camel").isTrue();
+ started = true;
+ }
+
+ @Override
+ public void stop() {
+ assertThat(camelIsStopped(context)).as("lifecycle bean should be stopped after Camel").isTrue();
+ stopped = true;
+ }
+
+ @Override
+ public void stop(final Runnable callback) {
+ stop();
+ callback.run();
+ }
+ }
+
+ interface TestState {
+ void assertValid();
+ }
+
+ @Test
+ public void camelContextShouldBeStartedLastAndStoppedFirst() {
+ final ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
+ CamelAutoConfiguration.class, Beans.class);
+
+ final ServiceSupport camelContext = (ServiceSupport) context.getBean(CamelContext.class);
+ final Map<String, TestState> testStates = context.getBeansOfType(TestState.class);
+
+ assertThat(camelContext.isStarted()).as("Camel context should be started").isTrue();
+
+ context.close();
+
+ assertThat(camelContext.isStopped()).as("Camel context should be stopped").isTrue();
+ testStates.values().stream().forEach(TestState::assertValid);
+ }
+
+ static ServiceSupport camel(final ApplicationContext context) {
+ return (ServiceSupport) context.getBean(CamelContext.class);
+ }
+
+ static boolean camelIsStarted(final ApplicationContext context) {
+ return camel(context).isStarted();
+ }
+
+ static boolean camelIsStopped(final ApplicationContext context) {
+ return !camelIsStarted(context);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
new file mode 100644
index 0000000..605cf01
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
@@ -0,0 +1,140 @@
+/**
+ * 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;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.SupervisingRouteController;
+import org.apache.camel.spring.boot.dummy.DummyComponent;
+import org.apache.camel.util.backoff.BackOffTimer;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.awaitility.Awaitility.await;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SupervisingRouteControllerAutoConfiguration.class,
+ SupervisingRouteControllerRestartTest.TestConfiguration.class
+ },
+ properties = {
+ "camel.springboot.xml-routes = false",
+ "camel.springboot.main-run-controller = true",
+ "camel.supervising.controller.enabled = true",
+ "camel.supervising.controller.initial-delay = 2s",
+ "camel.supervising.controller.default-back-off.delay = 1s",
+ "camel.supervising.controller.default-back-off.max-attempts = 10",
+ "camel.supervising.controller.routes.bar.back-off.delay = 10s",
+ "camel.supervising.controller.routes.bar.back-off.max-attempts = 3",
+ "camel.supervising.controller.routes.timer-unmanaged.supervise = false"
+ }
+)
+public class SupervisingRouteControllerRestartTest {
+
+ @Autowired
+ private CamelContext context;
+
+ @Test
+ public void testRouteRestart() throws Exception {
+ Assert.assertNotNull(context.getRouteController());
+ Assert.assertTrue(context.getRouteController() instanceof SupervisingRouteController);
+
+ SupervisingRouteController controller = context.getRouteController().unwrap(SupervisingRouteController.class);
+
+ // Wait for the controller to start the routes
+ await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+ // now its suspended by the policy
+ Assert.assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
+ Assert.assertEquals(ServiceStatus.Started, context.getRouteStatus("bar"));
+ Assert.assertEquals(ServiceStatus.Started, context.getRouteStatus("dummy"));
+ });
+
+ // restart the dummy route which should fail on first attempt
+ controller.stopRoute("dummy");
+
+ Assert.assertNull(context.getRoute("dummy").getRouteContext().getRouteController());
+
+ try {
+ controller.startRoute("dummy");
+ } catch (Exception e) {
+ Assert.assertEquals("Forced error on restart", e.getMessage());
+ }
+
+ Assert.assertTrue(controller.getBackOffContext("dummy").isPresent());
+ Assert.assertEquals(BackOffTimer.Task.Status.Active, controller.getBackOffContext("dummy").get().getStatus());
+ Assert.assertTrue(controller.getBackOffContext("dummy").get().getCurrentAttempts() > 0);
+
+ // Wait for wile to give time to the controller to start the route
+ await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
+ // now its suspended by the policy
+ Assert.assertEquals(ServiceStatus.Started, context.getRouteStatus("dummy"));
+ Assert.assertNotNull(context.getRoute("dummy").getRouteContext().getRouteController());
+ Assert.assertFalse(controller.getBackOffContext("dummy").isPresent());
+ });
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ getContext().addComponent("dummy", new DummyComponent());
+
+ from("timer:foo?period=5s")
+ .id("foo")
+ .startupOrder(2)
+ .to("mock:foo");
+ from("timer:bar?period=5s")
+ .id("bar")
+ .startupOrder(1)
+ .to("mock:bar");
+ from("timer:unmanaged?period=5s")
+ .id("timer-unmanaged")
+ .to("mock:timer-unmanaged");
+ from("timer:no-autostartup?period=5s")
+ .id("timer-no-autostartup")
+ .autoStartup(false)
+ .to("mock:timer-no-autostartup");
+
+ from("dummy:foo?failOnRestart=true")
+ .id("dummy")
+ .to("mock:dummy");
+ }
+ };
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
new file mode 100644
index 0000000..b1a43f0
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.SupervisingRouteController;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.util.backoff.BackOff;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SupervisingRouteControllerAutoConfiguration.class,
+ SupervisingRouteControllerTest.TestConfiguration.class
+ },
+ properties = {
+ "camel.springboot.xml-routes = false",
+ "camel.springboot.main-run-controller = true",
+ "camel.supervising.controller.enabled = true",
+ "camel.supervising.controller.initial-delay = 2s",
+ "camel.supervising.controller.default-back-off.delay = 1s",
+ "camel.supervising.controller.default-back-off.max-attempts = 10",
+ "camel.supervising.controller.routes.bar.back-off.delay = 10s",
+ "camel.supervising.controller.routes.bar.back-off.max-attempts = 3",
+ "camel.supervising.controller.routes.timer-unmanaged.supervise = false"
+ }
+)
+public class SupervisingRouteControllerTest {
+ @Autowired
+ private CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ Assert.assertNotNull(context.getRouteController());
+ Assert.assertTrue(context.getRouteController() instanceof SupervisingRouteController);
+
+ SupervisingRouteController controller = context.getRouteController().unwrap(SupervisingRouteController.class);
+
+ Assert.assertEquals(3, controller.getControlledRoutes().size());
+ Assert.assertEquals(2, controller.getInitialDelay().getSeconds());
+
+ // Route foo
+ BackOff foo = controller.getBackOff("foo");
+ Assert.assertEquals(1, foo.getDelay().getSeconds());
+ Assert.assertEquals(Long.MAX_VALUE, foo.getMaxDelay().toMillis());
+ Assert.assertEquals(10L, foo.getMaxAttempts().longValue());
+
+ // Route bar
+ BackOff bar = controller.getBackOff("bar");
+ Assert.assertEquals(10, bar.getDelay().getSeconds());
+ Assert.assertEquals(Long.MAX_VALUE, bar.getMaxDelay().toMillis());
+ Assert.assertEquals(3L, bar.getMaxAttempts().longValue());
+
+ Assert.assertEquals(controller, context.getRoute("foo").getRouteContext().getRouteController());
+ Assert.assertEquals(controller, context.getRoute("bar").getRouteContext().getRouteController());
+ Assert.assertNull(context.getRoute("timer-unmanaged").getRouteContext().getRouteController());
+ Assert.assertNull(context.getRoute("timer-no-autostartup").getRouteContext().getRouteController());
+
+ Assert.assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
+ Assert.assertEquals(ServiceStatus.Stopped, context.getRouteStatus("bar"));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+ private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:foo?period=5s")
+ .id("foo")
+ .startupOrder(2)
+ .to("mock:foo");
+ from("timer:bar?period=5s")
+ .id("bar")
+ .startupOrder(1)
+ .to("mock:bar");
+ from("timer:unmanaged?period=5s")
+ .id("timer-unmanaged")
+ .to("mock:timer-unmanaged");
+ from("timer:no-autostartup?period=5s")
+ .id("timer-no-autostartup")
+ .autoStartup(false)
+ .to("mock:timer-no-autostartup");
+
+ fromF("jetty:http://localhost:%d", PORT)
+ .id("jetty")
+ .to("mock:jetty");
+ }
+ };
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/ActuatorTestRoute.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/ActuatorTestRoute.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/ActuatorTestRoute.java
new file mode 100644
index 0000000..599f940
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/ActuatorTestRoute.java
@@ -0,0 +1,30 @@
+/**
+ * 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.actuate.endpoint;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ActuatorTestRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("timer:foo").routeId("foo-route").to("log:foo");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
new file mode 100644
index 0000000..ea6e8cb
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.actuate.endpoint;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteEndpointInfo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Test for the {@link CamelRoutesEndpoint} actuator endpoint.
+ */
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootApplication
+@SpringBootTest(classes = {CamelAutoConfiguration.class, CamelRoutesEndpointAutoConfiguration.class, ActuatorTestRoute.class})
+public class CamelRoutesEndpointTest extends Assert {
+
+ @Autowired
+ CamelRoutesEndpoint endpoint;
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Test
+ public void testRoutesEndpoint() throws Exception {
+ List<RouteEndpointInfo> routes = endpoint.invoke();
+
+ assertFalse(routes.isEmpty());
+ assertEquals(routes.size(), camelContext.getRoutes().size());
+ assertTrue(routes.stream().anyMatch(r -> "foo-route".equals(r.getId())));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
new file mode 100644
index 0000000..c0b1e45
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.actuate.endpoint;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteDetailsEndpointInfo;
+import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteEndpointInfo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Test for the {@link CamelRoutesEndpoint} actuator endpoint.
+ */
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootApplication
+@SpringBootTest(classes = {CamelAutoConfiguration.class, CamelRoutesEndpointAutoConfiguration.class, ActuatorTestRoute.class})
+public class CamelRoutesMvcEndpointTest extends Assert {
+
+ @Autowired
+ CamelRoutesMvcEndpoint endpoint;
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Test
+ public void testRoutesEndpoint() throws Exception {
+ List<RouteEndpointInfo> routes = (List<RouteEndpointInfo>)endpoint.invoke();
+
+ assertFalse(routes.isEmpty());
+ assertEquals(routes.size(), camelContext.getRoutes().size());
+ assertTrue(routes.stream().anyMatch(r -> "foo-route".equals(r.getId())));
+ }
+
+ @Test
+ public void testMvcRoutesEndpoint() throws Exception {
+ Object result = endpoint.detail("foo-route");
+
+ assertTrue(result instanceof RouteDetailsEndpointInfo);
+ assertEquals("foo-route", ((RouteDetailsEndpointInfo)result).getId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthTest.java
new file mode 100644
index 0000000..3e6b118
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/CamelHealthTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.actuate.health;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootApplication
+@SpringBootTest(classes = {CamelAutoConfiguration.class, CamelHealthAutoConfiguration.class, MyCamelRoute.class})
+public class CamelHealthTest extends Assert {
+
+ @Autowired
+ CamelHealthIndicator indicator;
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Test
+ public void shouldHaveHealth() throws Exception {
+ Health health = indicator.health();
+ assertNotNull(health);
+
+ String code = health.getStatus().getCode();
+ assertEquals("UP", code);
+
+ String version = (String) health.getDetails().get("version");
+ assertEquals(camelContext.getVersion(), version);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/MyCamelRoute.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/MyCamelRoute.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/MyCamelRoute.java
new file mode 100644
index 0000000..060165d
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/health/MyCamelRoute.java
@@ -0,0 +1,29 @@
+/**
+ * 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.actuate.health;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MyCamelRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("timer:foo").to("log:foo");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
new file mode 100644
index 0000000..4226323
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.cloud;
+
+import org.apache.camel.cloud.ServiceChooser;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.cloud.ServiceLoadBalancer;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootApplication()
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ CamelCloudAutoConfiguration.class,
+ CamelCloudServiceChooserAutoConfiguration.class
+ },
+ properties = {
+ "camel.cloud.enabled=false",
+ "camel.cloud.service-discovery.enabled=false",
+ "camel.cloud.service-filter.enabled=false",
+ "camel.cloud.service-chooser.enabled=true",
+ "camel.cloud.load-balancer.enabled=false",
+ "debug=false"
+ }
+)
+public class CamelCloudServiceCallConfigurationTest {
+ @Autowired
+ private ApplicationContext ctx;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Environment env = ctx.getEnvironment();
+
+ assertFalse(env.getProperty("camel.cloud.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.service-filter.enabled", Boolean.class));
+ assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", Boolean.class));
+
+ assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty());
+ assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty());
+ assertTrue(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
+ assertTrue(ctx.getBeansOfType(ServiceLoadBalancer.class).isEmpty());
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallGlobalConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallGlobalConfigurationTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallGlobalConfigurationTest.java
new file mode 100644
index 0000000..62946f7
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallGlobalConfigurationTest.java
@@ -0,0 +1,127 @@
+/**
+ * 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.cloud;
+
+import java.util.Properties;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ CamelCloudServiceCallGlobalConfigurationTest.TestConfiguration.class,
+ CamelCloudServiceCallGlobalConfigurationTest.SpringBootPropertySourceConfig.class,
+ }
+
+)
+public class CamelCloudServiceCallGlobalConfigurationTest {
+ @Autowired
+ private ProducerTemplate template;
+
+ @Test
+ public void testServiceCall() throws Exception {
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT1), template.requestBody("direct:start", null, String.class));
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT3), template.requestBody("direct:start", null, String.class));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+ @Bean
+ public RouteBuilder myRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .serviceCall("{{service.name}}");
+
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT1)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT1);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT2)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT2);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT3)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT3);
+ }
+ };
+ }
+ }
+
+ private static Properties getAllProperties() {
+
+ Properties prop = new Properties();
+ prop.put("service.name", "custom-svc-list");
+ prop.put("camel.cloud.load-balancer.enabled", false);
+ prop.put("camel.cloud.service-call.uri", "jetty:http://${service.name}/hello");
+ prop.put("camel.cloud.service-call.service-discovery", "sd");
+ prop.put("camel.cloud.service-call.service-filter", "sf");
+ prop.put("camel.cloud.service-discovery.configurations[sd].services[custom-svc-list]", SpringBootPropertyUtil.getDiscoveryServices());
+ prop.put("camel.cloud.service-filter.configurations[sf].blacklist[custom-svc-list]", SpringBootPropertyUtil.getServiceFilterBlacklist());
+ prop.put("ribbon.enabled", false);
+ prop.put("debug", false);
+ return prop;
+ }
+
+
+
+ // *************************************
+ // Config
+ //
+
+ @Configuration
+ public static class SpringBootPropertySourceConfig {
+
+ @Autowired
+ private ConfigurableEnvironment env;
+
+ @Bean
+ @Lazy(false)
+ public MutablePropertySources springBootPropertySource() {
+
+ MutablePropertySources sources = env.getPropertySources();
+ sources.addFirst(new PropertiesPropertySource("boot-test-property", CamelCloudServiceCallGlobalConfigurationTest.getAllProperties()));
+ return sources;
+
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallRefExpressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallRefExpressionTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallRefExpressionTest.java
new file mode 100644
index 0000000..c363367
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallRefExpressionTest.java
@@ -0,0 +1,133 @@
+/**
+ * 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.cloud;
+
+import java.util.Properties;
+
+import org.apache.camel.Expression;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.language.SimpleExpression;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ CamelCloudServiceCallRefExpressionTest.TestConfiguration.class,
+ CamelCloudServiceCallRefExpressionTest.SpringBootPropertySourceConfig.class
+ }
+
+)
+public class CamelCloudServiceCallRefExpressionTest {
+ @Autowired
+ private ProducerTemplate template;
+
+ @Test
+ public void testServiceCall() throws Exception {
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT1), template.requestBody("direct:start", null, String.class));
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT3), template.requestBody("direct:start", null, String.class));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+ @Bean
+ Expression myExpression() {
+ return new SimpleExpression(
+ "jetty:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/hello"
+ );
+ }
+
+ @Bean
+ public RouteBuilder myRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .serviceCall("{{service.name}}");
+
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT1)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT1);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT2)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT2);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT3)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT3);
+ }
+ };
+ }
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class SpringBootPropertySourceConfig {
+
+ @Autowired
+ private ConfigurableEnvironment env;
+
+ @Bean
+ @Lazy(false)
+ public MutablePropertySources springBootPropertySource() {
+
+ MutablePropertySources sources = env.getPropertySources();
+ sources.addFirst(new PropertiesPropertySource("boot-test-property", CamelCloudServiceCallRefExpressionTest.getAllProperties()));
+ return sources;
+
+ }
+ }
+
+ private static Properties getAllProperties() {
+
+ Properties prop = new Properties();
+ prop.put("service.name", "custom-svc-list");
+ prop.put("camel.cloud.service-call.expression", "myExpression");
+ prop.put("camel.cloud.load-balancer.enabled", false);
+ prop.put("camel.cloud.service-call.component", "jetty");
+ prop.put("camel.cloud.service-discovery.services[custom-svc-list]", SpringBootPropertyUtil.getDiscoveryServices());
+ prop.put("camel.cloud.service-filter.blacklist[custom-svc-list]", SpringBootPropertyUtil.getServiceFilterBlacklist());
+ prop.put("ribbon.enabled", false);
+ prop.put("debug", false);
+ return prop;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallSimpleExpressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallSimpleExpressionTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallSimpleExpressionTest.java
new file mode 100644
index 0000000..8e76419
--- /dev/null
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallSimpleExpressionTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.cloud;
+
+import java.util.Properties;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ CamelCloudServiceCallSimpleExpressionTest.TestConfiguration.class,
+ CamelCloudServiceCallSimpleExpressionTest.SpringBootPropertySourceConfig.class
+ }
+)
+public class CamelCloudServiceCallSimpleExpressionTest {
+ @Autowired
+ private ProducerTemplate template;
+
+ @Test
+ public void testServiceCall() throws Exception {
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT1), template.requestBody("direct:start", null, String.class));
+ Assert.assertEquals(String.valueOf(SpringBootPropertyUtil.PORT3), template.requestBody("direct:start", null, String.class));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+ @Bean
+ public RouteBuilder myRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .serviceCall("{{service.name}}");
+
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT1)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT1);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT2)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT2);
+ fromF("jetty:http://localhost:%d/hello", SpringBootPropertyUtil.PORT3)
+ .transform()
+ .constant(SpringBootPropertyUtil.PORT3);
+ }
+ };
+ }
+ }
+
+ private static Properties getAllProperties() {
+
+ Properties prop = new Properties();
+ prop.put("service.name", "custom-svc-list");
+ prop.put("camel.cloud.load-balancer.enabled", false);
+ prop.put("camel.cloud.service-call.component", "jetty");
+ prop.put("camel.cloud.service-call.expression", "${header.CamelServiceCallScheme}:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/hello");
+ prop.put("camel.cloud.service-call.expression-language", "simple");
+ prop.put("camel.cloud.service-discovery.services[custom-svc-list]", SpringBootPropertyUtil.getDiscoveryServices());
+ prop.put("camel.cloud.service-filter.blacklist[custom-svc-list]", SpringBootPropertyUtil.getServiceFilterBlacklist());
+ prop.put("ribbon.enabled", false);
+ prop.put("debug", false);
+ return prop;
+ }
+
+
+
+ // *************************************
+ // Config
+ //
+
+ @Configuration
+ public static class SpringBootPropertySourceConfig {
+
+ @Autowired
+ private ConfigurableEnvironment env;
+
+ @Bean
+ @Lazy(false)
+ public MutablePropertySources springBootPropertySource() {
+
+ MutablePropertySources sources = env.getPropertySources();
+ sources.addFirst(new PropertiesPropertySource("boot-test-property", CamelCloudServiceCallSimpleExpressionTest.getAllProperties()));
+ return sources;
+
+ }
+ }
+}
+