Search in sources :

Example 16 with VerifierMessage

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

the class MissingEqualityTest method testMissingEqualityInVariableRestrictions.

@Test
public void testMissingEqualityInVariableRestrictions() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in VariableRestrictions, equal operator"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> ruleNames = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Cause cause = ((VerifierMessage) o).getFaulty();
            String name = ((VariableRestriction) cause).getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Missing equality 5"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VariableRestriction(org.drools.verifier.components.VariableRestriction) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 17 with VerifierMessage

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

the class MissingEqualityTest method testMissingEqualityInVariableRestrictions3.

@Test
public void testMissingEqualityInVariableRestrictions3() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in VariableRestrictions, custom operator"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Set<String> ruleNames = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Cause cause = ((VerifierMessage) o).getFaulty();
            String name = ((VariableRestriction) cause).getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Missing equality 3"));
    assertTrue(ruleNames.remove("Missing equality 4"));
    assertTrue(ruleNames.remove("Missing equality 6"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VariableRestriction(org.drools.verifier.components.VariableRestriction) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 18 with VerifierMessage

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

the class PatternOrderTest method testEvalOrderInsideOperator.

@Test
public void testEvalOrderInsideOperator() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("PatternOrder.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationPatternOrderTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise evals inside pattern"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.NOTE).iterator();
    Collection<String> ruleNames = new ArrayList<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            String name = ((VerifierMessage) o).getCauses().toArray(new RuleComponent[2])[0].getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Wrong eval order 1"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            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) ArrayList(java.util.ArrayList) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 19 with VerifierMessage

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

the class RestrictionOrderTest method testRestrictionOrderInsideOperator.

@Test
public void testRestrictionOrderInsideOperator() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("RestrictionOrder.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationRestrictionOrderTest.drl"), result.getVerifierData());
    // for ( Object object : testData ) {
    // if ( object instanceof SubPattern ) {
    // SubPattern s = (SubPattern) object;
    // System.out.println( " - " + s );
    // for ( PatternComponent o : s.getItems() ) {
    // System.out.println( " -- " + o + " : " + o.getOrderNumber() );
    // }
    // }
    // }
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise restrictions inside operator"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.NOTE).iterator();
    Collection<String> ruleNames = new ArrayList<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            String name = ((VerifierMessage) o).getCauses().toArray(new Restriction[2])[0].getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Wrong descr order 1"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            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) ArrayList(java.util.ArrayList) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 20 with VerifierMessage

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

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleVariables.

@Test
public void testIncoherentPatternsInSubRuleVariables() 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, 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 3"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 4"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 5"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 6"));
    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