From 2d63d598db17cdf0c975a2ae71b70fa8558940e7 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 10 Feb 2015 11:01:26 +0000 Subject: [PATCH] Add test for spring.cloud.config.server.bootstrap Setting this flag to "true" makes the config server load its own configuration from the git repository (hence both have to be confifgured in bootstrap.yml) --- ...BootstrapConfigServerIntegrationTests.java | 53 +++++++++++++++++++ .../src/test/resources/enable-bootstrap.yml | 7 +++ 2 files changed, 60 insertions(+) create mode 100644 spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java create mode 100644 spring-cloud-config-server/src/test/resources/enable-bootstrap.yml 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 new file mode 100644 index 00000000..60fb5159 --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java @@ -0,0 +1,53 @@ +package org.springframework.cloud.config.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.cloud.config.Environment; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = ConfigServerApplication.class) +@IntegrationTest({ "debug", "server.port:0", + "spring.cloud.bootstrap.name:enable-bootstrap" }) +@WebAppConfiguration +@ActiveProfiles("test") +public class BootstrapConfigServerIntegrationTests { + + @Value("${local.server.port}") + private int port; + + @Value("${info.foo}") + private String foo; + + @BeforeClass + public static void init() throws IOException { + ConfigServerTestUtils.prepareLocalRepo(); + } + + @Test + public void contextLoads() { + Environment environment = new TestRestTemplate().getForObject("http://localhost:" + + port + "/foo/development/", Environment.class); + assertFalse(environment.getPropertySources().isEmpty()); + assertEquals("bar", environment.getPropertySources().get(0) + .getSource().get("info.foo")); + } + + @Test + public void environmentBootstraps() throws Exception { + assertEquals("bar", foo); + } + +} diff --git a/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml b/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml new file mode 100644 index 00000000..c780b861 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml @@ -0,0 +1,7 @@ +spring: + cloud: + config: + server: + git: + uri: file:./target/repos/config-repo + bootstrap: true \ No newline at end of file