Search in sources :

Example 31 with VerifierMessageBase

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

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualVariable.

@Test
public void testIncoherentPatternsInSubRuleRangesEqualVariable() 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 variable"));
    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 13"));
    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 32 with VerifierMessageBase

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

the class IncoherentRestrictionsTest method testIncoherentLiteralRestrictionsInSubPatternImpossibleEqualityGreater.

@Test
public void testIncoherentLiteralRestrictionsInSubPatternImpossibleEqualityGreater() 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 equality greater"));
    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 10"));
    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)

Example 33 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase 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)

Example 34 with VerifierMessageBase

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

the class PlainTextReportWriter method writeReport.

public void writeReport(OutputStream out, VerifierReport result) throws IOException {
    StringBuffer str = new StringBuffer();
    for (Severity severity : Severity.values()) {
        Collection<VerifierMessageBase> messages = result.getBySeverity(severity);
        str.append("************* ");
        str.append(severity.getTuple());
        str.append(" ");
        str.append(messages.size());
        str.append(" ******************\n");
        for (VerifierMessageBase message : messages) {
            str.append(message);
            str.append("\n");
        }
        str.append("\n");
    }
    out.write(str.toString().getBytes(IoUtils.UTF8_CHARSET));
}
Also used : VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) Severity(org.drools.verifier.report.components.Severity)

Aggregations

VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)34 VerifierReport (org.drools.verifier.data.VerifierReport)32 Test (org.junit.Test)31 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)27 KieSession (org.kie.api.runtime.KieSession)27 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)26 HashSet (java.util.HashSet)17 VerifierRule (org.drools.verifier.components.VerifierRule)10 ArrayList (java.util.ArrayList)8 Pattern (org.drools.verifier.components.Pattern)7 Cause (org.drools.verifier.report.components.Cause)7 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)4 VariableRestriction (org.drools.verifier.components.VariableRestriction)3 InputStream (java.io.InputStream)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 Verifier (org.drools.verifier.Verifier)2 Redundancy (org.drools.verifier.report.components.Redundancy)2 Ignore (org.junit.Ignore)2 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1