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();
}
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);
}
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();
}
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);
}
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");
}
Aggregations