From c1bff9c27b0002de9b1b20b4615af751e1e8f4c8 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Wed, 4 May 2022 18:11:34 -0400 Subject: [PATCH] Adds TestConfigServerApplication for use in tests. This avoids a classpath scanning issue which popped up with boot 2.7+ --- .../sample/ApplicationBootstrapTests.java | 2 +- .../test/java/sample/ApplicationTests.java | 2 +- ...igDataCustomMediaTypeIntegrationTests.java | 2 +- .../sample/ConfigDataIntegrationTests.java | 2 +- .../ConfigDataOrderingIntegrationTests.java | 2 +- .../sample/ServerNativeApplicationTests.java | 2 +- .../server/ConfigServerApplication.java | 2 ++ ...BootstrapConfigServerIntegrationTests.java | 3 +- .../server/CompositeClasspathTests.java | 13 ++++---- .../server/CompositeIntegrationTests.java | 5 +-- ...ackwardsCompatibilityIntegrationTests.java | 3 +- .../ConfigClientOffIntegrationTests.java | 3 +- ...CompositeConfigServerIntegrationTests.java | 3 +- .../CredhubConfigServerIntegrationTests.java | 3 +- .../NativeConfigServerIntegrationTests.java | 3 +- ...ubversionConfigServerIntegrationTests.java | 3 +- ...ransportConfigurationIntegrationTests.java | 17 +++++----- .../VanillaConfigServerIntegrationTests.java | 3 +- .../server/composite/CompositUtilsTests.java | 6 ++-- .../EncryptionIntegrationTests.java | 10 +++--- ...vironmentRepositoryConfigurationTests.java | 8 ++--- .../test/TestConfigServerApplication.java | 32 +++++++++++++++++++ 22 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/test/TestConfigServerApplication.java diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java index 0f18678c..470e86a0 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java @@ -72,7 +72,7 @@ public class ApplicationBootstrapTests { String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample"); String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config"); System.setProperty("repo1", repo); - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, // FIXME: configdata why is use legacy needed here and above? "--spring.config.use-legacy-processing=true", "--server.port=" + configPort, "--spring.config.name=compositeserver", "--repo1=" + repo); diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java index 2085e21a..73d1a5b6 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java @@ -61,7 +61,7 @@ public class ApplicationTests { public static void startConfigServer() throws IOException { String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample"); String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config"); - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, "--server.port=" + configPort, "--spring.config.name=server", "--spring.cloud.config.server.git.uri=" + repo); /* diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java index e752f87b..5e2af30d 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java @@ -66,7 +66,7 @@ public class ConfigDataCustomMediaTypeIntegrationTests { public static void startConfigServer() throws IOException { String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample"); String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config"); - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, "--server.port=" + configPort, "--spring.config.name=server", "--spring.cloud.config.server.git.uri=" + repo); diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java index 5e1d4963..aa14fe39 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java @@ -59,7 +59,7 @@ public class ConfigDataIntegrationTests { public static void startConfigServer() throws IOException { String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample"); String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config"); - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, "--server.port=" + configPort, "--spring.config.name=server", "--spring.cloud.config.server.git.uri=" + repo); diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java index 4d861988..9ffaca6f 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java @@ -60,7 +60,7 @@ public class ConfigDataOrderingIntegrationTests { @BeforeClass public static void startConfigServer() { - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, "--spring.profiles.active=native", "--server.port=" + configPort, "--spring.config.name=server"); System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort); diff --git a/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java b/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java index d2f22ac4..fba10370 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java @@ -52,7 +52,7 @@ public class ServerNativeApplicationTests { @BeforeClass public static void startConfigServer() throws IOException { String repo = ConfigServerTestUtils.prepareLocalRepo(); - server = SpringApplication.run(org.springframework.cloud.config.server.ConfigServerApplication.class, + server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class, "--server.port=" + configPort, "--spring.config.name=server", "--spring.cloud.config.server.git.uri=" + repo, "--spring.profiles.active=native"); /* diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java index 7bab622b..f4a73fed 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java @@ -24,10 +24,12 @@ import org.springframework.context.annotation.Configuration; * Configuration server application. * * @author Dave Syer + * @deprecated Will be removed in 4.0.0. */ @Configuration(proxyBeanMethods = false) @EnableAutoConfiguration @EnableConfigServer +@Deprecated public class ConfigServerApplication { public static void main(String[] args) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java index 9cb7d4b1..102d9e7c 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -42,7 +43,7 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity; @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, properties = { "spring.cloud.bootstrap.enabled=true", +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.cloud.bootstrap.enabled=true", "logging.level.org.springframework.boot.context.config=TRACE", "spring.cloud.bootstrap.name:enable-bootstrap", "encrypt.rsa.algorithm=DEFAULT", "encrypt.rsa.strong=false" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java index 6571525b..b30b7ba0 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java @@ -21,6 +21,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.cloud.config.server.composite.CompositeUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.cloud.test.ClassPathExclusions; import org.springframework.cloud.test.ModifiedClassPathRunner; @@ -34,7 +35,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", @@ -54,7 +55,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", @@ -73,7 +74,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", @@ -93,7 +94,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", @@ -113,7 +114,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:///./target/repos/svn-config-repo", @@ -133,7 +134,7 @@ public class CompositeClasspathTests { @Test public void contextLoads() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.jmx.enabled=false", "spring.config.name:configserver", "spring.cloud.config.server.composite[0].uri:https://source.developers.google.com", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java index 8c97232b..f2ec4f89 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java @@ -27,6 +27,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; @@ -43,7 +44,7 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils public class CompositeIntegrationTests { @RunWith(SpringRunner.class) - @SpringBootTest(classes = ConfigServerApplication.class, + @SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:compositeconfigserver", "spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo", "spring.cloud.config.server.svn.order:2", @@ -94,7 +95,7 @@ public class CompositeIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = ConfigServerApplication.class, + @SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", "spring.cloud.config.server.composite[0].type:git", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java index 4cf02a55..171dff1a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -42,7 +43,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity; @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, properties = { "spring.config.name:configserver" }, +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver" }, webEnvironment = RANDOM_PORT) @ActiveProfiles({ "test", "native" }) public class ConfigClientBackwardsCompatibilityIntegrationTests { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java index 1d15f842..adc97ab5 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java @@ -36,6 +36,7 @@ import org.springframework.cloud.config.server.ConfigClientOffIntegrationTests.T import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.resource.ResourceRepository; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -83,7 +84,7 @@ public class ConfigClientOffIntegrationTests { } @Configuration(proxyBeanMethods = false) - @Import(ConfigServerApplication.class) + @Import(TestConfigServerApplication.class) protected static class TestConfiguration { @Bean diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java index ca80fcc0..a14d3599 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java @@ -23,6 +23,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +33,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Alberto C. Ríos */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.profiles.active:composite", "spring.cloud.config.server.composite[0].type:credhub", "spring.cloud.config.server.composite[0].url:https://credhub:8844" }, webEnvironment = RANDOM_PORT) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java index 46ee6eac..9817cf4a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java @@ -23,6 +23,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +33,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Alberto C. Ríos */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, properties = { "spring.profiles.active:credhub", +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.profiles.active:credhub", "spring.cloud.config.server.credhub.url:https://credhub:8844" }, webEnvironment = RANDOM_PORT) public class CredhubConfigServerIntegrationTests extends CredhubIntegrationTest { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java index dfe900b1..86872562 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java @@ -29,6 +29,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,7 +42,7 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.prepareLocalRepo; @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, properties = { "spring.config.name:configserver" }, +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver" }, webEnvironment = RANDOM_PORT) @ActiveProfiles({ "test", "native" }) public class NativeConfigServerIntegrationTests { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java index 228d385a..d6acf60b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java @@ -30,6 +30,7 @@ import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -47,7 +48,7 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils * @author Roy Clarkson */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver", "spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo", "logging.level.org.springframework.cloud=DEBUG" }, diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java index 7088ba99..13bf1711 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java @@ -36,6 +36,7 @@ import org.springframework.cloud.config.server.environment.MultipleJGitEnvironme import org.springframework.cloud.config.server.ssh.FileBasedSshTransportConfigCallback; import org.springframework.cloud.config.server.ssh.PropertiesBasedSshTransportConfigCallback; import org.springframework.cloud.config.server.ssh.SshPropertyValidator; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -53,7 +54,7 @@ public class TransportConfigurationIntegrationTests { public static class PropertyBasedCallbackTest { @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-private-key-block" }) @@ -73,7 +74,7 @@ public class TransportConfigurationIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-private-key-block-list" }) @@ -97,7 +98,7 @@ public class TransportConfigurationIntegrationTests { public static class PrivateKeyPropertyWithLineBreaks { @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-private-key-newline" }) @@ -120,7 +121,7 @@ public class TransportConfigurationIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-private-key-newline-list" }) @@ -147,7 +148,7 @@ public class TransportConfigurationIntegrationTests { public static class SshPropertiesWithinNestedRepo { @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-nested-settings" }) @@ -175,7 +176,7 @@ public class TransportConfigurationIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/", "spring.config.name:ssh-nested-settings-list" }) @@ -207,7 +208,7 @@ public class TransportConfigurationIntegrationTests { public static class FileBasedCallbackTest { @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.cloud.config.server.git.uri=git@gitserver.com:team/repo.git", "spring.cloud.config.server.git.ignoreLocalSshSettings=false" }) @@ -259,7 +260,7 @@ public class TransportConfigurationIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class, SshPropertyValidator.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.cloud.config.server.composite[0].type=git", "spring.cloud.config.server.composite[0].uri=git@gitserver.com:team/repo.git", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java index 2caf5e00..76fcf7a1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java @@ -30,6 +30,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -43,7 +44,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity; @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigServerApplication.class, properties = { "spring.config.name:configserver", +@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver", "spring.cloud.config.server.git.uri:file:./target/repos/config-repo" }, webEnvironment = RANDOM_PORT) @ActiveProfiles("test") public class VanillaConfigServerIntegrationTests { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java index 3460914d..3228239d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; -import org.springframework.cloud.config.server.ConfigServerApplication; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +34,7 @@ public class CompositUtilsTests { @Test public void getCompositeTypeListWorks() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.config.name:compositeconfigserver", "spring.jmx.enabled=false", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", @@ -51,7 +51,7 @@ public class CompositUtilsTests { public void getCompositeTypeListFails() { this.thrown.expect(IllegalStateException.class); - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active:test,composite", "spring.config.name:compositeconfigserver", "spring.jmx.enabled=false", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java index 630f93e6..4912acda 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java @@ -23,8 +23,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.cloud.config.server.ConfigServerApplication; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class EncryptionIntegrationTests { @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "spring.config.use-legacy-processing=true", "encrypt.key=foobar" }) @ActiveProfiles({ "test", "native" }) @@ -58,7 +58,7 @@ public class EncryptionIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class }, properties = { "spring.config.use-legacy-processing=true", "spring.cloud.bootstrap.name:symmetric-key-bootstrap" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -78,7 +78,7 @@ public class EncryptionIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class }, properties = { "spring.config.use-legacy-processing=true", "spring.cloud.bootstrap.name:keystore-bootstrap" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -98,7 +98,7 @@ public class EncryptionIntegrationTests { } @RunWith(SpringRunner.class) - @SpringBootTest(classes = { ConfigServerApplication.class }, + @SpringBootTest(classes = { TestConfigServerApplication.class }, properties = { "spring.config.use-legacy-processing=true", "spring.cloud.bootstrap.name:keystore-bootstrap", "spring.cloud.config.server.encrypt.enabled=false", "encrypt.keyStore.alias=myencryptionkey" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java index dd245143..6bb6e5b1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java @@ -26,8 +26,8 @@ import org.junit.Test; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; -import org.springframework.cloud.config.server.ConfigServerApplication; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; +import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.dao.DataAccessException; import static org.assertj.core.api.Assertions.assertThat; @@ -41,7 +41,7 @@ public class JdbcEnvironmentRepositoryConfigurationTests { @Test public void jdbcEnvironmentRepositoryBeansConfiguredWhenDefault() throws IOException { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active=test,jdbc", "spring.main.web-application-type=none") .run(context -> { assertThat(context).hasSingleBean(JdbcEnvironmentRepositoryFactory.class); @@ -52,7 +52,7 @@ public class JdbcEnvironmentRepositoryConfigurationTests { @Test public void jdbcEnvironmentRepositoryBeansConfiguredWitCustomResultSetExtractor() { - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withBean(CustomResultSetExtractor.class, CustomResultSetExtractor::new) .withPropertyValues("spring.profiles.active=test,jdbc", "spring.main.web-application-type=none") .run(context -> { @@ -85,7 +85,7 @@ public class JdbcEnvironmentRepositoryConfigurationTests { private void getApplicationContextWithJdbcEnabled(boolean jdbcEnabled, ContextConsumer consumer) throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo(); - new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class) + new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class) .withPropertyValues("spring.profiles.active=test,jdbc", "spring.main.web-application-type=none", "spring.cloud.config.server.git.uri:" + uri, "spring.cloud.config.server.jdbc.enabled:" + jdbcEnabled) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/test/TestConfigServerApplication.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/test/TestConfigServerApplication.java new file mode 100644 index 00000000..5049ef47 --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/test/TestConfigServerApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2022 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.config.server.test; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cloud.config.server.EnableConfigServer; + +@EnableConfigServer +@SpringBootApplication +public class TestConfigServerApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder(TestConfigServerApplication.class).properties("spring.config.name=configserver") + .run(args); + } + +}