You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2018/06/27 13:46:28 UTC
[camel] branch master updated: CAMEL-12494: spring-boot: use
ApplicationContextRunner in spring-boot test to test AutoConfigurations
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 13ee4d6 CAMEL-12494: spring-boot: use ApplicationContextRunner in spring-boot test to test AutoConfigurations
13ee4d6 is described below
commit 13ee4d64c79e854ac7036d7113ce002c208aa345
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Jun 27 15:45:08 2018 +0200
CAMEL-12494: spring-boot: use ApplicationContextRunner in spring-boot test to test AutoConfigurations
---
.../cloud/ConsulServiceDiscoveryDisabledTest.java | 64 -------------
.../cloud/ConsulServiceDiscoveryEnabledTest.java | 65 -------------
.../cloud/DnsServiceDiscoveryDisabledTest.java | 64 -------------
.../cloud/DnsServiceDiscoveryEnabledTest.java | 65 -------------
.../springboot/cloud/DnsServiceDiscoveryTest.java | 63 ++++++++++++
.../cloud/EtcdServiceDiscoveryDisabledTest.java | 64 -------------
.../cloud/EtcdServiceDiscoveryEnabledTest.java | 65 -------------
.../springboot/cloud/EtcdServiceDiscoveryTest.java | 63 ++++++++++++
...lusterServiceAutoConfigurationDisabledTest.java | 47 ---------
...ernetesClusterServiceAutoConfigurationTest.java | 106 ++++++++++++---------
.../RibbonLoadBalancerAutoConfigurationTest.java | 63 ++++++++++++
.../cloud/RibbonLoadBalancerDisabledTest.java | 64 -------------
.../cloud/RibbonLoadBalancerEnabledTest.java | 65 -------------
.../springboot/cloud/RibbonLoadBalancerTest.java | 77 ++++++++-------
14 files changed, 289 insertions(+), 646 deletions(-)
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
deleted file mode 100644
index 01cc252..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
+++ /dev/null
@@ -1,64 +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.component.consul.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.consul.service-discovery.enabled=false"
-})
-public class ConsulServiceDiscoveryDisabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertTrue(beans.isEmpty());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertFalse(beans.containsKey("consul-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
deleted file mode 100644
index cedfde5..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
+++ /dev/null
@@ -1,65 +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.component.consul.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.consul.service-discovery.enabled=true"
-})
-public class ConsulServiceDiscoveryEnabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertEquals(1, beans.size());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertTrue(beans.containsKey("consul-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java
deleted file mode 100644
index cc967c0..0000000
--- a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java
+++ /dev/null
@@ -1,64 +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.component.dns.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- DnsServiceDiscoveryEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.dns.service-discovery.enabled=false"
-})
-public class DnsServiceDiscoveryDisabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertTrue(beans.isEmpty());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertFalse(beans.containsKey("dns-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java
deleted file mode 100644
index bc1bcc7..0000000
--- a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java
+++ /dev/null
@@ -1,65 +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.component.dns.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- DnsServiceDiscoveryEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.dns.service-discovery.enabled=true"
-})
-public class DnsServiceDiscoveryEnabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertEquals(1, beans.size());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertTrue(beans.containsKey("dns-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryTest.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryTest.java
new file mode 100644
index 0000000..75ec4ca
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.component.dns.springboot.cloud;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DnsServiceDiscoveryTest {
+ @Test
+ public void testServiceDiscoveryDisabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.dns.service-discovery.enabled=false")
+ .run(
+ context -> {
+ assertThat(context).doesNotHaveBean(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceDiscovery.class).doesNotContainKeys("dns-service-discovery");
+ }
+ );
+ }
+
+ @Test
+ public void testServiceDiscoveryEnabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.dns.service-discovery.enabled=true")
+ .run(
+ context -> {
+ assertThat(context).hasSingleBean(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("dns-service-discovery");
+ }
+ );
+ }
+
+ @EnableAutoConfiguration
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
deleted file mode 100644
index 3d3548a..0000000
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
+++ /dev/null
@@ -1,64 +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.component.etcd.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- EtcdServiceDiscoveryDisabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.etcd.service-discovery.enabled=false"
-})
-public class EtcdServiceDiscoveryDisabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertTrue(beans.isEmpty());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertFalse(beans.containsKey("etcd-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
deleted file mode 100644
index f678282..0000000
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
+++ /dev/null
@@ -1,65 +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.component.etcd.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- EtcdServiceDiscoveryEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.etcd.service-discovery.enabled=true"
-})
-public class EtcdServiceDiscoveryEnabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertEquals(1, beans.size());
-
- beans = context.getBeansOfType(ServiceDiscovery.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertTrue(beans.containsKey("etcd-service-discovery"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryTest.java b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryTest.java
new file mode 100644
index 0000000..0f8579c
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.component.etcd.springboot.cloud;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EtcdServiceDiscoveryTest {
+ @Test
+ public void testServiceDiscoveryDisabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.etcd.service-discovery.enabled=false")
+ .run(
+ context -> {
+ assertThat(context).doesNotHaveBean(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceDiscovery.class).doesNotContainKeys("etcd-service-discovery");
+ }
+ );
+ }
+
+ @Test
+ public void testServiceDiscoveryEnabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.etcd.service-discovery.enabled=true")
+ .run(
+ context -> {
+ assertThat(context).hasSingleBean(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("etcd-service-discovery");
+ }
+ );
+ }
+
+ @EnableAutoConfiguration
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationDisabledTest.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationDisabledTest.java
deleted file mode 100644
index a917b88..0000000
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationDisabledTest.java
+++ /dev/null
@@ -1,47 +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.component.kubernetes.springboot.test.cluster;
-
-import org.apache.camel.component.kubernetes.cluster.KubernetesClusterService;
-import org.apache.camel.component.kubernetes.springboot.cluster.KubernetesClusterServiceAutoConfiguration;
-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.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import static org.junit.Assert.assertNull;
-
-/**
- * Testing that the service is not enabled by default.
- */
-@RunWith(SpringRunner.class)
-@SpringBootApplication
-@ContextConfiguration(classes = KubernetesClusterServiceAutoConfiguration.class)
-public class KubernetesClusterServiceAutoConfigurationDisabledTest {
-
- @Autowired(required = false)
- private KubernetesClusterService clusterService;
-
- @Test
- public void testPropertiesMapped() {
- assertNull(clusterService);
- }
-
-}
-
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationTest.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationTest.java
index b6f8485..18706a7 100644
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationTest.java
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cluster/KubernetesClusterServiceAutoConfigurationTest.java
@@ -19,66 +19,78 @@ package org.apache.camel.component.kubernetes.springboot.test.cluster;
import org.apache.camel.component.kubernetes.cluster.KubernetesClusterService;
import org.apache.camel.component.kubernetes.springboot.cluster.KubernetesClusterServiceAutoConfiguration;
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.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-/**
- * Testing that the service can be enabled and configured completely.
- */
-@RunWith(SpringRunner.class)
-@SpringBootApplication
-@DirtiesContext
-@ContextConfiguration(classes = KubernetesClusterServiceAutoConfiguration.class)
-@SpringBootTest(properties = {
- "spring.main.banner-mode=off",
- "camel.component.kubernetes.cluster.service.enabled=true",
- "camel.component.kubernetes.cluster.service.id=myid1",
- "camel.component.kubernetes.cluster.service.master-url=http://myurl:9000",
- "camel.component.kubernetes.cluster.service.connection-timeout-millis=1234",
- "camel.component.kubernetes.cluster.service.kubernetes-namespace=ns1",
- "camel.component.kubernetes.cluster.service.config-map-name=cm",
- "camel.component.kubernetes.cluster.service.pod-name=mypod1",
- "camel.component.kubernetes.cluster.service.cluster-labels.app=myapp",
- "camel.component.kubernetes.cluster.service.cluster-labels.provider=myprovider",
- "camel.component.kubernetes.cluster.service.lease-duration-millis=10000",
- "camel.component.kubernetes.cluster.service.renew-deadline-millis=8000",
- "camel.component.kubernetes.cluster.service.retry-period-millis=4000",
-})
public class KubernetesClusterServiceAutoConfigurationTest {
- @Autowired
- private KubernetesClusterService clusterService;
+ @Test
+ public void testDisable() {
+ new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(KubernetesClusterServiceAutoConfiguration.class))
+ .withUserConfiguration(TestConfiguration.class)
+ .run(
+ context -> {
+ assertThat(context).doesNotHaveBean(KubernetesClusterService.class);
+ }
+ );
+ }
+ /**
+ * Testing that the service can be enabled and configured completely.
+ */
@Test
public void testPropertiesMapped() {
- assertEquals("myid1", clusterService.getId());
- assertEquals("http://myurl:9000", clusterService.getMasterUrl());
- assertEquals(Integer.valueOf(1234), clusterService.getConnectionTimeoutMillis());
- assertEquals("ns1", clusterService.getKubernetesNamespace());
- assertEquals("cm", clusterService.getConfigMapName());
- assertEquals("mypod1", clusterService.getPodName());
-
- assertNotNull(clusterService.getClusterLabels());
- assertEquals(2, clusterService.getClusterLabels().size());
- assertEquals("myapp", clusterService.getClusterLabels().get("app"));
- assertEquals("myprovider", clusterService.getClusterLabels().get("provider"));
-
- assertEquals(1.2, clusterService.getJitterFactor(), 1e-10);
- assertEquals(10000, clusterService.getLeaseDurationMillis());
- assertEquals(8000, clusterService.getRenewDeadlineMillis());
- assertEquals(4000, clusterService.getRetryPeriodMillis());
+ new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(KubernetesClusterServiceAutoConfiguration.class))
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.component.kubernetes.cluster.service.enabled=true",
+ "camel.component.kubernetes.cluster.service.id=myid1",
+ "camel.component.kubernetes.cluster.service.master-url=http://myurl:9000",
+ "camel.component.kubernetes.cluster.service.connection-timeout-millis=1234",
+ "camel.component.kubernetes.cluster.service.kubernetes-namespace=ns1",
+ "camel.component.kubernetes.cluster.service.config-map-name=cm",
+ "camel.component.kubernetes.cluster.service.pod-name=mypod1",
+ "camel.component.kubernetes.cluster.service.cluster-labels.app=myapp",
+ "camel.component.kubernetes.cluster.service.cluster-labels.provider=myprovider",
+ "camel.component.kubernetes.cluster.service.lease-duration-millis=10000",
+ "camel.component.kubernetes.cluster.service.renew-deadline-millis=8000",
+ "camel.component.kubernetes.cluster.service.retry-period-millis=4000")
+ .run(
+ context -> {
+ final KubernetesClusterService clusterService = context.getBean(KubernetesClusterService.class);
+ assertEquals("myid1", clusterService.getId());
+ assertEquals("http://myurl:9000", clusterService.getMasterUrl());
+ assertEquals(Integer.valueOf(1234), clusterService.getConnectionTimeoutMillis());
+ assertEquals("ns1", clusterService.getKubernetesNamespace());
+ assertEquals("cm", clusterService.getConfigMapName());
+ assertEquals("mypod1", clusterService.getPodName());
+ assertNotNull(clusterService.getClusterLabels());
+ assertEquals(2, clusterService.getClusterLabels().size());
+ assertEquals("myapp", clusterService.getClusterLabels().get("app"));
+ assertEquals("myprovider", clusterService.getClusterLabels().get("provider"));
+ assertEquals(1.2, clusterService.getJitterFactor(), 1e-10);
+ assertEquals(10000, clusterService.getLeaseDurationMillis());
+ assertEquals(8000, clusterService.getRenewDeadlineMillis());
+ assertEquals(4000, clusterService.getRetryPeriodMillis());
+ }
+ );
}
+ @EnableAutoConfiguration
+ @Configuration
+ public static class TestConfiguration {
+ }
}
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerAutoConfigurationTest.java b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerAutoConfigurationTest.java
new file mode 100644
index 0000000..12fe87a
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerAutoConfigurationTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.component.ribbon.springboot.cloud;
+
+import org.apache.camel.cloud.ServiceLoadBalancer;
+import org.apache.camel.model.cloud.springboot.RibbonServiceCallServiceLoadBalancerConfigurationProperties;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RibbonLoadBalancerAutoConfigurationTest {
+ @Test
+ public void testRibbonLoadBalancerDisabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.ribbon.load-balancer.enabled=false")
+ .run(
+ context -> {
+ assertThat(context).doesNotHaveBean(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceLoadBalancer.class).doesNotContainKeys("ribbon-load-balancer");
+ }
+ );
+ }
+
+ @Test
+ public void testRibbonLoadBalancerEnabled() {
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.ribbon.load-balancer.enabled=true")
+ .run(
+ context -> {
+ assertThat(context).hasSingleBean(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
+ assertThat(context).getBeans(ServiceLoadBalancer.class).containsKeys("ribbon-load-balancer");
+ }
+ );
+ }
+
+ @EnableAutoConfiguration
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerDisabledTest.java b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerDisabledTest.java
deleted file mode 100644
index 082a8aa..0000000
--- a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerDisabledTest.java
+++ /dev/null
@@ -1,64 +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.component.ribbon.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceLoadBalancer;
-import org.apache.camel.model.cloud.springboot.RibbonServiceCallServiceLoadBalancerConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- RibbonLoadBalancerDisabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.ribbon.load-balancer.enabled=false"
-})
-public class RibbonLoadBalancerDisabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
- Assert.assertTrue(beans.isEmpty());
-
- beans = context.getBeansOfType(ServiceLoadBalancer.class);
- Assert.assertTrue(beans.isEmpty());
- Assert.assertFalse(beans.containsKey("ribbon-load-balancer"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerEnabledTest.java b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerEnabledTest.java
deleted file mode 100644
index 9a25722..0000000
--- a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerEnabledTest.java
+++ /dev/null
@@ -1,65 +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.component.ribbon.springboot.cloud;
-
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceLoadBalancer;
-import org.apache.camel.model.cloud.springboot.RibbonServiceCallServiceLoadBalancerConfigurationProperties;
-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.ApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- RibbonLoadBalancerEnabledTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.ribbon.load-balancer.enabled=true"
-})
-public class RibbonLoadBalancerEnabledTest {
- @Autowired
- ApplicationContext context;
-
- @Test
- public void testConfiguration() throws Exception {
- Map<String, ?> beans;
-
- beans = context.getBeansOfType(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertEquals(1, beans.size());
-
- beans = context.getBeansOfType(ServiceLoadBalancer.class);
- Assert.assertFalse(beans.isEmpty());
- Assert.assertTrue(beans.containsKey("ribbon-load-balancer"));
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerTest.java b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerTest.java
index c021b00..ccb719a 100644
--- a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerTest.java
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/test/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonLoadBalancerTest.java
@@ -29,50 +29,51 @@ import org.apache.camel.component.ribbon.cloud.RibbonServiceLoadBalancer;
import org.apache.camel.impl.cloud.DefaultServiceCallProcessor;
import org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscovery;
import org.apache.camel.spring.boot.cloud.CamelCloudServiceFilter;
+import org.apache.camel.test.AvailablePortFinder;
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.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
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;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- RibbonLoadBalancerTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.cloud.service-discovery.services[myService]=localhost:9090,localhost:9091",
- "camel.cloud.ribbon.load-balancer.enabled=true"
-})
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
public class RibbonLoadBalancerTest {
- @Autowired
- private CamelContext context;
- @Autowired
- private ProducerTemplate template;
+ private static final int PORT1 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT2 = AvailablePortFinder.getNextAvailable();
@Test
public void testLoadBalancer() throws Exception {
- DefaultServiceCallProcessor processor = findServiceCallProcessor();
+ new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues(
+ "spring.main.banner-mode=off",
+ "camel.cloud.consul.service-discovery.enabled=false",
+ "debug=false",
+ "camel.cloud.service-discovery.services[myService]=localhost:" + PORT1 + ",localhost:" + PORT2,
+ "camel.cloud.ribbon.load-balancer.enabled=true")
+ .run(
+ context -> {
+ final CamelContext camelContext = context.getBean(CamelContext.class);
+ final ProducerTemplate template = camelContext.createProducerTemplate();
- Assert.assertNotNull(processor.getLoadBalancer());
- Assert.assertTrue(processor.getLoadBalancer() instanceof RibbonServiceLoadBalancer);
+ DefaultServiceCallProcessor processor = findServiceCallProcessor(camelContext);
+ assertThat(processor.getLoadBalancer()).isNotNull();
+ assertThat(processor.getLoadBalancer()).isInstanceOf(RibbonServiceLoadBalancer.class);
- RibbonServiceLoadBalancer loadBalancer = (RibbonServiceLoadBalancer)processor.getLoadBalancer();
- Assert.assertTrue(loadBalancer.getServiceDiscovery() instanceof CamelCloudServiceDiscovery);
- Assert.assertTrue(loadBalancer.getServiceFilter() instanceof CamelCloudServiceFilter);
+ RibbonServiceLoadBalancer loadBalancer = (RibbonServiceLoadBalancer)processor.getLoadBalancer();
+ assertThat(loadBalancer.getServiceDiscovery()).isInstanceOf(CamelCloudServiceDiscovery.class);
+ assertThat(loadBalancer.getServiceFilter()).isInstanceOf(CamelCloudServiceFilter.class);
- Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class));
- Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class));
+ assertThat(template.requestBody("direct:start", null, String.class)).isEqualTo("" + PORT2);
+ assertThat(template.requestBody("direct:start", null, String.class)).isEqualTo("" + PORT1);
+ }
+ );
}
+ @EnableAutoConfiguration
@Configuration
public static class TestConfiguration {
@Bean
@@ -86,10 +87,14 @@ public class RibbonLoadBalancerTest {
.name("myService")
.uri("jetty:http://myService")
.end();
- from("jetty:http://localhost:9090").routeId("9090")
- .transform().constant("9090");
- from("jetty:http://localhost:9091").routeId("9091")
- .transform().constant("9091");
+ fromF("jetty:http://localhost:%d", PORT1)
+ .routeId("" + PORT1)
+ .transform()
+ .constant("" + PORT1);
+ fromF("jetty:http://localhost:%d", PORT2)
+ .routeId("" + PORT2)
+ .transform()
+ .constant("" + PORT2);
}
};
}
@@ -99,7 +104,7 @@ public class RibbonLoadBalancerTest {
// Helpers
// ************************************
- protected DefaultServiceCallProcessor findServiceCallProcessor() {
+ protected DefaultServiceCallProcessor findServiceCallProcessor(CamelContext context) {
Route route = context.getRoute("scall");
Assert.assertNotNull("ServiceCall Route should be present", route);