Search in sources :

Example 16 with StandardEnvironment

use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.

the class AbstractApplicationEnvironmentTests method getActiveProfilesDoesNotResolveProperty.

@Test
void getActiveProfilesDoesNotResolveProperty() {
    StandardEnvironment environment = createEnvironment();
    new MockPropertySource().withProperty("", "");
    environment.getPropertySources().addFirst(new MockPropertySource().withProperty(AbstractEnvironment.KEY_ACTIVE_PROFILES, "test"));
    assertThat(environment.getActiveProfiles()).isEmpty();
}
Also used : MockPropertySource(cn.taketoday.core.env.MockPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 17 with StandardEnvironment

use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.

the class AbstractApplicationEnvironmentTests method getDefaultProfilesDoesNotResolveProperty.

@Test
void getDefaultProfilesDoesNotResolveProperty() {
    StandardEnvironment environment = createEnvironment();
    new MockPropertySource().withProperty("", "");
    environment.getPropertySources().addFirst(new MockPropertySource().withProperty(AbstractEnvironment.KEY_DEFAULT_PROFILES, "test"));
    assertThat(environment.getDefaultProfiles()).containsExactly("default");
}
Also used : MockPropertySource(cn.taketoday.core.env.MockPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 18 with StandardEnvironment

use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.

the class EnvironmentConverterTests method convertedEnvironmentHasSameActiveProfiles.

@Test
void convertedEnvironmentHasSameActiveProfiles() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    originalEnvironment.setActiveProfiles("activeProfile1", "activeProfile2");
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getActiveProfiles()).containsExactly("activeProfile1", "activeProfile2");
}
Also used : MockEnvironment(cn.taketoday.context.support.MockEnvironment) AbstractEnvironment(cn.taketoday.core.env.AbstractEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 19 with StandardEnvironment

use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.

the class EnvironmentConverterTests method servletPropertySourcesAreNotCopiedOverIfNotWebEnvironment.

@Test
void servletPropertySourcesAreNotCopiedOverIfNotWebEnvironment() {
    StandardServletEnvironment standardServletEnvironment = new StandardServletEnvironment();
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), standardServletEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment).isNotSameAs(standardServletEnvironment);
    Set<String> names = new HashSet<>();
    for (PropertySource<?> propertySource : convertedEnvironment.getPropertySources()) {
        names.add(propertySource.getName());
    }
    assertThat(names).doesNotContain(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME);
}
Also used : StandardServletEnvironment(cn.taketoday.web.context.support.StandardServletEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 20 with StandardEnvironment

use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.

the class EnvironmentConverterTests method servletPropertySourcesArePresentWhenTypeToConvertIsWeb.

@Test
void servletPropertySourcesArePresentWhenTypeToConvertIsWeb() {
    StandardEnvironment standardEnvironment = new StandardEnvironment();
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), standardEnvironment, StandardServletEnvironment.class);
    assertThat(convertedEnvironment).isNotSameAs(standardEnvironment);
    Set<String> names = new HashSet<>();
    for (PropertySource<?> propertySource : convertedEnvironment.getPropertySources()) {
        names.add(propertySource.getName());
    }
    assertThat(names).contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME);
}
Also used : StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)96 Test (org.junit.jupiter.api.Test)88 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)46 MapPropertySource (cn.taketoday.core.env.MapPropertySource)24 PropertySources (cn.taketoday.core.env.PropertySources)18 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)8 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)8 Environment (cn.taketoday.core.env.Environment)6 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)6 StandardServletEnvironment (cn.taketoday.web.context.support.StandardServletEnvironment)6 LinkedHashMap (java.util.LinkedHashMap)6 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)4 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)4 ClassPathScanningCandidateComponentProvider (cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider)4 MockEnvironment (cn.taketoday.context.support.MockEnvironment)4 AbstractEnvironment (cn.taketoday.core.env.AbstractEnvironment)4 CommandLinePropertySource (cn.taketoday.core.env.CommandLinePropertySource)4 CompositePropertySource (cn.taketoday.core.env.CompositePropertySource)4 MockPropertySource (cn.taketoday.core.env.MockPropertySource)4 PropertyResolver (cn.taketoday.core.env.PropertyResolver)4