Merge branch '2.4.x'

Closes gh-26575
pull/26586/head
Andy Wilkinson 4 years ago
commit d41fa13463

@ -297,6 +297,8 @@ class ConfigDataEnvironment {
binder.bind(Profiles.INCLUDE_PROFILES, STRING_LIST).ifBound((includes) -> { binder.bind(Profiles.INCLUDE_PROFILES, STRING_LIST).ifBound((includes) -> {
if (!contributor.isActive(activationContext)) { if (!contributor.isActive(activationContext)) {
InactiveConfigDataAccessException.throwIfPropertyFound(contributor, Profiles.INCLUDE_PROFILES); InactiveConfigDataAccessException.throwIfPropertyFound(contributor, Profiles.INCLUDE_PROFILES);
InactiveConfigDataAccessException.throwIfPropertyFound(contributor,
Profiles.INCLUDE_PROFILES.append("[0]"));
} }
result.addAll(includes); result.addAll(includes);
}); });

@ -27,6 +27,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.boot.ConfigurableBootstrapContext; import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.DefaultBootstrapContext; import org.springframework.boot.DefaultBootstrapContext;
@ -216,6 +218,53 @@ class ConfigDataEnvironmentTests {
assertThat(this.environment.getActiveProfiles()).containsExactly("test"); assertThat(this.environment.getActiveProfiles()).containsExactly("test");
} }
@ParameterizedTest
@CsvSource({ "include", "include[0]" })
void processAndApplyWhenHasProfileIncludeInProfileSpecificDocumentThrowsException(String property, TestInfo info) {
this.environment.setProperty("spring.config.location", getConfigLocation(info));
ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext,
this.environment, this.resourceLoader, this.additionalProfiles, null) {
@Override
protected ConfigDataEnvironmentContributors createContributors(
List<ConfigDataEnvironmentContributor> contributors) {
Map<String, Object> source = new LinkedHashMap<>();
source.put("spring.config.activate.on-profile", "activate");
source.put("spring.profiles." + property, "include");
ConfigData data = new ConfigData(Collections.singleton(new MapPropertySource("test", source)));
contributors.add(ConfigDataEnvironmentContributor.ofUnboundImport(ConfigDataLocation.of("test"),
mock(ConfigDataResource.class), false, data, 0));
return super.createContributors(contributors);
}
};
assertThatExceptionOfType(InactiveConfigDataAccessException.class)
.isThrownBy(configDataEnvironment::processAndApply);
}
@ParameterizedTest
@CsvSource({ "spring.profiles.include", "spring.profiles.include[0]" })
void processAndApplyIncludesProfilesFromSpringProfilesInclude(String property, TestInfo info) {
this.environment.setProperty("spring.config.location", getConfigLocation(info));
ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext,
this.environment, this.resourceLoader, this.additionalProfiles, null) {
@Override
protected ConfigDataEnvironmentContributors createContributors(
List<ConfigDataEnvironmentContributor> contributors) {
Map<String, Object> source = new LinkedHashMap<>();
source.put(property, "included");
ConfigData data = new ConfigData(Collections.singleton(new MapPropertySource("test", source)));
contributors.add(ConfigDataEnvironmentContributor.ofUnboundImport(ConfigDataLocation.of("test"),
mock(ConfigDataResource.class), false, data, 0));
return super.createContributors(contributors);
}
};
configDataEnvironment.processAndApply();
assertThat(this.environment.getActiveProfiles()).containsExactly("included");
}
@Test @Test
void processAndApplyDoesNotSetProfilesFromIgnoreProfilesContributorsWhenNoProfilesActive(TestInfo info) { void processAndApplyDoesNotSetProfilesFromIgnoreProfilesContributorsWhenNoProfilesActive(TestInfo info) {
this.environment.setProperty("spring.config.location", getConfigLocation(info)); this.environment.setProperty("spring.config.location", getConfigLocation(info));

Loading…
Cancel
Save