Search in sources :

Example 36 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class ConfigDataActivationContextTests method getCloudPlatformWhenCloudPropertyNotPresentDeducesCloudPlatform.

@Test
void getCloudPlatformWhenCloudPropertyNotPresentDeducesCloudPlatform() {
    Environment environment = new MockEnvironment();
    Binder binder = Binder.get(environment);
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    assertThat(context.getCloudPlatform()).isNull();
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockEnvironment(org.springframework.mock.env.MockEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 37 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class CloudPlatformTests method getActiveWhenHasVcapApplicationShouldReturnCloudFoundry.

@Test
void getActiveWhenHasVcapApplicationShouldReturnCloudFoundry() {
    Environment environment = new MockEnvironment().withProperty("VCAP_APPLICATION", "---");
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.CLOUD_FOUNDRY);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 38 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class CloudPlatformTests method getActiveWhenHasKubernetesServicePortAndNoKubernetesServiceHostShouldNotReturnKubernetes.

@Test
void getActiveWhenHasKubernetesServicePortAndNoKubernetesServiceHostShouldNotReturnKubernetes() {
    Environment environment = getEnvironmentWithEnvVariables(Collections.singletonMap("KUBERNETES_SERVICE_PORT", "8080"));
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isNull();
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 39 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class CloudPlatformTests method getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes.

@Test
void getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes() {
    Environment environment = getEnvironmentWithEnvVariables(Collections.singletonMap("EXAMPLE_SERVICE_HOST", "---"));
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isNull();
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 40 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class CloudPlatformTests method getActiveWhenHasKubernetesServiceHostAndPortShouldReturnKubernetes.

@Test
void getActiveWhenHasKubernetesServiceHostAndPortShouldReturnKubernetes() {
    Map<String, Object> envVars = new HashMap<>();
    envVars.put("KUBERNETES_SERVICE_HOST", "---");
    envVars.put("KUBERNETES_SERVICE_PORT", "8080");
    Environment environment = getEnvironmentWithEnvVariables(envVars);
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.KUBERNETES);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : HashMap(java.util.HashMap) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (org.springframework.core.env.Environment)163 Test (org.junit.jupiter.api.Test)68 StandardEnvironment (org.springframework.core.env.StandardEnvironment)30 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)26 MockEnvironment (org.springframework.mock.env.MockEnvironment)24 SpringApplication (org.springframework.boot.SpringApplication)21 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)19 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)19 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)19 HashMap (java.util.HashMap)14 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)12 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)11 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)9 Map (java.util.Map)8 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)7 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)7 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)7 Predicate (java.util.function.Predicate)7