Polish
This commit is contained in:
parent
124574e345
commit
9432ee6a6b
|
@ -19,7 +19,10 @@ package org.springframework.boot.autoconfigure.web;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties used to configure resource handling0
|
* Properties used to configure resource handling.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
|
@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
|
||||||
public class ResourceProperties {
|
public class ResourceProperties {
|
||||||
|
|
|
@ -63,8 +63,15 @@ import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.junit.Assert.*;
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConfigFileApplicationListener}.
|
* Tests for {@link ConfigFileApplicationListener}.
|
||||||
|
@ -362,7 +369,8 @@ public class ConfigFileApplicationListenerTests {
|
||||||
"spring.profiles.active:other");
|
"spring.profiles.active:other");
|
||||||
this.environment.addActiveProfile("dev");
|
this.environment.addActiveProfile("dev");
|
||||||
this.initializer.onApplicationEvent(this.event);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
assertThat(Arrays.asList(this.environment.getActiveProfiles()), containsInAnyOrder("dev", "other"));
|
assertThat(Arrays.asList(this.environment.getActiveProfiles()),
|
||||||
|
containsInAnyOrder("dev", "other"));
|
||||||
assertThat(this.environment.getProperty("my.property"),
|
assertThat(this.environment.getProperty("my.property"),
|
||||||
equalTo("fromotherpropertiesfile"));
|
equalTo("fromotherpropertiesfile"));
|
||||||
validateProfilePrecedence(null, "dev", "other");
|
validateProfilePrecedence(null, "dev", "other");
|
||||||
|
@ -374,39 +382,48 @@ public class ConfigFileApplicationListenerTests {
|
||||||
"spring.profiles.active:dev,other");
|
"spring.profiles.active:dev,other");
|
||||||
this.environment.addActiveProfile("dev");
|
this.environment.addActiveProfile("dev");
|
||||||
this.initializer.onApplicationEvent(this.event);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
assertThat(Arrays.asList(this.environment.getActiveProfiles()), containsInAnyOrder("dev", "other"));
|
assertThat(Arrays.asList(this.environment.getActiveProfiles()),
|
||||||
|
containsInAnyOrder("dev", "other"));
|
||||||
assertThat(this.environment.getProperty("my.property"),
|
assertThat(this.environment.getProperty("my.property"),
|
||||||
equalTo("fromotherpropertiesfile"));
|
equalTo("fromotherpropertiesfile"));
|
||||||
validateProfilePrecedence(null, "dev", "other");
|
validateProfilePrecedence(null, "dev", "other");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins() throws Exception {
|
public void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins()
|
||||||
|
throws Exception {
|
||||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||||
"spring.profiles.active:other,dev");
|
"spring.profiles.active:other,dev");
|
||||||
this.environment.addActiveProfile("other");
|
this.environment.addActiveProfile("other");
|
||||||
this.initializer.onApplicationEvent(this.event);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
assertThat(Arrays.asList(this.environment.getActiveProfiles()), containsInAnyOrder("dev", "other"));
|
assertThat(Arrays.asList(this.environment.getActiveProfiles()),
|
||||||
|
containsInAnyOrder("dev", "other"));
|
||||||
assertThat(this.environment.getProperty("my.property"),
|
assertThat(this.environment.getProperty("my.property"),
|
||||||
equalTo("fromdevpropertiesfile"));
|
equalTo("fromdevpropertiesfile"));
|
||||||
validateProfilePrecedence(null, "other", "dev");
|
validateProfilePrecedence(null, "other", "dev");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateProfilePrecedence(String... profiles) {
|
private void validateProfilePrecedence(String... profiles) {
|
||||||
this.initializer.onApplicationEvent(new ApplicationPreparedEvent(
|
ApplicationPreparedEvent event = new ApplicationPreparedEvent(
|
||||||
new SpringApplication(), new String[0], new AnnotationConfigApplicationContext()));
|
new SpringApplication(), new String[0],
|
||||||
|
new AnnotationConfigApplicationContext());
|
||||||
|
this.initializer.onApplicationEvent(event);
|
||||||
String log = this.out.toString();
|
String log = this.out.toString();
|
||||||
|
|
||||||
// First make sure that each profile got processed only once
|
// First make sure that each profile got processed only once
|
||||||
for (String profile : profiles) {
|
for (String profile : profiles) {
|
||||||
assertThat("Wrong number of occurrences for profile '" + profile + "' --> " + log,
|
String reason = "Wrong number of occurrences for profile '" + profile
|
||||||
StringUtils.countOccurrencesOf(log, createLogForProfile(profile)), equalTo(1));
|
+ "' --> " + log;
|
||||||
|
assertThat(reason,
|
||||||
|
StringUtils.countOccurrencesOf(log, createLogForProfile(profile)),
|
||||||
|
equalTo(1));
|
||||||
}
|
}
|
||||||
// Make sure the order of loading is the right one
|
// Make sure the order of loading is the right one
|
||||||
for (String profile : profiles) {
|
for (String profile : profiles) {
|
||||||
String line = createLogForProfile(profile);
|
String line = createLogForProfile(profile);
|
||||||
int index = log.indexOf(line);
|
int index = log.indexOf(line);
|
||||||
assertTrue("Loading profile '" + profile + "' not found in '" + log + "'", index != -1);
|
assertTrue("Loading profile '" + profile + "' not found in '" + log + "'",
|
||||||
|
index != -1);
|
||||||
log = log.substring(index + line.length(), log.length());
|
log = log.substring(index + line.length(), log.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue