use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorsTests method getBinderWhenHasInactiveIgnoresInactive.
@Test
void getBinderWhenHasInactiveIgnoresInactive() {
MockPropertySource firstPropertySource = new MockPropertySource();
firstPropertySource.setProperty("test", "one");
firstPropertySource.setProperty("context.config.activate.on-profile", "production");
MockPropertySource secondPropertySource = new MockPropertySource();
secondPropertySource.setProperty("test", "two");
ConfigData configData = new ConfigData(Arrays.asList(firstPropertySource, secondPropertySource));
ConfigDataEnvironmentContributor firstContributor = createBoundImportContributor(configData, 0);
ConfigDataEnvironmentContributor secondContributor = createBoundImportContributor(configData, 1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.bootstrapContext, Arrays.asList(firstContributor, secondContributor));
Binder binder = contributors.getBinder(this.activationContext);
assertThat(binder.bind("test", String.class).get()).isEqualTo("two");
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorsTests method withProcessedImportsWhenHasNoUnprocessedImportsReturnsSameInstance.
@Test
void withProcessedImportsWhenHasNoUnprocessedImportsReturnsSameInstance() {
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(new MockPropertySource());
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.bootstrapContext, Arrays.asList(contributor));
ConfigDataEnvironmentContributors withProcessedImports = contributors.withProcessedImports(this.importer, this.activationContext);
assertThat(withProcessedImports).isSameAs(contributors);
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorsTests method withProcessedImportsProvidesLoaderContextWithAccessToBootstrapRegistry.
@Test
void withProcessedImportsProvidesLoaderContextWithAccessToBootstrapRegistry() {
MockPropertySource existingPropertySource = new MockPropertySource();
existingPropertySource.setProperty("test", "springboot");
ConfigDataEnvironmentContributor existingContributor = ConfigDataEnvironmentContributor.ofExisting(existingPropertySource);
this.importer = mock(ConfigDataImporter.class);
List<ConfigDataLocation> locations = List.of(LOCATION_1);
MockPropertySource propertySource = new MockPropertySource();
Map<ConfigDataResolutionResult, ConfigData> imported = new LinkedHashMap<>();
imported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a'"), false), new ConfigData(List.of(propertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(locations))).willReturn(imported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.bootstrapContext, Arrays.asList(existingContributor, contributor));
contributors.withProcessedImports(this.importer, this.activationContext);
then(this.importer).should().resolveAndLoad(any(), any(), this.loaderContext.capture(), any());
ConfigDataLoaderContext context = this.loaderContext.getValue();
assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext);
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorsTests method getBinderWhenHasPlaceholderResolvesPlaceholder.
@Test
void getBinderWhenHasPlaceholderResolvesPlaceholder() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("test", "${other}");
propertySource.setProperty("other", "springboot");
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(propertySource);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.bootstrapContext, List.of(contributor));
Binder binder = contributors.getBinder(this.activationContext);
assertThat(binder.bind("test", String.class).get()).isEqualTo("springboot");
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorsTests method withProcessedImportsProvidesLocationResolverContextWithAccessToParent.
@Test
void withProcessedImportsProvidesLocationResolverContextWithAccessToParent() {
this.importer = mock(ConfigDataImporter.class);
List<ConfigDataLocation> initialLocations = List.of(LOCATION_1);
MockPropertySource initialPropertySource = new MockPropertySource();
initialPropertySource.setProperty("context.config.import", "location2");
Map<ConfigDataResolutionResult, ConfigData> initialImported = new LinkedHashMap<>();
initialImported.put(new ConfigDataResolutionResult(LOCATION_1, new TestConfigDataResource("a"), false), new ConfigData(List.of(initialPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(initialLocations))).willReturn(initialImported);
List<ConfigDataLocation> secondLocations = List.of(LOCATION_2);
MockPropertySource secondPropertySource = new MockPropertySource();
Map<ConfigDataResolutionResult, ConfigData> secondImported = new LinkedHashMap<>();
secondImported.put(new ConfigDataResolutionResult(LOCATION_2, new TestConfigDataResource("b"), false), new ConfigData(List.of(secondPropertySource)));
given(this.importer.resolveAndLoad(eq(this.activationContext), any(), any(), eq(secondLocations))).willReturn(secondImported);
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.bootstrapContext, List.of(contributor));
contributors.withProcessedImports(this.importer, this.activationContext);
then(this.importer).should().resolveAndLoad(any(), this.locationResolverContext.capture(), any(), eq(secondLocations));
ConfigDataLocationResolverContext context = this.locationResolverContext.getValue();
assertThat(context.getParent()).hasToString("a");
}
Aggregations