|
|
@ -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));
|
|
|
|