Search in sources :

Example 6 with VerifierMessage

use of org.drools.verifier.report.components.VerifierMessage in project drools by kiegroup.

the class AlwaysTrueRuleTest method testPatterns.

@Test
public void testPatterns() 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 is always true.
    VerifierRule rule1 = VerifierComponentMockFactory.createRule1();
    SubRule rp1 = new SubRule(rule1, 0);
    AlwaysTrue alwaysTrue1 = new AlwaysTrue(rp1);
    SubRule rp2 = new SubRule(rule1, 1);
    AlwaysTrue alwaysTrue2 = new AlwaysTrue(rp2);
    // This rule is okay.
    VerifierRule rule2 = VerifierComponentMockFactory.createRule2();
    SubRule rp3 = new SubRule(rule2, 0);
    SubRule rp4 = new SubRule(rule2, 1);
    AlwaysTrue alwaysTrue4 = new AlwaysTrue(rp4);
    data.add(rule1);
    data.add(rp1);
    data.add(rp2);
    data.add(alwaysTrue1);
    data.add(alwaysTrue2);
    data.add(rule2);
    data.add(rp3);
    data.add(rp4);
    data.add(alwaysTrue4);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Rule that is always true"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).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(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(1, result.getBySeverity(Severity.WARNING).size());
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
    assertTrue(works);
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) SubRule(org.drools.verifier.components.SubRule) ArrayList(java.util.ArrayList) VerifierRule(org.drools.verifier.components.VerifierRule) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierReport(org.drools.verifier.data.VerifierReport) KieSession(org.kie.api.runtime.KieSession) AlwaysTrue(org.drools.verifier.report.components.AlwaysTrue) Test(org.junit.Test)

Example 7 with VerifierMessage

use of org.drools.verifier.report.components.VerifierMessage in project drools by kiegroup.

the class ConsequenceTest method testMissingConsequence.

@Test
public void testMissingConsequence() throws Exception {
    InputStream in = getClass().getResourceAsStream("Consequence.drl");
    KieSession session = getStatelessKieSession(in);
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("ConsequenceTest2.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("No action - possibly commented out"));
    Iterator<VerifierMessageBase> iterator = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        if (o instanceof VerifierMessage) {
            VerifierMessage message = (VerifierMessage) o;
            rulesThatHadErrors.addAll(message.getImpactedRules().values());
        }
    }
    assertFalse(rulesThatHadErrors.contains("Has a consequence 1"));
    assertTrue(rulesThatHadErrors.remove("Missing consequence 1"));
    assertTrue(rulesThatHadErrors.remove("Missing consequence 2"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) InputStream(java.io.InputStream) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with VerifierMessage

use of org.drools.verifier.report.components.VerifierMessage in project drools by kiegroup.

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables.

@Test
public void testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility, ranges when not conflicts with equal or unequal variables"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof VerifierMessage) {
            VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(rule.getName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 11"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with VerifierMessage

use of org.drools.verifier.report.components.VerifierMessage in project drools by kiegroup.

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesLess.

@Test
public void testIncoherentPatternsInSubRuleRangesLess() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility, ranges when not conflicts with lesser value"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof VerifierMessage) {
            VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(rule.getName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 8"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 12"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with VerifierMessage

use of org.drools.verifier.report.components.VerifierMessage in project drools by kiegroup.

the class IncoherentPatternsTest method testIncoherentPatternsInSubRule.

@Test
public void testIncoherentPatternsInSubRule() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof VerifierMessage) {
            VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(rule.getName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 1"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 2"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 7"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VerifierReport (org.drools.verifier.data.VerifierReport)26 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)26 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)26 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)25 Test (org.junit.Test)25 KieSession (org.kie.api.runtime.KieSession)25 HashSet (java.util.HashSet)17 VerifierRule (org.drools.verifier.components.VerifierRule)10 Pattern (org.drools.verifier.components.Pattern)7 ArrayList (java.util.ArrayList)5 Cause (org.drools.verifier.report.components.Cause)5 VariableRestriction (org.drools.verifier.components.VariableRestriction)3 InputStream (java.io.InputStream)2 FileOutputStream (java.io.FileOutputStream)1 Iterator (java.util.Iterator)1 Field (org.drools.verifier.components.Field)1 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)1 ObjectType (org.drools.verifier.components.ObjectType)1 SubRule (org.drools.verifier.components.SubRule)1 VerifierReportWriter (org.drools.verifier.report.VerifierReportWriter)1