use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorTests method hasUnprocessedImportsWhenHasNoChildrenForPhaseReturnsTrue.
@Test
void hasUnprocessedImportsWhenHasNoChildrenForPhaseReturnsTrue() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("context.config.import", "springboot");
ConfigData configData = new ConfigData(Collections.singleton(propertySource));
ConfigDataEnvironmentContributor contributor = createBoundContributor(null, configData, 0);
assertThat(contributor.hasUnprocessedImports(ImportPhase.BEFORE_PROFILE_ACTIVATION)).isTrue();
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorTests method bindWhenConfigDataHasIgnoreImportsOptionsCreatesImportedContributorWithoutImports.
@Test
void bindWhenConfigDataHasIgnoreImportsOptionsCreatesImportedContributorWithoutImports() {
TestResource resource = new TestResource("test");
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("context.config.import", "test");
ConfigData configData = new ConfigData(Collections.singleton(propertySource), ConfigData.Option.IGNORE_IMPORTS);
ConfigDataEnvironmentContributor contributor = createBoundContributor(resource, configData, 0);
assertThat(contributor.getKind()).isEqualTo(Kind.BOUND_IMPORT);
assertThat(contributor.getResource()).isSameAs(resource);
assertThat(contributor.getImports()).isEmpty();
assertThat(contributor.isActive(this.activationContext)).isTrue();
assertThat(contributor.getPropertySource()).isEqualTo(propertySource);
assertThat(contributor.getConfigurationPropertySource()).isNotNull();
assertThat(contributor.getChildren(ImportPhase.BEFORE_PROFILE_ACTIVATION)).isEmpty();
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorTests method ofUnboundImportCreatesImportedContributor.
@Test
void ofUnboundImportCreatesImportedContributor() {
TestResource resource = new TestResource("test");
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("context.config.import", "test");
ConfigData configData = new ConfigData(Collections.singleton(propertySource));
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofUnboundImport(TEST_LOCATION, resource, false, configData, 0);
assertThat(contributor.getKind()).isEqualTo(Kind.UNBOUND_IMPORT);
assertThat(contributor.getResource()).isSameAs(resource);
assertThat(contributor.getImports()).isEmpty();
assertThat(contributor.isActive(this.activationContext)).isFalse();
assertThat(contributor.getPropertySource()).isEqualTo(propertySource);
assertThat(contributor.getConfigurationPropertySource()).isNotNull();
assertThat(contributor.getChildren(ImportPhase.BEFORE_PROFILE_ACTIVATION)).isEmpty();
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentTests method createCreatesContributorsBasedOnExistingSources.
@Test
void createCreatesContributorsBasedOnExistingSources() {
MockPropertySource propertySource1 = new MockPropertySource("p1");
MockPropertySource propertySource2 = new MockPropertySource("p2");
MockPropertySource propertySource3 = new MockPropertySource("p3");
this.environment.getPropertySources().addLast(propertySource1);
this.environment.getPropertySources().addLast(propertySource2);
this.environment.getPropertySources().addLast(propertySource3);
ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.bootstrapContext, this.environment, this.resourceLoader, this.additionalProfiles, null);
List<ConfigDataEnvironmentContributor> children = configDataEnvironment.getContributors().getRoot().getChildren(ImportPhase.BEFORE_PROFILE_ACTIVATION);
Object[] wrapped = children.stream().filter((child) -> child.getKind() == Kind.EXISTING).map(ConfigDataEnvironmentContributor::getPropertySource).toArray();
assertThat(wrapped[1]).isEqualTo(propertySource1);
assertThat(wrapped[2]).isEqualTo(propertySource2);
assertThat(wrapped[3]).isEqualTo(propertySource3);
}
use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class InvalidConfigDataPropertyExceptionTests method throwOrWarnWhenHasNoInvalidPropertyDoesNothing.
@Test
void throwOrWarnWhenHasNoInvalidPropertyDoesNothing() {
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(new MockPropertySource());
InvalidConfigDataPropertyException.throwIfPropertyFound(contributor);
}
Aggregations