Search in sources :

Example 1 with MockPropertySource

use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentContributorTests method isActiveWhenPropertiesIsNotActiveReturnsFalse.

@Test
void isActiveWhenPropertiesIsNotActiveReturnsFalse() {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("context.config.activate.on-cloud-platform", "heroku");
    ConfigData configData = new ConfigData(Collections.singleton(propertySource));
    ConfigDataEnvironmentContributor contributor = createBoundContributor(null, configData, 0);
    assertThat(contributor.isActive(this.activationContext)).isFalse();
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 2 with MockPropertySource

use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentContributorTests method isActiveWhenPropertiesIsActiveReturnsTrue.

@Test
void isActiveWhenPropertiesIsActiveReturnsTrue() {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("context.config.activate.on-cloud-platform", "kubernetes");
    ConfigData configData = new ConfigData(Collections.singleton(propertySource));
    ConfigDataEnvironmentContributor contributor = createBoundContributor(null, configData, 0);
    assertThat(contributor.isActive(this.activationContext)).isTrue();
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 3 with MockPropertySource

use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentContributorTests method bindCreatesImportedContributor.

@Test
void bindCreatesImportedContributor() {
    TestResource resource = new TestResource("test");
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("context.config.import", "test");
    ConfigData configData = new ConfigData(Collections.singleton(propertySource));
    ConfigDataEnvironmentContributor contributor = createBoundContributor(resource, configData, 0);
    assertThat(contributor.getKind()).isEqualTo(Kind.BOUND_IMPORT);
    assertThat(contributor.getResource()).isSameAs(resource);
    assertThat(contributor.getImports()).containsExactly(TEST_LOCATION);
    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 4 with MockPropertySource

use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentContributorTests method getConfigurationPropertySourceReturnsAdaptedPropertySource.

@Test
void getConfigurationPropertySourceReturnsAdaptedPropertySource() {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("spring", "boot");
    ConfigData configData = new ConfigData(Collections.singleton(propertySource));
    ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofUnboundImport(null, null, false, configData, 0);
    assertThat(contributor.getConfigurationPropertySource().getConfigurationProperty(ConfigurationPropertyName.of("spring")).getValue()).isEqualTo("boot");
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Example 5 with MockPropertySource

use of cn.taketoday.mock.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentContributorTests method getImportsIgnoresEmptyElements.

@Test
void getImportsIgnoresEmptyElements() {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("context.config.import", "spring,,boot,");
    ConfigData configData = new ConfigData(Collections.singleton(propertySource));
    ConfigDataEnvironmentContributor contributor = createBoundContributor(null, configData, 0);
    assertThat(contributor.getImports()).containsExactly(ConfigDataLocation.valueOf("spring"), ConfigDataLocation.valueOf("boot"));
}
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