Search in sources :

Example 1 with Redundancy

use of org.drools.verifier.report.components.Redundancy 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 2 with Redundancy

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

ArrayList (java.util.ArrayList)2 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)2 VerifierReport (org.drools.verifier.data.VerifierReport)2 Cause (org.drools.verifier.report.components.Cause)2 Redundancy (org.drools.verifier.report.components.Redundancy)2 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2