Search in sources :

Example 36 with VerifierReport

use of org.drools.verifier.data.VerifierReport 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 37 with VerifierReport

use of org.drools.verifier.data.VerifierReport 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 38 with VerifierReport

use of org.drools.verifier.data.VerifierReport 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 39 with VerifierReport

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

the class NotesTest method testRedundantRestrictionsInPatternPossibilities.

@Test
public void testRedundantRestrictionsInPatternPossibilities() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    Collection<Object> objects = new ArrayList<Object>();
    LiteralRestriction left = LiteralRestriction.createRestriction(pattern, "");
    LiteralRestriction right = LiteralRestriction.createRestriction(pattern, "");
    Redundancy redundancy = new Redundancy(left, right);
    SubPattern possibility = new SubPattern(pattern, 0);
    possibility.add(left);
    possibility.add(right);
    objects.add(left);
    objects.add(right);
    objects.add(redundancy);
    objects.add(possibility);
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    session.setGlobal("result", result);
    for (Object o : objects) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant restrictions from pattern possibilities"));
    Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
    // Has at least one item.
    assertEquals(1, notes.size());
    VerifierMessageBase note = notes.iterator().next();
    Iterator<Cause> causes = note.getCauses().iterator();
    assertEquals(left, causes.next());
    assertEquals(right, causes.next());
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Redundancy(org.drools.verifier.report.components.Redundancy) ArrayList(java.util.ArrayList) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 40 with VerifierReport

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

the class NotesTest method testRedundantPatternPossibilitiesInRulePossibilities.

@Test
public void testRedundantPatternPossibilitiesInRulePossibilities() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    Collection<Object> objects = new ArrayList<Object>();
    SubPattern left = new SubPattern(pattern, 0);
    SubPattern right = new SubPattern(pattern, 1);
    Redundancy redundancy = new Redundancy(left, right);
    SubRule possibility = new SubRule(rule, 0);
    possibility.add(left);
    possibility.add(right);
    objects.add(left);
    objects.add(right);
    objects.add(redundancy);
    objects.add(possibility);
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    session.setGlobal("result", result);
    for (Object o : objects) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant pattern possibilities from rule possibilities"));
    Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
    // Has at least one item.
    assertEquals(1, notes.size());
    VerifierMessageBase note = notes.iterator().next();
    Iterator<Cause> causes = note.getCauses().iterator();
    assertEquals(left, causes.next());
    assertEquals(right, causes.next());
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Redundancy(org.drools.verifier.report.components.Redundancy) ArrayList(java.util.ArrayList) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) 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