Fix ordering of property sources

When the bootstrap properties are added back into the main Environment
we have to be careful that any source that is already there (such as
one that was added in a Spring Boot EnvironmentPostProcessor) is not
replaced in the wrong order.

Fixes gh-90
This commit is contained in:
Dave Syer
2016-02-15 10:25:19 +00:00
parent 8628949a8d
commit 624be9d19e
2 changed files with 53 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
package org.springframework.cloud.bootstrap;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJsonIntegrationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@IntegrationTest("spring.cloud.bootstrap.name:json")
public class BootstrapOrderingSpringApplicationJsonIntegrationTests {
@BeforeClass
public static void spikeJson() {
System.setProperty("SPRING_APPLICATION_JSON", "{\"message\":\"From JSON\"}");
}
@AfterClass
public static void unspikeJson() {
System.clearProperty("SPRING_APPLICATION_JSON");
}
@Autowired
private ConfigurableEnvironment environment;
@Test
public void bootstrapPropertiesExist() {
assertTrue(this.environment.getPropertySources()
.contains("spring.application.json"));
assertEquals("From JSON", this.environment.getProperty("message"));
}
@EnableAutoConfiguration
@Configuration
protected static class Application {
}
}