Search in sources :

Example 1 with AnnotatedTypeMetadata

use of org.springframework.core.type.AnnotatedTypeMetadata in project spring-boot by spring-projects.

the class ConditionalOnExpressionTests method mockMetaData.

private AnnotatedTypeMetadata mockMetaData(String value) {
    AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
    given(metadata.getAnnotationAttributes(ConditionalOnExpression.class.getName())).willReturn(Collections.singletonMap("value", value));
    return metadata;
}
Also used : AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata)

Example 2 with AnnotatedTypeMetadata

use of org.springframework.core.type.AnnotatedTypeMetadata in project spring-boot by spring-projects.

the class ConditionalOnJndiTests method mockMetaData.

private AnnotatedTypeMetadata mockMetaData(String... value) {
    AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("value", value);
    given(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName())).willReturn(attributes);
    return metadata;
}
Also used : HashMap(java.util.HashMap) AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata)

Example 3 with AnnotatedTypeMetadata

use of org.springframework.core.type.AnnotatedTypeMetadata 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 4 with AnnotatedTypeMetadata

use of org.springframework.core.type.AnnotatedTypeMetadata in project spring-boot-admin by codecentric.

the class SpringBootAdminClientEnabledConditionTest method setUp.

@Before
public void setUp() {
    condition = new SpringBootAdminClientEnabledCondition();
    annotatedTypeMetadata = mock(AnnotatedTypeMetadata.class);
    conditionContext = mock(ConditionContext.class);
}
Also used : ConditionContext(org.springframework.context.annotation.ConditionContext) SpringBootAdminClientEnabledCondition(de.codecentric.boot.admin.client.config.SpringBootAdminClientEnabledCondition) AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata) Before(org.junit.Before)

Aggregations

AnnotatedTypeMetadata (org.springframework.core.type.AnnotatedTypeMetadata)4 ConditionContext (org.springframework.context.annotation.ConditionContext)2 SpringBootAdminClientEnabledCondition (de.codecentric.boot.admin.client.config.SpringBootAdminClientEnabledCondition)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 WebApplicationType (org.springframework.boot.WebApplicationType)1 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)1 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)1 SpringBootCondition (org.springframework.boot.autoconfigure.condition.SpringBootCondition)1 BindException (org.springframework.boot.context.properties.bind.BindException)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 Environment (org.springframework.core.env.Environment)1 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)1