Search in sources :

Example 46 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class VerifierTest method testCustomRule.

@Test
public void testCustomRule() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("FindPatterns.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    if (!works) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
        fail("Could not run verifier");
    }
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(6, result.getBySeverity(Severity.NOTE).size());
    for (VerifierMessageBase m : result.getBySeverity(Severity.NOTE)) {
        assertEquals("This pattern was found.", m.getMessage());
    }
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 47 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class VerifyingScopeTest method testSingleRule.

@Test
public void testSingleRule() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, ScopesAgendaFilter.VERIFYING_SCOPE_SINGLE_RULE));
    if (!works) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
        fail("Error when building in verifier");
    }
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(6, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 48 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class VerifyingScopeTest method testNothing.

@Test
public void testNothing() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, Collections.EMPTY_LIST));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(2, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 49 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class VerifyingScopeTest method testDecisionTable.

@Test
public void testDecisionTable() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(false, ScopesAgendaFilter.VERIFYING_SCOPE_DECISION_TABLE));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(2, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 50 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class AlwaysFalseTest method testRules.

@Test
public void testRules() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Rules.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<Object> data = new ArrayList<Object>();
    session.setGlobal("result", result);
    // This rule has an error.
    VerifierRule rule1 = VerifierComponentMockFactory.createRule1();
    Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
    SubPattern pp1 = new SubPattern(pattern1, 0);
    SubPattern pp2 = new SubPattern(pattern1, 1);
    Incompatibility i1 = new Incompatibility(pp1, pp2);
    SubRule rp1 = new SubRule(rule1, 0);
    rp1.add(pp1);
    rp1.add(pp2);
    SubPattern pp3 = new SubPattern(pattern1, 2);
    SubPattern pp4 = new SubPattern(pattern1, 3);
    Incompatibility i2 = new Incompatibility(pp1, pp2);
    SubRule rp2 = new SubRule(rule1, 1);
    rp2.add(pp1);
    rp2.add(pp2);
    // This pattern does not have an error.
    VerifierRule rule2 = VerifierComponentMockFactory.createRule2();
    Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
    SubPattern pp5 = new SubPattern(pattern2, 0);
    SubPattern pp6 = new SubPattern(pattern2, 1);
    SubRule rp3 = new SubRule(rule2, 2);
    rp3.add(pp5);
    rp3.add(pp6);
    SubPattern pp7 = new SubPattern(pattern2, 2);
    SubPattern pp8 = new SubPattern(pattern2, 3);
    Incompatibility i4 = new Incompatibility(pp7, pp8);
    SubRule rp4 = new SubRule(rule2, 3);
    rp4.add(pp7);
    rp4.add(pp8);
    data.add(rule1);
    data.add(pp1);
    data.add(pp2);
    data.add(pp3);
    data.add(pp4);
    data.add(i1);
    data.add(i2);
    data.add(rp1);
    data.add(rp2);
    data.add(rule2);
    data.add(pp5);
    data.add(pp6);
    data.add(pp7);
    data.add(pp8);
    data.add(i4);
    data.add(rp3);
    data.add(rp4);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Rule that is always false"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.ERROR).iterator();
    boolean works = false;
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            VerifierMessage message = (VerifierMessage) o;
            if (message.getFaulty().equals(rule1)) {
                works = true;
            } else {
                fail("There can be only one. (And this is not the one)");
            }
        }
    }
    assertEquals(1, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
    assertTrue(works);
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) ArrayList(java.util.ArrayList) VerifierReport(org.drools.verifier.data.VerifierReport) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

VerifierReport (org.drools.verifier.data.VerifierReport)60 Test (org.junit.Test)59 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)45 KieSession (org.kie.api.runtime.KieSession)45 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)32 HashSet (java.util.HashSet)29 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)26 ArrayList (java.util.ArrayList)14 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)13 Gap (org.drools.verifier.report.components.Gap)12 VerifierRule (org.drools.verifier.components.VerifierRule)11 ClassPathResource (org.drools.core.io.impl.ClassPathResource)10 Pattern (org.drools.verifier.components.Pattern)8 Cause (org.drools.verifier.report.components.Cause)7 Verifier (org.drools.verifier.Verifier)4 ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)4 Ignore (org.junit.Ignore)4 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)4 Field (org.drools.verifier.components.Field)3 ObjectType (org.drools.verifier.components.ObjectType)3