Merge branch '2.5.x'

Closes gh-27006
pull/27017/head
Phillip Webb 3 years ago
commit 86dc156162

@ -117,10 +117,9 @@ class ConfigDataEnvironmentContributors implements Iterable<ConfigDataEnvironmen
result, contributor, activationContext); result, contributor, activationContext);
ConfigDataLoaderContext loaderContext = new ContributorDataLoaderContext(this); ConfigDataLoaderContext loaderContext = new ContributorDataLoaderContext(this);
List<ConfigDataLocation> imports = contributor.getImports(); List<ConfigDataLocation> imports = contributor.getImports();
boolean resolveProfileSpecific = !contributor.isFromProfileSpecificImport();
this.logger.trace(LogMessage.format("Processing imports %s", imports)); this.logger.trace(LogMessage.format("Processing imports %s", imports));
Map<ConfigDataResolutionResult, ConfigData> imported = importer.resolveAndLoad(activationContext, Map<ConfigDataResolutionResult, ConfigData> imported = importer.resolveAndLoad(activationContext,
locationResolverContext, loaderContext, imports, resolveProfileSpecific); locationResolverContext, loaderContext, imports);
this.logger.trace(LogMessage.of(() -> getImportedMessage(imported.keySet()))); this.logger.trace(LogMessage.of(() -> getImportedMessage(imported.keySet())));
ConfigDataEnvironmentContributor contributorAndChildren = contributor.withChildren(importPhase, ConfigDataEnvironmentContributor contributorAndChildren = contributor.withChildren(importPhase,
asContributors(imported)); asContributors(imported));

@ -75,16 +75,14 @@ class ConfigDataImporter {
* @param locationResolverContext the location resolver context * @param locationResolverContext the location resolver context
* @param loaderContext the loader context * @param loaderContext the loader context
* @param locations the locations to resolve * @param locations the locations to resolve
* @param resolveProfileSpecific if profile specific resolution should be attempted
* @return a map of the loaded locations and data * @return a map of the loaded locations and data
*/ */
Map<ConfigDataResolutionResult, ConfigData> resolveAndLoad(ConfigDataActivationContext activationContext, Map<ConfigDataResolutionResult, ConfigData> resolveAndLoad(ConfigDataActivationContext activationContext,
ConfigDataLocationResolverContext locationResolverContext, ConfigDataLoaderContext loaderContext, ConfigDataLocationResolverContext locationResolverContext, ConfigDataLoaderContext loaderContext,
List<ConfigDataLocation> locations, boolean resolveProfileSpecific) { List<ConfigDataLocation> locations) {
try { try {
Profiles profiles = (activationContext != null) ? activationContext.getProfiles() : null; Profiles profiles = (activationContext != null) ? activationContext.getProfiles() : null;
List<ConfigDataResolutionResult> resolved = resolve(locationResolverContext, profiles, locations, List<ConfigDataResolutionResult> resolved = resolve(locationResolverContext, profiles, locations);
resolveProfileSpecific);
return load(loaderContext, resolved); return load(loaderContext, resolved);
} }
catch (IOException ex) { catch (IOException ex) {
@ -93,18 +91,18 @@ class ConfigDataImporter {
} }
private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext locationResolverContext, private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext locationResolverContext,
Profiles profiles, List<ConfigDataLocation> locations, boolean resolveProfileSpecific) { Profiles profiles, List<ConfigDataLocation> locations) {
List<ConfigDataResolutionResult> resolved = new ArrayList<>(locations.size()); List<ConfigDataResolutionResult> resolved = new ArrayList<>(locations.size());
for (ConfigDataLocation location : locations) { for (ConfigDataLocation location : locations) {
resolved.addAll(resolve(locationResolverContext, profiles, location, resolveProfileSpecific)); resolved.addAll(resolve(locationResolverContext, profiles, location));
} }
return Collections.unmodifiableList(resolved); return Collections.unmodifiableList(resolved);
} }
private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext locationResolverContext, private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext locationResolverContext,
Profiles profiles, ConfigDataLocation location, boolean resolveProfileSpecific) { Profiles profiles, ConfigDataLocation location) {
try { try {
return this.resolvers.resolve(locationResolverContext, location, profiles, resolveProfileSpecific); return this.resolvers.resolve(locationResolverContext, location, profiles);
} }
catch (ConfigDataNotFoundException ex) { catch (ConfigDataNotFoundException ex) {
handle(ex, location, null); handle(ex, location, null);

@ -98,23 +98,22 @@ class ConfigDataLocationResolvers {
} }
List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext context, ConfigDataLocation location, List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolverContext context, ConfigDataLocation location,
Profiles profiles, boolean resolveProfileSpecific) { Profiles profiles) {
if (location == null) { if (location == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
for (ConfigDataLocationResolver<?> resolver : getResolvers()) { for (ConfigDataLocationResolver<?> resolver : getResolvers()) {
if (resolver.isResolvable(context, location)) { if (resolver.isResolvable(context, location)) {
return resolve(resolver, context, location, profiles, resolveProfileSpecific); return resolve(resolver, context, location, profiles);
} }
} }
throw new UnsupportedConfigDataLocationException(location); throw new UnsupportedConfigDataLocationException(location);
} }
private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolver<?> resolver, private List<ConfigDataResolutionResult> resolve(ConfigDataLocationResolver<?> resolver,
ConfigDataLocationResolverContext context, ConfigDataLocation location, Profiles profiles, ConfigDataLocationResolverContext context, ConfigDataLocation location, Profiles profiles) {
boolean resolveProfileSpecific) {
List<ConfigDataResolutionResult> resolved = resolve(location, false, () -> resolver.resolve(context, location)); List<ConfigDataResolutionResult> resolved = resolve(location, false, () -> resolver.resolve(context, location));
if (profiles == null || !resolveProfileSpecific) { if (profiles == null) {
return resolved; return resolved;
} }
List<ConfigDataResolutionResult> profileSpecific = resolve(location, true, List<ConfigDataResolutionResult> profileSpecific = resolve(location, true,

@ -44,7 +44,6 @@ import org.springframework.mock.env.MockPropertySource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -122,7 +121,7 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>();
imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false), imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false),
new ConfigData(Arrays.asList(propertySource))); new ConfigData(Arrays.asList(propertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations)))
.willReturn(imported); .willReturn(imported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
@ -145,14 +144,14 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> initialImported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> initialImported = new LinkedHashMap<>();
initialImported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false), initialImported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false),
new ConfigData(Arrays.asList(initialPropertySource))); new ConfigData(Arrays.asList(initialPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(initialLocations), given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(initialLocations)))
anyBoolean())).willReturn(initialImported); .willReturn(initialImported);
List<ConfigDataLocation> secondLocations = Arrays.asList(LOCATION_2); List<ConfigDataLocation> secondLocations = Arrays.asList(LOCATION_2);
MockPropertySource secondPropertySource = new MockPropertySource(); MockPropertySource secondPropertySource = new MockPropertySource();
Map<ConfigDataResolutionResult, ConfigData> secondImported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> secondImported = new LinkedHashMap<>();
secondImported.put(new ConfigDataResolutionResult(LOCATION_2, new TestConfigDataResource("b"), false), secondImported.put(new ConfigDataResolutionResult(LOCATION_2, new TestConfigDataResource("b"), false),
new ConfigData(Arrays.asList(secondPropertySource))); new ConfigData(Arrays.asList(secondPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(secondLocations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(secondLocations)))
.willReturn(secondImported); .willReturn(secondImported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
@ -179,13 +178,13 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>();
imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false), imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false),
new ConfigData(Arrays.asList(propertySource))); new ConfigData(Arrays.asList(propertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations)))
.willReturn(imported); .willReturn(imported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
this.bootstrapContext, Arrays.asList(existingContributor, contributor)); this.bootstrapContext, Arrays.asList(existingContributor, contributor));
contributors.withProcessedImports(this.importer, this.activationContext); contributors.withProcessedImports(this.importer, this.activationContext);
verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any(), anyBoolean()); verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any());
ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue();
assertThat(context.getBinder().bind("test", String.class).get()).isEqualTo("springboot"); assertThat(context.getBinder().bind("test", String.class).get()).isEqualTo("springboot");
} }
@ -199,21 +198,20 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> initialImported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> initialImported = new LinkedHashMap<>();
initialImported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false), initialImported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false),
new ConfigData(Arrays.asList(initialPropertySource))); new ConfigData(Arrays.asList(initialPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(initialLocations), given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(initialLocations)))
anyBoolean())).willReturn(initialImported); .willReturn(initialImported);
List<ConfigDataLocation> secondLocations = Arrays.asList(LOCATION_2); List<ConfigDataLocation> secondLocations = Arrays.asList(LOCATION_2);
MockPropertySource secondPropertySource = new MockPropertySource(); MockPropertySource secondPropertySource = new MockPropertySource();
Map<ConfigDataResolutionResult, ConfigData> secondImported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> secondImported = new LinkedHashMap<>();
secondImported.put(new ConfigDataResolutionResult(LOCATION_2, new TestConfigDataResource("b"), false), secondImported.put(new ConfigDataResolutionResult(LOCATION_2, new TestConfigDataResource("b"), false),
new ConfigData(Arrays.asList(secondPropertySource))); new ConfigData(Arrays.asList(secondPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(secondLocations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(secondLocations)))
.willReturn(secondImported); .willReturn(secondImported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
this.bootstrapContext, Arrays.asList(contributor)); this.bootstrapContext, Arrays.asList(contributor));
contributors.withProcessedImports(this.importer, this.activationContext); contributors.withProcessedImports(this.importer, this.activationContext);
verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), eq(secondLocations), verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), eq(secondLocations));
anyBoolean());
ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue();
assertThat(context.getParent()).hasToString("a"); assertThat(context.getParent()).hasToString("a");
} }
@ -230,13 +228,13 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>();
imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false), imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false),
new ConfigData(Arrays.asList(propertySource))); new ConfigData(Arrays.asList(propertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations)))
.willReturn(imported); .willReturn(imported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
this.bootstrapContext, Arrays.asList(existingContributor, contributor)); this.bootstrapContext, Arrays.asList(existingContributor, contributor));
contributors.withProcessedImports(this.importer, this.activationContext); contributors.withProcessedImports(this.importer, this.activationContext);
verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any(), anyBoolean()); verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any());
ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue();
assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext); assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext);
} }
@ -253,13 +251,13 @@ class ConfigDataEnvironmentContributorsTests {
Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>(); Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>();
imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false), imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false),
new ConfigData(Arrays.asList(propertySource))); new ConfigData(Arrays.asList(propertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations), anyBoolean())) given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations)))
.willReturn(imported); .willReturn(imported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
this.bootstrapContext, Arrays.asList(existingContributor, contributor)); this.bootstrapContext, Arrays.asList(existingContributor, contributor));
contributors.withProcessedImports(this.importer, this.activationContext); contributors.withProcessedImports(this.importer, this.activationContext);
verify(this.importer).resolveAndLoad(any(), any(), this.loaderContext.capture(), any(), anyBoolean()); verify(this.importer).resolveAndLoad(any(), any(), this.loaderContext.capture(), any());
ConfigDataLoaderContext context = this.loaderContext.getValue(); ConfigDataLoaderContext context = this.loaderContext.getValue();
assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext); assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext);
} }

@ -750,8 +750,8 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat(environment.getProperty("test2")).isEqualTo("test2"); assertThat(environment.getProperty("test2")).isEqualTo("test2");
} }
@Test // gh-26752 @Test // gh-26960
void runWhenHasProfileSpecificImportWithImportDoesNotImportSecondProfileSpecificFile() { void runWhenHasProfileSpecificImportWithImportImportsSecondProfileSpecificFile() {
ConfigurableApplicationContext context = this.application ConfigurableApplicationContext context = this.application
.run("--spring.config.name=application-profile-specific-import-with-import"); .run("--spring.config.name=application-profile-specific-import-with-import");
ConfigurableEnvironment environment = context.getEnvironment(); ConfigurableEnvironment environment = context.getEnvironment();
@ -759,17 +759,17 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat(environment.containsProperty("application-profile-specific-import-with-import-p1")).isTrue(); assertThat(environment.containsProperty("application-profile-specific-import-with-import-p1")).isTrue();
assertThat(environment.containsProperty("application-profile-specific-import-with-import-p2")).isFalse(); assertThat(environment.containsProperty("application-profile-specific-import-with-import-p2")).isFalse();
assertThat(environment.containsProperty("application-profile-specific-import-with-import-import")).isTrue(); assertThat(environment.containsProperty("application-profile-specific-import-with-import-import")).isTrue();
assertThat(environment.containsProperty("application-profile-specific-import-with-import-import-p1")).isFalse(); assertThat(environment.containsProperty("application-profile-specific-import-with-import-import-p1")).isTrue();
assertThat(environment.containsProperty("application-profile-specific-import-with-import-import-p2")).isFalse(); assertThat(environment.containsProperty("application-profile-specific-import-with-import-import-p2")).isTrue();
} }
@Test // gh-26753 @Test // gh-26960
void runWhenHasProfileSpecificImportWithCustomImportDoesNotResolveProfileSpecific() { void runWhenHasProfileSpecificImportWithCustomImportResolvesProfileSpecific() {
ConfigurableApplicationContext context = this.application ConfigurableApplicationContext context = this.application
.run("--spring.config.name=application-profile-specific-import-with-custom-import"); .run("--spring.config.name=application-profile-specific-import-with-custom-import");
ConfigurableEnvironment environment = context.getEnvironment(); ConfigurableEnvironment environment = context.getEnvironment();
assertThat(environment.containsProperty("test:boot")).isTrue(); assertThat(environment.containsProperty("test:boot")).isTrue();
assertThat(environment.containsProperty("test:boot:ps")).isFalse(); assertThat(environment.containsProperty("test:boot:ps")).isTrue();
} }
@Test // gh-26593 @Test // gh-26593

@ -80,16 +80,16 @@ class ConfigDataImporterTests {
TestResource resource2 = new TestResource("r2"); TestResource resource2 = new TestResource("r2");
ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource())); ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource()));
ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource())); ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource()));
given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles, true)) given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles))
.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false))); .willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false)));
given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles, true)) given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles))
.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false))); .willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false)));
given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1); given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1);
given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2); given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2);
ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL, ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL,
this.resolvers, this.loaders); this.resolvers, this.loaders);
Collection<ConfigData> loaded = importer.resolveAndLoad(this.activationContext, this.locationResolverContext, Collection<ConfigData> loaded = importer.resolveAndLoad(this.activationContext, this.locationResolverContext,
this.loaderContext, Arrays.asList(location1, location2), true).values(); this.loaderContext, Arrays.asList(location1, location2)).values();
assertThat(loaded).containsExactly(configData2, configData1); assertThat(loaded).containsExactly(configData2, configData1);
} }
@ -106,11 +106,11 @@ class ConfigDataImporterTests {
ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource())); ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource()));
ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource())); ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource()));
ConfigData configData3 = new ConfigData(Collections.singleton(new MockPropertySource())); ConfigData configData3 = new ConfigData(Collections.singleton(new MockPropertySource()));
given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles, true)) given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles))
.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false))); .willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false)));
given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles, true)) given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles))
.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false))); .willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false)));
given(this.resolvers.resolve(this.locationResolverContext, location3, this.profiles, true)) given(this.resolvers.resolve(this.locationResolverContext, location3, this.profiles))
.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location3, resource3, false))); .willReturn(Collections.singletonList(new ConfigDataResolutionResult(location3, resource3, false)));
given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1); given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1);
given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2); given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2);
@ -118,9 +118,9 @@ class ConfigDataImporterTests {
ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL, ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL,
this.resolvers, this.loaders); this.resolvers, this.loaders);
Collection<ConfigData> loaded1and2 = importer.resolveAndLoad(this.activationContext, Collection<ConfigData> loaded1and2 = importer.resolveAndLoad(this.activationContext,
this.locationResolverContext, this.loaderContext, locations1and2, true).values(); this.locationResolverContext, this.loaderContext, locations1and2).values();
Collection<ConfigData> loaded2and3 = importer.resolveAndLoad(this.activationContext, Collection<ConfigData> loaded2and3 = importer.resolveAndLoad(this.activationContext,
this.locationResolverContext, this.loaderContext, locations2and3, true).values(); this.locationResolverContext, this.loaderContext, locations2and3).values();
assertThat(loaded1and2).containsExactly(configData2, configData1); assertThat(loaded1and2).containsExactly(configData2, configData1);
assertThat(loaded2and3).containsExactly(configData3); assertThat(loaded2and3).containsExactly(configData3);
} }

@ -131,7 +131,7 @@ class ConfigDataLocationResolversTests {
this.binder, this.resourceLoader, this.binder, this.resourceLoader,
Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName())); Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName()));
ConfigDataLocation location = ConfigDataLocation.of("LowestTestResolver:test"); ConfigDataLocation location = ConfigDataLocation.of("LowestTestResolver:test");
List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, null, true); List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, null);
assertThat(resolved).hasSize(1); assertThat(resolved).hasSize(1);
TestConfigDataResource resource = (TestConfigDataResource) resolved.get(0).getResource(); TestConfigDataResource resource = (TestConfigDataResource) resolved.get(0).getResource();
assertThat(resource.getResolver()).isInstanceOf(LowestTestResolver.class); assertThat(resource.getResolver()).isInstanceOf(LowestTestResolver.class);
@ -145,7 +145,7 @@ class ConfigDataLocationResolversTests {
this.binder, this.resourceLoader, this.binder, this.resourceLoader,
Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName())); Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName()));
ConfigDataLocation location = ConfigDataLocation.of("LowestTestResolver:test"); ConfigDataLocation location = ConfigDataLocation.of("LowestTestResolver:test");
List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, this.profiles, true); List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, this.profiles);
assertThat(resolved).hasSize(2); assertThat(resolved).hasSize(2);
TestConfigDataResource resource = (TestConfigDataResource) resolved.get(0).getResource(); TestConfigDataResource resource = (TestConfigDataResource) resolved.get(0).getResource();
assertThat(resource.getResolver()).isInstanceOf(LowestTestResolver.class); assertThat(resource.getResolver()).isInstanceOf(LowestTestResolver.class);
@ -164,7 +164,7 @@ class ConfigDataLocationResolversTests {
Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName())); Arrays.asList(LowestTestResolver.class.getName(), HighestTestResolver.class.getName()));
ConfigDataLocation location = ConfigDataLocation.of("Missing:test"); ConfigDataLocation location = ConfigDataLocation.of("Missing:test");
assertThatExceptionOfType(UnsupportedConfigDataLocationException.class) assertThatExceptionOfType(UnsupportedConfigDataLocationException.class)
.isThrownBy(() -> resolvers.resolve(this.context, location, null, true)) .isThrownBy(() -> resolvers.resolve(this.context, location, null))
.satisfies((ex) -> assertThat(ex.getLocation()).isEqualTo(location)); .satisfies((ex) -> assertThat(ex.getLocation()).isEqualTo(location));
} }
@ -173,7 +173,7 @@ class ConfigDataLocationResolversTests {
ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext, ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext,
this.binder, this.resourceLoader, Arrays.asList(OptionalResourceTestResolver.class.getName())); this.binder, this.resourceLoader, Arrays.asList(OptionalResourceTestResolver.class.getName()));
ConfigDataLocation location = ConfigDataLocation.of("OptionalResourceTestResolver:test"); ConfigDataLocation location = ConfigDataLocation.of("OptionalResourceTestResolver:test");
List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, null, true); List<ConfigDataResolutionResult> resolved = resolvers.resolve(this.context, location, null);
assertThat(resolved.get(0).getResource().isOptional()).isTrue(); assertThat(resolved.get(0).getResource().isOptional()).isTrue();
} }

Loading…
Cancel
Save