Backported tests for property source ordering
Issue: SPR-12198
(cherry picked from commit 90b93ff)
This commit is contained in:
parent
29abca5399
commit
205e681295
|
|
@ -142,16 +142,6 @@ public class PropertySourceAnnotationTests {
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SPR-10820
|
|
||||||
@Test
|
|
||||||
public void orderingWithAndWithoutNameAndMultipleResourceLocations() {
|
|
||||||
// p2 should 'win' as it was registered last
|
|
||||||
AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
|
|
||||||
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
|
|
||||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
|
|
||||||
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withNameAndMultipleResourceLocations() {
|
public void withNameAndMultipleResourceLocations() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
|
||||||
|
|
@ -202,6 +192,30 @@ public class PropertySourceAnnotationTests {
|
||||||
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
|
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withSameSourceImportedInDifferentOrder() {
|
||||||
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithSameSourceImportedInDifferentOrder.class);
|
||||||
|
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
|
||||||
|
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
|
||||||
|
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void orderingWithAndWithoutNameAndMultipleResourceLocations() {
|
||||||
|
// SPR-10820: p2 should 'win' as it was registered last
|
||||||
|
AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
|
||||||
|
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
|
||||||
|
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
|
||||||
|
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void orderingWithAndWithoutNameAndFourResourceLocations() {
|
||||||
|
// SPR-12198: p4 should 'win' as it was registered last
|
||||||
|
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithFourResourceLocations.class);
|
||||||
|
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p4TestBean"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource(value="classpath:${unresolvable}/p1.properties")
|
@PropertySource(value="classpath:${unresolvable}/p1.properties")
|
||||||
|
|
@ -326,8 +340,8 @@ public class PropertySourceAnnotationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p1.properties"),
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p1.properties"),
|
||||||
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties"),
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties"),
|
||||||
})
|
})
|
||||||
static class ConfigWithNamedPropertySources {
|
static class ConfigWithNamedPropertySources {
|
||||||
}
|
}
|
||||||
|
|
@ -359,4 +373,36 @@ public class PropertySourceAnnotationTests {
|
||||||
static class ConfigWithEmptyResourceLocations {
|
static class ConfigWithEmptyResourceLocations {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Import(ConfigImportedWithSameSourceImportedInDifferentOrder.class)
|
||||||
|
@PropertySources({
|
||||||
|
@PropertySource("classpath:org/springframework/context/annotation/p1.properties"),
|
||||||
|
@PropertySource("classpath:org/springframework/context/annotation/p2.properties")
|
||||||
|
})
|
||||||
|
@Configuration
|
||||||
|
public static class ConfigWithSameSourceImportedInDifferentOrder {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySources({
|
||||||
|
@PropertySource("classpath:org/springframework/context/annotation/p2.properties"),
|
||||||
|
@PropertySource("classpath:org/springframework/context/annotation/p1.properties")
|
||||||
|
})
|
||||||
|
public static class ConfigImportedWithSameSourceImportedInDifferentOrder {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource(
|
||||||
|
value = {
|
||||||
|
"classpath:org/springframework/context/annotation/p1.properties",
|
||||||
|
"classpath:org/springframework/context/annotation/p2.properties",
|
||||||
|
"classpath:org/springframework/context/annotation/p3.properties",
|
||||||
|
"classpath:org/springframework/context/annotation/p4.properties"
|
||||||
|
})
|
||||||
|
static class ConfigWithFourResourceLocations {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
testbean.name=p3TestBean
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
testbean.name=p4TestBean
|
||||||
Loading…
Reference in New Issue