Search in sources :

Example 41 with Environment

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

the class CloudPlatformTests method getActiveWhenHasVcapServicesShouldReturnCloudFoundry.

@Test
void getActiveWhenHasVcapServicesShouldReturnCloudFoundry() {
    Environment environment = new MockEnvironment().withProperty("VCAP_SERVICES", "---");
    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 42 with Environment

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

the class CloudPlatformTests method getActiveWhenHasAllAzureEnvVariablesShouldReturnAzureAppService.

@Test
void getActiveWhenHasAllAzureEnvVariablesShouldReturnAzureAppService() {
    Map<String, Object> envVars = new HashMap<>();
    envVars.put("WEBSITE_SITE_NAME", "---");
    envVars.put("WEBSITE_INSTANCE_ID", "1234");
    envVars.put("WEBSITE_RESOURCE_GROUP", "test");
    envVars.put("WEBSITE_SKU", "1234");
    Environment environment = getEnvironmentWithEnvVariables(envVars);
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE);
    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)

Example 43 with Environment

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

the class AbstractSessionCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("Session Condition");
    Environment environment = context.getEnvironment();
    StoreType required = SessionStoreMappings.getType(this.webApplicationType, ((AnnotationMetadata) metadata).getClassName());
    if (!environment.containsProperty("spring.session.store-type")) {
        return ConditionOutcome.match(message.didNotFind("property", "properties").items(ConditionMessage.Style.QUOTE, "spring.session.store-type"));
    }
    try {
        Binder binder = Binder.get(environment);
        return binder.bind("spring.session.store-type", StoreType.class).map((t) -> new ConditionOutcome(t == required, message.found("spring.session.store-type property").items(t))).orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("spring.session.store-type property").atAll()));
    } catch (BindException ex) {
        return ConditionOutcome.noMatch(message.found("invalid spring.session.store-type property").atAll());
    }
}
Also used : ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome) ConditionContext(org.springframework.context.annotation.ConditionContext) BindException(org.springframework.boot.context.properties.bind.BindException) Environment(org.springframework.core.env.Environment) WebApplicationType(org.springframework.boot.WebApplicationType) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata) Binder(org.springframework.boot.context.properties.bind.Binder) AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata) ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) SpringBootCondition(org.springframework.boot.autoconfigure.condition.SpringBootCondition) Binder(org.springframework.boot.context.properties.bind.Binder) ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) Environment(org.springframework.core.env.Environment) BindException(org.springframework.boot.context.properties.bind.BindException) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 44 with Environment

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

the class KeyValueCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("Public Key Value Condition");
    Environment environment = context.getEnvironment();
    String publicKeyLocation = environment.getProperty("spring.security.oauth2.resourceserver.jwt.public-key-location");
    if (!StringUtils.hasText(publicKeyLocation)) {
        return ConditionOutcome.noMatch(message.didNotFind("public-key-location property").atAll());
    }
    String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
    String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
    if (StringUtils.hasText(jwkSetUri)) {
        return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
    }
    if (StringUtils.hasText(issuerUri)) {
        return ConditionOutcome.noMatch(message.found("issuer-uri property").items(issuerUri));
    }
    return ConditionOutcome.match(message.foundExactly("public key location property"));
}
Also used : ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) Environment(org.springframework.core.env.Environment)

Example 45 with Environment

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

the class IssuerUriCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("OpenID Connect Issuer URI Condition");
    Environment environment = context.getEnvironment();
    String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
    String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
    if (!StringUtils.hasText(issuerUri)) {
        return ConditionOutcome.noMatch(message.didNotFind("issuer-uri property").atAll());
    }
    if (StringUtils.hasText(jwkSetUri)) {
        return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
    }
    return ConditionOutcome.match(message.foundExactly("issuer-uri property"));
}
Also used : ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) Environment(org.springframework.core.env.Environment)

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