Search in sources :

Example 56 with RuleNameMatchesAgendaFilter

use of org.drools.core.base.RuleNameMatchesAgendaFilter 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 57 with RuleNameMatchesAgendaFilter

use of org.drools.core.base.RuleNameMatchesAgendaFilter 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 58 with RuleNameMatchesAgendaFilter

use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.

the class IncompatibilityPatternsTest method testPatternsPossibilitiesIncompatibility.

@Test
public void testPatternsPossibilitiesIncompatibility() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
    Collection<Object> data = new ArrayList<Object>();
    Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
    Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
    /*
         * Working pair
         */
    SubPattern pp1 = new SubPattern(pattern1, 0);
    SubPattern pp2 = new SubPattern(pattern2, 0);
    Restriction r1 = LiteralRestriction.createRestriction(pattern1, "");
    pp1.add(r1);
    Restriction r2 = LiteralRestriction.createRestriction(pattern2, "");
    pp2.add(r2);
    Restriction r3 = LiteralRestriction.createRestriction(pattern1, "");
    pp1.add(r3);
    Restriction r4 = LiteralRestriction.createRestriction(pattern2, "");
    pp2.add(r4);
    Incompatibility o1 = new Incompatibility(r1, r2);
    Incompatibility o2 = new Incompatibility(r3, r4);
    Pattern pattern3 = VerifierComponentMockFactory.createPattern(3);
    Pattern pattern4 = VerifierComponentMockFactory.createPattern(4);
    /*
         * Another working pair.
         */
    SubPattern pp3 = new SubPattern(pattern3, 0);
    SubPattern pp4 = new SubPattern(pattern4, 0);
    Restriction r5 = LiteralRestriction.createRestriction(pattern3, "");
    pp3.add(r5);
    Restriction r6 = LiteralRestriction.createRestriction(pattern4, "");
    pp4.add(r6);
    Restriction r7 = LiteralRestriction.createRestriction(pattern3, "");
    pp3.add(r7);
    Restriction r8 = LiteralRestriction.createRestriction(pattern4, "");
    pp4.add(r8);
    Incompatibility o3 = new Incompatibility(r5, r6);
    data.add(r1);
    data.add(r2);
    data.add(r3);
    data.add(r4);
    data.add(r5);
    data.add(r6);
    data.add(r7);
    data.add(r8);
    data.add(pp1);
    data.add(pp2);
    data.add(pp3);
    data.add(pp4);
    data.add(o1);
    data.add(o2);
    data.add(o3);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible Patterns"));
    Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.SUB_PATTERN, (Iterator<Object>) session.getObjects().iterator());
    assertTrue((TestBaseOld.causeMapContains(map, pp1, pp2) ^ TestBaseOld.causeMapContains(map, pp2, pp1)));
    assertTrue((TestBaseOld.causeMapContains(map, pp3, pp4) ^ TestBaseOld.causeMapContains(map, pp4, pp3)));
    if (!map.isEmpty()) {
        fail("More opposites than was expected.");
    }
}
Also used : Incompatibility(org.drools.verifier.report.components.Incompatibility) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Set(java.util.Set) Cause(org.drools.verifier.report.components.Cause) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)58 Test (org.junit.Test)58 KieSession (org.kie.api.runtime.KieSession)56 VerifierReport (org.drools.verifier.data.VerifierReport)45 HashSet (java.util.HashSet)29 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)27 ArrayList (java.util.ArrayList)25 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)25 Pattern (org.drools.verifier.components.Pattern)17 Cause (org.drools.verifier.report.components.Cause)17 VerifierRule (org.drools.verifier.components.VerifierRule)12 Gap (org.drools.verifier.report.components.Gap)12 Set (java.util.Set)11 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)8 VariableRestriction (org.drools.verifier.components.VariableRestriction)5 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)4 InputStream (java.io.InputStream)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 List (java.util.List)2