Search in sources :

Example 6 with MockPropertySource

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();
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 7 with MockPropertySource

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();
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 8 with MockPropertySource

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();
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 9 with MockPropertySource

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);
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with MockPropertySource

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);
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MockPropertySource (cn.taketoday.mock.env.MockPropertySource)88 Test (org.junit.jupiter.api.Test)84 Binder (cn.taketoday.context.properties.bind.Binder)16 LinkedHashMap (java.util.LinkedHashMap)12 MockServletContext (cn.taketoday.mock.web.MockServletContext)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 PropertySource (cn.taketoday.core.env.PropertySource)4 MockServletConfig (cn.taketoday.mock.web.MockServletConfig)4 MapPropertySource (cn.taketoday.core.env.MapPropertySource)2 AddedPropertySource (cn.taketoday.framework.context.config.TestConfigDataEnvironmentUpdateListener.AddedPropertySource)2 AbstractRefreshableWebApplicationContext (cn.taketoday.web.context.support.AbstractRefreshableWebApplicationContext)2 AnnotationConfigWebApplicationContext (cn.taketoday.web.context.support.AnnotationConfigWebApplicationContext)2 GenericWebServletApplicationContext (cn.taketoday.web.context.support.GenericWebServletApplicationContext)2 StaticWebServletApplicationContext (cn.taketoday.web.context.support.StaticWebServletApplicationContext)2