Search in sources :

Example 26 with MockEnvironment

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

the class CloudPlatformTests method getEnvironmentWithEnvVariables.

private Environment getEnvironmentWithEnvVariables(Map<String, Object> environmentVariables) {
    MockEnvironment environment = new MockEnvironment();
    PropertySource<?> propertySource = new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, environmentVariables);
    environment.getPropertySources().addFirst(propertySource);
    return environment;
}
Also used : SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) MockEnvironment(cn.taketoday.mock.env.MockEnvironment)

Example 27 with MockEnvironment

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

the class CloudPlatformTests method getActiveWhenNotInCloudShouldReturnNull.

@Test
void getActiveWhenNotInCloudShouldReturnNull() {
    Environment environment = new MockEnvironment();
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isNull();
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 28 with MockEnvironment

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

the class TomcatServletWebServerFactoryCustomizerTests method setup.

@BeforeEach
void setup() {
    this.environment = new MockEnvironment();
    this.serverProperties = new ServerProperties();
    ConfigurationPropertySources.attach(this.environment);
    this.customizer = new TomcatServletWebServerFactoryCustomizer(this.serverProperties);
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with MockEnvironment

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

the class BackCompatibilityBinderIntegrationTests method bindWhenBindingCamelCaseToEnvironmentWithExtractUnderscore.

@Test
void bindWhenBindingCamelCaseToEnvironmentWithExtractUnderscore() {
    // gh-10873
    MockEnvironment environment = new MockEnvironment();
    SystemEnvironmentPropertySource propertySource = new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("FOO_ZK_NODES", "foo"));
    environment.getPropertySources().addFirst(propertySource);
    ExampleCamelCaseBean result = Binder.get(environment).bind("foo", Bindable.of(ExampleCamelCaseBean.class)).get();
    assertThat(result.getZkNodes()).isEqualTo("foo");
}
Also used : SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 30 with MockEnvironment

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

the class TestPropertySourceUtilsTests method addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile.

@Test
void addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile() {
    ConfigurableEnvironment environment = new MockEnvironment();
    PropertySources propertySources = environment.getPropertySources();
    propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
    assertThat(propertySources.size()).isEqualTo(0);
    String pair = "key = value";
    ByteArrayResource resource = new ByteArrayResource(pair.getBytes(), "from inlined property: " + pair);
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    given(resourceLoader.getResource(anyString())).willReturn(resource);
    addPropertiesFilesToEnvironment(environment, resourceLoader, FOO_LOCATIONS);
    assertThat(propertySources.size()).isEqualTo(1);
    assertThat(environment.getProperty("key")).isEqualTo("value");
}
Also used : ResourceLoader(cn.taketoday.core.io.ResourceLoader) TestPropertySourceUtils.buildMergedTestPropertySources(cn.taketoday.test.context.support.TestPropertySourceUtils.buildMergedTestPropertySources) PropertySources(cn.taketoday.core.env.PropertySources) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteArrayResource(cn.taketoday.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

MockEnvironment (cn.taketoday.mock.env.MockEnvironment)132 Test (org.junit.jupiter.api.Test)118 Binder (cn.taketoday.context.properties.bind.Binder)84 Environment (cn.taketoday.core.env.Environment)24 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)16 MapConfigurationPropertySource (cn.taketoday.context.properties.source.MapConfigurationPropertySource)12 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)4 PropertySources (cn.taketoday.core.env.PropertySources)4 TestPropertySourceUtils.buildMergedTestPropertySources (cn.taketoday.test.context.support.TestPropertySourceUtils.buildMergedTestPropertySources)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 ConditionEvaluationContext (cn.taketoday.context.annotation.ConditionEvaluationContext)2 ByteArrayResource (cn.taketoday.core.io.ByteArrayResource)2 DefaultResourceLoader (cn.taketoday.core.io.DefaultResourceLoader)2 ResourceLoader (cn.taketoday.core.io.ResourceLoader)2 ApplicationBuilder (cn.taketoday.framework.builder.ApplicationBuilder)2