Search in sources :

Example 21 with StandardEnvironment

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

the class EnvironmentConverterTests method envClassSameShouldReturnEnvironmentUnconverted.

@Test
void envClassSameShouldReturnEnvironmentUnconverted() {
    StandardEnvironment standardEnvironment = new StandardEnvironment();
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), standardEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment).isSameAs(standardEnvironment);
}
Also used : StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 22 with StandardEnvironment

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

the class EnvironmentConverterTests method envClassSameShouldReturnEnvironmentUnconvertedEvenForWeb.

@Test
void envClassSameShouldReturnEnvironmentUnconvertedEvenForWeb() {
    StandardServletEnvironment standardServletEnvironment = new StandardServletEnvironment();
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), standardServletEnvironment, StandardServletEnvironment.class);
    assertThat(convertedEnvironment).isSameAs(standardServletEnvironment);
}
Also used : StandardServletEnvironment(cn.taketoday.web.context.support.StandardServletEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 23 with StandardEnvironment

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

the class EnvironmentConverter method convertEnvironment.

static StandardEnvironment convertEnvironment(ClassLoader classLoader, ConfigurableEnvironment environment, Class<? extends StandardEnvironment> type) {
    StandardEnvironment result = createEnvironment(type);
    result.setActiveProfiles(environment.getActiveProfiles());
    result.setConversionService(environment.getConversionService());
    copyPropertySources(environment, result, classLoader);
    return result;
}
Also used : StandardEnvironment(cn.taketoday.core.env.StandardEnvironment)

Example 24 with StandardEnvironment

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

the class MapBinderTests method bindToMapWithPlaceholdersShouldBeGreedyForScalars.

@Test
void bindToMapWithPlaceholdersShouldBeGreedyForScalars() {
    StandardEnvironment environment = new StandardEnvironment();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "foo=boo");
    MockConfigurationPropertySource source = new MockConfigurationPropertySource("foo.aaa.bbb.ccc", "baz-${foo}");
    this.sources.add(source);
    this.binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment));
    Map<String, ExampleEnum> result = this.binder.bind("foo", Bindable.mapOf(String.class, ExampleEnum.class)).get();
    assertThat(result).containsEntry("aaa.bbb.ccc", ExampleEnum.BAZ_BOO);
}
Also used : MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) ExampleEnum(cn.taketoday.context.properties.bind.BinderTests.ExampleEnum) Test(org.junit.jupiter.api.Test)

Example 25 with StandardEnvironment

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

the class BinderTests method bindToValueWithPlaceholdersShouldResolve.

@Test
void bindToValueWithPlaceholdersShouldResolve() {
    StandardEnvironment environment = new StandardEnvironment();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "bar=23");
    this.sources.add(new MockConfigurationPropertySource("foo", "1${bar}"));
    this.binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment));
    BindResult<Integer> result = this.binder.bind("foo", Bindable.of(Integer.class));
    assertThat(result.get()).isEqualTo(123);
}
Also used : MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) 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