Search in sources :

Example 26 with VerifierMessage

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

the class IncoherentRestrictionsTest method testIncoherentLiteralRestrictionsInSubPatternImpossibleRanges.

@Test
public void testIncoherentLiteralRestrictionsInSubPatternImpossibleRanges() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("RestrictionsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent LiteralRestrictions with ranges in pattern possibility, impossible ranges"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.ERROR).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Pattern pattern = (Pattern) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(pattern.getRuleName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent restrictions 8"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Pattern(org.drools.verifier.components.Pattern) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) 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