Search in sources :

Example 1 with ConditionAndOutcomes

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

the class ConditionEvaluationReportTests method testDuplicateConditionAndOutcomes.

@Test
public void testDuplicateConditionAndOutcomes() {
    ConditionAndOutcome outcome1 = new ConditionAndOutcome(this.condition1, new ConditionOutcome(true, "Message 1"));
    ConditionAndOutcome outcome2 = new ConditionAndOutcome(this.condition2, new ConditionOutcome(true, "Message 2"));
    ConditionAndOutcome outcome3 = new ConditionAndOutcome(this.condition3, new ConditionOutcome(true, "Message 2"));
    assertThat(outcome1).isEqualTo(outcome1);
    assertThat(outcome1).isNotEqualTo(outcome2);
    assertThat(outcome2).isEqualTo(outcome3);
    ConditionAndOutcomes outcomes = new ConditionAndOutcomes();
    outcomes.add(this.condition1, new ConditionOutcome(true, "Message 1"));
    outcomes.add(this.condition2, new ConditionOutcome(true, "Message 2"));
    outcomes.add(this.condition3, new ConditionOutcome(true, "Message 2"));
    assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2);
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) ConditionAndOutcome(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome) Test(org.junit.Test)

Example 2 with ConditionAndOutcomes

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

the class ConditionEvaluationReportTests method recordConditionEvaluations.

@Test
public void recordConditionEvaluations() throws Exception {
    this.outcome1 = new ConditionOutcome(false, "m1");
    this.outcome2 = new ConditionOutcome(false, "m2");
    this.outcome3 = new ConditionOutcome(false, "m3");
    this.report.recordConditionEvaluation("a", this.condition1, this.outcome1);
    this.report.recordConditionEvaluation("a", this.condition2, this.outcome2);
    this.report.recordConditionEvaluation("b", this.condition3, this.outcome3);
    Map<String, ConditionAndOutcomes> map = this.report.getConditionAndOutcomesBySource();
    assertThat(map.size()).isEqualTo(2);
    Iterator<ConditionAndOutcome> iterator = map.get("a").iterator();
    ConditionAndOutcome conditionAndOutcome = iterator.next();
    assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition1);
    assertThat(conditionAndOutcome.getOutcome()).isEqualTo(this.outcome1);
    conditionAndOutcome = iterator.next();
    assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition2);
    assertThat(conditionAndOutcome.getOutcome()).isEqualTo(this.outcome2);
    assertThat(iterator.hasNext()).isFalse();
    iterator = map.get("b").iterator();
    conditionAndOutcome = iterator.next();
    assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition3);
    assertThat(conditionAndOutcome.getOutcome()).isEqualTo(this.outcome3);
    assertThat(iterator.hasNext()).isFalse();
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) ConditionAndOutcome(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with ConditionAndOutcomes

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

the class ConditionEvaluationReportTests method negativeOuterPositiveInnerBean.

@Test
public void negativeOuterPositiveInnerBean() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "test.present=true");
    context.register(NegativeOuterConfig.class);
    context.refresh();
    ConditionEvaluationReport report = ConditionEvaluationReport.get(context.getBeanFactory());
    Map<String, ConditionAndOutcomes> sourceOutcomes = report.getConditionAndOutcomesBySource();
    assertThat(context.containsBean("negativeOuterPositiveInnerBean")).isFalse();
    String negativeConfig = NegativeOuterConfig.class.getName();
    assertThat(sourceOutcomes.get(negativeConfig).isFullMatch()).isFalse();
    String positiveConfig = NegativeOuterConfig.PositiveInnerConfig.class.getName();
    assertThat(sourceOutcomes.get(positiveConfig).isFullMatch()).isFalse();
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with ConditionAndOutcomes

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

the class ConditionEvaluationReportTests method duplicateOutcomes.

@Test
public void duplicateOutcomes() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DuplicateConfig.class);
    ConditionEvaluationReport report = ConditionEvaluationReport.get(context.getBeanFactory());
    String autoconfigKey = MultipartAutoConfiguration.class.getName();
    ConditionAndOutcomes outcomes = report.getConditionAndOutcomesBySource().get(autoconfigKey);
    assertThat(outcomes).isNotEqualTo(nullValue());
    assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2);
    List<String> messages = new ArrayList<>();
    for (ConditionAndOutcome outcome : outcomes) {
        messages.add(outcome.getOutcome().getMessage());
    }
    assertThat(messages).areAtLeastOne(Matched.by(containsString("@ConditionalOnClass found required classes " + "'javax.servlet.Servlet', 'org.springframework.web.multipart." + "support.StandardServletMultipartResolver', " + "'javax.servlet.MultipartConfigElement'")));
    context.close();
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ArrayList(java.util.ArrayList) ConditionAndOutcome(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 5 with ConditionAndOutcomes

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

the class NoSuchBeanDefinitionFailureAnalyzer method collectReportedConditionOutcomes.

private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, List<AutoConfigurationResult> results) {
    for (Map.Entry<String, ConditionAndOutcomes> entry : this.report.getConditionAndOutcomesBySource().entrySet()) {
        Source source = new Source(entry.getKey());
        ConditionAndOutcomes conditionAndOutcomes = entry.getValue();
        if (!conditionAndOutcomes.isFullMatch()) {
            BeanMethods methods = new BeanMethods(source, cause);
            for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
                if (!conditionAndOutcome.getOutcome().isMatch()) {
                    for (MethodMetadata method : methods) {
                        results.add(new AutoConfigurationResult(method, conditionAndOutcome.getOutcome(), source.isMethod()));
                    }
                }
            }
        }
    }
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) ConditionAndOutcome(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome) MethodMetadata(org.springframework.core.type.MethodMetadata) Map(java.util.Map)

Aggregations

ConditionAndOutcomes (org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes)5 Test (org.junit.Test)4 ConditionAndOutcome (org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MethodMetadata (org.springframework.core.type.MethodMetadata)1