From 54bd12c7c229ee5bca95ee1afaae036396af704e Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 3 Jul 2019 11:17:27 -0400 Subject: [PATCH] Separate and fix tests in SidecarApplicationTests (#3585) * Separate and fix tests in SidecarApplicationTests. Fixes #3584 * Renaming classes so they end in Tests --- .../AcceptAllSslCertificatesContextTests.java | 102 ++++++++++ ...thPropertiesEurekaTestConfigBeanTests.java | 51 +++++ .../sidecar/EurekaTestConfigBeanTests.java | 51 +++++ ...textPathStatusAndHealthCheckUrlsTests.java | 52 +++++ .../NewPropertyEurekaTestConfigBeanTests.java | 51 +++++ .../netflix/sidecar/PreferIpAddressTests.java | 52 +++++ .../netflix/sidecar/SecurePortEnableds.java | 47 +++++ ...textPathStatusAndHealthCheckUrlsTests.java | 52 +++++ .../sidecar/SidecarApplicationTests.java | 185 ------------------ 9 files changed, 458 insertions(+), 185 deletions(-) create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/AcceptAllSslCertificatesContextTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/BothPropertiesEurekaTestConfigBeanTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/EurekaTestConfigBeanTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ManagementContextPathStatusAndHealthCheckUrlsTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/NewPropertyEurekaTestConfigBeanTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/PreferIpAddressTests.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SecurePortEnableds.java create mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ServerContextPathStatusAndHealthCheckUrlsTests.java delete mode 100644 spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/AcceptAllSslCertificatesContextTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/AcceptAllSslCertificatesContextTests.java new file mode 100644 index 000000000..c77382bff --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/AcceptAllSslCertificatesContextTests.java @@ -0,0 +1,102 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +import java.lang.reflect.Field; +import java.util.Map; + +import javax.net.ssl.HostnameVerifier; + +import org.apache.http.config.Registry; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.conn.DefaultHttpClientConnectionOperator; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +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.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { + "sidecar.accept-all-ssl-certificates=false" }) +public class AcceptAllSslCertificatesContextTests { + + @Autowired + RestTemplate restTemplate; + + @Test + public void testUseRestTemplateWhenHttpClientIsNotAvailable() { + HttpComponentsClientHttpRequestFactory requestFactory = (HttpComponentsClientHttpRequestFactory) restTemplate + .getRequestFactory(); + CloseableHttpClient client = (CloseableHttpClient) requestFactory.getHttpClient(); + PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = getHttpClientConnectionManager( + client); + DefaultHttpClientConnectionOperator httpClientConnectionOperator = getHttpClientConnectionOperator( + poolingHttpClientConnectionManager); + Registry registry = getRegistry(httpClientConnectionOperator); + Map registryMap = getRegistryMap(registry); + SSLConnectionSocketFactory connectionSocketFactory = (SSLConnectionSocketFactory) registryMap + .get("https"); + HostnameVerifier hostnameVerifier = getHostnameVerifier(connectionSocketFactory); + assertThat(hostnameVerifier).isInstanceOf(DefaultHostnameVerifier.class); + } + + private HostnameVerifier getHostnameVerifier( + SSLConnectionSocketFactory connectionSocketFactory) { + return getField(connectionSocketFactory, "hostnameVerifier"); + } + + private PoolingHttpClientConnectionManager getHttpClientConnectionManager( + CloseableHttpClient httpClient) { + return getField(httpClient, "connManager"); + } + + private DefaultHttpClientConnectionOperator getHttpClientConnectionOperator( + PoolingHttpClientConnectionManager connectionManager) { + return getField(connectionManager, "connectionOperator"); + } + + private Registry getRegistry( + DefaultHttpClientConnectionOperator httpClientConnectionOperator) { + return getField(httpClientConnectionOperator, "socketFactoryRegistry"); + } + + private Map getRegistryMap(Registry registry) { + return getField(registry, "map"); + } + + private T getField(Object target, String name) { + Field field = ReflectionUtils.findField(target.getClass(), name); + ReflectionUtils.makeAccessible(field); + Object value = ReflectionUtils.getField(field, target); + return (T) value; + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/BothPropertiesEurekaTestConfigBeanTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/BothPropertiesEurekaTestConfigBeanTests.java new file mode 100644 index 000000000..6b6b1d3a5 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/BothPropertiesEurekaTestConfigBeanTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", + "sidecar.hostname=mhhost2", "sidecar.port=7000", "sidecar.ip-address=127.0.0.1" }) +public class BothPropertiesEurekaTestConfigBeanTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testEurekaConfigBeanEurekaInstanceHostnamePropertyShouldBeUsed() { + assertThat(config.getAppname()).isEqualTo("mytest"); + assertThat(config.getHostname()).isEqualTo("mhhost1"); + assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); + assertThat(config.getNonSecurePort()).isEqualTo(7000); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/EurekaTestConfigBeanTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/EurekaTestConfigBeanTests.java new file mode 100644 index 000000000..29ad702d3 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/EurekaTestConfigBeanTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "eureka.instance.hostname=mhhost", + "sidecar.port=7000", "sidecar.ip-address=127.0.0.1" }) +public class EurekaTestConfigBeanTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testEurekaConfigBean() { + assertThat(this.config.getAppname()).isEqualTo("mytest"); + assertThat(this.config.getHostname()).isEqualTo("mhhost"); + assertThat(this.config.getInstanceId()).isEqualTo("mhhost:mytest:1"); + assertThat(this.config.getNonSecurePort()).isEqualTo(7000); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ManagementContextPathStatusAndHealthCheckUrlsTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ManagementContextPathStatusAndHealthCheckUrlsTests.java new file mode 100644 index 000000000..e57a4afff --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ManagementContextPathStatusAndHealthCheckUrlsTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", + "sidecar.hostname=mhhost2", "sidecar.port=7000", "sidecar.ipAddress=127.0.0.1", + "management.server.servlet.context-path=/foo" }) +public class ManagementContextPathStatusAndHealthCheckUrlsTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testStatusAndHealthCheckUrls() { + assertThat(config.getStatusPageUrl()) + .isEqualTo("http://mhhost2:0/foo/actuator/info"); + assertThat(config.getHealthCheckUrl()) + .isEqualTo("http://mhhost2:0/foo/actuator/health"); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/NewPropertyEurekaTestConfigBeanTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/NewPropertyEurekaTestConfigBeanTests.java new file mode 100644 index 000000000..d17ef64e3 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/NewPropertyEurekaTestConfigBeanTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "sidecar.hostname=mhhost", + "sidecar.port=7000", "sidecar.ip-address=127.0.0.1" }) +public class NewPropertyEurekaTestConfigBeanTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testEurekaConfigBean() { + assertThat(config.getAppname()).isEqualTo("mytest"); + assertThat(config.getHostname()).isEqualTo("mhhost"); + assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); + assertThat(config.getNonSecurePort()).isEqualTo(7000); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/PreferIpAddressTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/PreferIpAddressTests.java new file mode 100644 index 000000000..be3e3e6f0 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/PreferIpAddressTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", + "sidecar.hostname=mhhost2", "sidecar.port=7000", "sidecar.ip-address=10.0.0.1", + "eureka.instance.prefer-ip-address=true" }) +public class PreferIpAddressTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testEurekaConfigBeanPreferIpAddress() { + assertThat(config.getAppname()).isEqualTo("mytest"); + assertThat(config.getHostname()).isEqualTo("10.0.0.1"); + assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); + assertThat(config.getNonSecurePort()).isEqualTo(7000); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SecurePortEnableds.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SecurePortEnableds.java new file mode 100644 index 000000000..cfb877d08 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SecurePortEnableds.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { + "sidecar.port=7000", "sidecar.ip-address=127.0.0.1", + "sidecar.secure-port-enabled=true" }) +public class SecurePortEnableds { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testThatSecureEnabledOptionIsSetFromPropertyFile() { + assertThat(this.config.isSecurePortEnabled()).isEqualTo(true); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ServerContextPathStatusAndHealthCheckUrlsTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ServerContextPathStatusAndHealthCheckUrlsTests.java new file mode 100644 index 000000000..63c2c5f34 --- /dev/null +++ b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/ServerContextPathStatusAndHealthCheckUrlsTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.netflix.sidecar; + +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.cloud.netflix.eureka.EurekaInstanceConfigBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { + "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", + "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", + "sidecar.hostname=mhhost2", "sidecar.port=7000", "sidecar.ipAddress=127.0.0.1", + "server.servlet.context-path=/foo" }) +public class ServerContextPathStatusAndHealthCheckUrlsTests { + + @Autowired + EurekaInstanceConfigBean config; + + @Test + public void testStatusAndHealthCheckUrls() { + assertThat(config.getStatusPageUrl()) + .isEqualTo("http://mhhost2:0/foo/actuator/info"); + assertThat(config.getHealthCheckUrl()) + .isEqualTo("http://mhhost2:0/foo/actuator/health"); + } + +} diff --git a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java b/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java deleted file mode 100644 index c6173a6af..000000000 --- a/spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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.springframework.cloud.netflix.sidecar; - -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.cloud.netflix.eureka.EurekaInstanceConfigBean; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -public class SidecarApplicationTests { - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "eureka.instance.hostname=mhhost", - "sidecar.port=7000", "sidecar.ip-address=127.0.0.1" }) - public static class EurekaTestConfigBeanTest { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testEurekaConfigBean() { - assertThat(this.config.getAppname()).isEqualTo("mytest"); - assertThat(this.config.getHostname()).isEqualTo("mhhost"); - assertThat(this.config.getInstanceId()).isEqualTo("mhhost:mytest:1"); - assertThat(this.config.getNonSecurePort()).isEqualTo(7000); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "sidecar.hostname=mhhost", - "sidecar.port=7000", "sidecar.ip-address=127.0.0.1" }) - public static class NewPropertyEurekaTestConfigBeanTest { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testEurekaConfigBean() { - assertThat(config.getAppname()).isEqualTo("mytest"); - assertThat(config.getHostname()).isEqualTo("mhhost"); - assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); - assertThat(config.getNonSecurePort()).isEqualTo(7000); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", - "sidecar.hostname=mhhost2", "sidecar.port=7000", - "sidecar.ip-address=127.0.0.1" }) - public static class BothPropertiesEurekaTestConfigBeanTest { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testEurekaConfigBeanEurekaInstanceHostnamePropertyShouldBeUsed() { - assertThat(config.getAppname()).isEqualTo("mytest"); - assertThat(config.getHostname()).isEqualTo("mhhost1"); - assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); - assertThat(config.getNonSecurePort()).isEqualTo(7000); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, properties = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", - "sidecar.hostname=mhhost2", "sidecar.port=7000", - "sidecar.ip-address=10.0.0.1", "eureka.instance.prefer-ip-address=true" }) - public static class PreferIpAddressTest { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testEurekaConfigBeanPreferIpAddress() { - assertThat(config.getAppname()).isEqualTo("mytest"); - assertThat(config.getHostname()).isEqualTo("10.0.0.1"); - assertThat(config.getInstanceId()).isEqualTo("mhhost:mytest:1"); - assertThat(config.getNonSecurePort()).isEqualTo(7000); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", - "sidecar.hostname=mhhost2", "sidecar.port=7000", - "sidecar.ipAddress=127.0.0.1", "management.context-path=/foo" }) - public static class ManagementContextPathStatusAndHealthCheckUrls { - - @Autowired - EurekaInstanceConfigBean config; - - public void testStatusAndHealthCheckUrls() { - assertThat(config.getStatusPageUrl()).isEqualTo("http://mhhost2:0/foo/info"); - assertThat(config.getHealthCheckUrl()) - .isEqualTo("http://mhhost2:0/foo/health"); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { - "spring.application.name=mytest", "spring.cloud.client.hostname=mhhost", - "spring.application.instance_id=1", "eureka.instance.hostname=mhhost1", - "sidecar.hostname=mhhost2", "sidecar.port=7000", - "sidecar.ipAddress=127.0.0.1", "server.context-path=/foo" }) - public static class ServerContextPathStatusAndHealthCheckUrls { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testStatusAndHealthCheckUrls() { - assertThat(config.getStatusPageUrl()).isEqualTo("http://mhhost2:0/foo/info"); - assertThat(config.getHealthCheckUrl()) - .isEqualTo("http://mhhost2:0/foo/health"); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { - "sidecar.accept-all-ssl-certificates=false" }) - public static class AcceptAllSslCertificatesContext { - - @Autowired - RestTemplate restTemplate; - - @Test - public void testUseRestTemplateWhenHttpClientIsNotAvailable() { - assertThat(restTemplate.getRequestFactory()).isNull(); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = SidecarApplication.class, webEnvironment = RANDOM_PORT, value = { - "sidecar.port=7000", "sidecar.ip-address=127.0.0.1", - "sidecar.secure-port-enabled=true" }) - public static class SecurePortEnabled { - - @Autowired - EurekaInstanceConfigBean config; - - @Test - public void testThatSecureEnabledOptionIsSetFromPropertyFile() { - assertThat(this.config.isSecurePortEnabled()).isEqualTo(true); - } - - } - -}