Search in sources :

Example 96 with MockEnvironment

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

the class CloudPlatformTests method isEnforcedWhenEnvironmentPropertyIsMissingReturnsFalse.

@Test
void isEnforcedWhenEnvironmentPropertyIsMissingReturnsFalse() {
    MockEnvironment environment = new MockEnvironment();
    Assertions.assertThat(CloudPlatform.KUBERNETES.isEnforced(environment)).isFalse();
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 97 with MockEnvironment

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

the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithEmptyProperty.

@Test
@SuppressWarnings("rawtypes")
void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
    ConfigurableEnvironment environment = new MockEnvironment();
    PropertySources propertySources = environment.getPropertySources();
    propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
    assertThat(propertySources.size()).isEqualTo(0);
    addInlinedPropertiesToEnvironment(environment, asArray("  "));
    assertThat(propertySources.size()).isEqualTo(1);
    assertThat(((Map) propertySources.iterator().next().getSource()).size()).isEqualTo(0);
}
Also used : 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) Map(java.util.Map) TestPropertySourceUtils.convertInlinedPropertiesToMap(cn.taketoday.test.context.support.TestPropertySourceUtils.convertInlinedPropertiesToMap) Test(org.junit.jupiter.api.Test)

Example 98 with MockEnvironment

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

the class FilteredPropertySourceTests method applyWhenHasNoSourceShouldRunOperation.

@Test
void applyWhenHasNoSourceShouldRunOperation() {
    ConfigurableEnvironment environment = new MockEnvironment();
    TestOperation operation = new TestOperation();
    FilteredPropertySource.apply(environment, "test", Collections.emptySet(), operation);
    assertThat(operation.isCalled()).isTrue();
    assertThat(operation.getOriginal()).isNull();
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 99 with MockEnvironment

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

the class FilteredPropertySourceTests method applyWhenHasSourceShouldRunWithReplacedSource.

@Test
void applyWhenHasSourceShouldRunWithReplacedSource() {
    ConfigurableEnvironment environment = new MockEnvironment();
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("regular", "regularValue");
    map.put("filtered", "filteredValue");
    PropertySource<?> propertySource = new MapPropertySource("test", map);
    environment.getPropertySources().addFirst(propertySource);
    TestOperation operation = new TestOperation(() -> {
        assertThat(environment.containsProperty("regular")).isTrue();
        assertThat(environment.containsProperty("filtered")).isFalse();
    });
    FilteredPropertySource.apply(environment, "test", Collections.singleton("filtered"), operation);
    assertThat(operation.isCalled()).isTrue();
    assertThat(operation.getOriginal()).isSameAs(propertySource);
    assertThat(environment.getPropertySources().get("test")).isSameAs(propertySource);
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 100 with MockEnvironment

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

the class ProfilesTests method getActiveWhenEnvironmentProfilesAndBinderPropertyShouldReturnEnvironmentProperty.

@Test
void getActiveWhenEnvironmentProfilesAndBinderPropertyShouldReturnEnvironmentProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active", "a,b,c");
    List<ConfigurationPropertySource> sources = new ArrayList<>();
    ConfigurationPropertySources.get(environment).forEach(sources::add);
    sources.add(new MapConfigurationPropertySource(Collections.singletonMap("context.profiles.active", "d,e,f")));
    Binder binder = new Binder(sources);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).containsExactly("a", "b", "c");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ConfigurationPropertySource(cn.taketoday.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) ArrayList(java.util.ArrayList) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) 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