Search in sources :

Example 1 with ConditionOutcome

use of org.springframework.boot.autoconfigure.condition.ConditionOutcome in project spring-boot by spring-projects.

the class LocalDebugPortAvailableConditionTests method getOutcome.

private ConditionOutcome getOutcome() {
    MockEnvironment environment = new MockEnvironment();
    EnvironmentTestUtils.addEnvironment(environment, "spring.devtools.remote.debug.local-port:" + this.port);
    ConditionContext context = mock(ConditionContext.class);
    given(context.getEnvironment()).willReturn(environment);
    ConditionOutcome outcome = this.condition.getMatchOutcome(context, null);
    return outcome;
}
Also used : ConditionContext(org.springframework.context.annotation.ConditionContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 2 with ConditionOutcome

use of org.springframework.boot.autoconfigure.condition.ConditionOutcome in project spring-boot by spring-projects.

the class LocalDebugPortAvailableConditionTests method portInUse.

@Test
public void portInUse() throws Exception {
    final ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(this.port);
    ConditionOutcome outcome = getOutcome();
    serverSocket.close();
    assertThat(outcome.isMatch()).isFalse();
    assertThat(outcome.getMessage()).isEqualTo("Local Debug Port Condition did not find local debug port");
}
Also used : ServerSocket(java.net.ServerSocket) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome) Test(org.junit.Test)

Example 3 with ConditionOutcome

use of org.springframework.boot.autoconfigure.condition.ConditionOutcome in project spring-boot by spring-projects.

the class LocalDebugPortAvailableConditionTests method portAvailable.

@Test
public void portAvailable() throws Exception {
    ConditionOutcome outcome = getOutcome();
    assertThat(outcome.isMatch()).isTrue();
    assertThat(outcome.getMessage()).isEqualTo("Local Debug Port Condition found local debug port");
}
Also used : ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome) Test(org.junit.Test)

Example 4 with ConditionOutcome

use of org.springframework.boot.autoconfigure.condition.ConditionOutcome in project spring-boot by spring-projects.

the class OnEnabledEndpointElementCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(this.annotationType.getName()));
    String endpointName = annotationAttributes.getString("value");
    ConditionOutcome outcome = getEndpointOutcome(context, endpointName);
    if (outcome != null) {
        return outcome;
    }
    return getDefaultEndpointsOutcome(context);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 5 with ConditionOutcome

use of org.springframework.boot.autoconfigure.condition.ConditionOutcome in project spring-boot by spring-projects.

the class OnEnabledEndpointCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()));
    String endpointName = annotationAttributes.getString("value");
    boolean enabledByDefault = annotationAttributes.getBoolean("enabledByDefault");
    ConditionOutcome outcome = determineEndpointOutcome(endpointName, enabledByDefault, context);
    if (outcome != null) {
        return outcome;
    }
    return determineAllEndpointsOutcome(context);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Aggregations

ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)9 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)3 Test (org.junit.Test)2 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)2 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)2 ServerSocket (java.net.ServerSocket)1 ConditionContext (org.springframework.context.annotation.ConditionContext)1 MethodMetadata (org.springframework.core.type.MethodMetadata)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1