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