Search in sources :

Example 11 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class VerifierDataMapsTest method testSavePatternAndGet.

@Test
public void testSavePatternAndGet() {
    VerifierData data = VerifierReportFactory.newVerifierData();
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    assertNotNull(rule.getName());
    assertEquals("testRule1", rule.getName());
    ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    assertNotNull(pattern.getRulePath());
    assertEquals(rule.getPath(), pattern.getRulePath());
    assertNotNull(pattern.getName());
    assertEquals(rule.getName(), pattern.getRuleName());
    pattern.setObjectTypePath(objectType.getPath());
    assertNotNull(pattern.getObjectTypePath());
    assertEquals(objectType.getPath(), pattern.getObjectTypePath());
    data.add(rule);
    data.add(objectType);
    data.add(pattern);
    Collection<VerifierComponent> all = data.getAll();
    assertEquals(3, all.size());
    assertTrue(all.contains(pattern));
    assertTrue(all.contains(objectType));
    assertTrue(all.contains(rule));
    Collection<VerifierComponent> components = data.getAll(pattern.getVerifierComponentType());
    assertEquals(1, components.size());
    assertEquals(pattern, components.toArray()[0]);
    VerifierComponent objectType2 = data.getVerifierObject(objectType.getVerifierComponentType(), objectType.getPath());
    assertNotNull(objectType2);
    assertEquals(objectType, objectType2);
    VerifierComponent rule2 = data.getVerifierObject(rule.getVerifierComponentType(), rule.getPath());
    assertNotNull(rule2);
    assertEquals(rule, rule2);
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) VerifierRule(org.drools.verifier.components.VerifierRule) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 12 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllComponentTypes.

@Test
public void testSaveVerifierComponentAndGetForAllComponentTypes() {
    RulePackage rulePackage = VerifierComponentMockFactory.createPackage1();
    saveVerifierComponentAndGet(rulePackage);
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    saveVerifierComponentAndGet(rule);
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(pattern);
    saveVerifierComponentAndGet(new InlineEvalDescr(pattern));
    saveVerifierComponentAndGet(new ObjectType(new PackageDescr("testPackage1")));
    saveVerifierComponentAndGet(new RuleOperatorDescr(new AndDescr(), rule, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new PatternOperatorDescr(pattern, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new SubPattern(pattern, 0));
    saveVerifierComponentAndGet(new ReturnValueFieldDescr(pattern));
    saveVerifierComponentAndGet(new SubRule(rule, 0));
    saveVerifierComponentAndGet(new TextConsequence(rule));
    saveVerifierComponentAndGet(new PatternVariable(rule));
    saveVerifierComponentAndGet(new VerifierAccessorDescr(rule));
    saveVerifierComponentAndGet(new VerifierAccumulateDescr(pattern));
    saveVerifierComponentAndGet(new VerifierCollectDescr(pattern));
    saveVerifierComponentAndGet(new RuleEval(rule));
    saveVerifierComponentAndGet(new VerifierFieldAccessDescr(rule));
    saveVerifierComponentAndGet(new VerifierFromDescr(pattern));
    saveVerifierComponentAndGet(new VerifierMethodAccessDescr(rule));
    saveVerifierComponentAndGet(new PatternEval(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) TextConsequence(org.drools.verifier.components.TextConsequence) PatternVariable(org.drools.verifier.components.PatternVariable) VerifierMethodAccessDescr(org.drools.verifier.components.VerifierMethodAccessDescr) ReturnValueFieldDescr(org.drools.verifier.components.ReturnValueFieldDescr) SubRule(org.drools.verifier.components.SubRule) VerifierFieldAccessDescr(org.drools.verifier.components.VerifierFieldAccessDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) VerifierAccumulateDescr(org.drools.verifier.components.VerifierAccumulateDescr) VerifierRule(org.drools.verifier.components.VerifierRule) VerifierFromDescr(org.drools.verifier.components.VerifierFromDescr) SubPattern(org.drools.verifier.components.SubPattern) RuleEval(org.drools.verifier.components.RuleEval) RulePackage(org.drools.verifier.components.RulePackage) PatternEval(org.drools.verifier.components.PatternEval) ObjectType(org.drools.verifier.components.ObjectType) PatternOperatorDescr(org.drools.verifier.components.PatternOperatorDescr) RuleOperatorDescr(org.drools.verifier.components.RuleOperatorDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierCollectDescr(org.drools.verifier.components.VerifierCollectDescr) VerifierAccessorDescr(org.drools.verifier.components.VerifierAccessorDescr) InlineEvalDescr(org.drools.verifier.components.InlineEvalDescr) Test(org.junit.Test)

Example 13 with VerifierRule

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

Example 14 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesGreater.

@Test
public void testIncoherentPatternsInSubRuleRangesGreater() 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 greater value"));
    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 9"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 14"));
    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 15 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualOrUnequal.

@Test
public void testIncoherentPatternsInSubRuleRangesEqualOrUnequal() 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 or unequal value"));
    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 10"));
    assertTrue(rulesThatHadErrors.remove("Incoherent patterns 15"));
    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

VerifierRule (org.drools.verifier.components.VerifierRule)20 Test (org.junit.Test)15 VerifierReport (org.drools.verifier.data.VerifierReport)11 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)10 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)10 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)10 KieSession (org.kie.api.runtime.KieSession)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)5 ObjectType (org.drools.verifier.components.ObjectType)5 Pattern (org.drools.verifier.components.Pattern)5 SubPattern (org.drools.verifier.components.SubPattern)5 SubRule (org.drools.verifier.components.SubRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Restriction (org.drools.verifier.components.Restriction)3 Field (org.drools.verifier.components.Field)2 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)2 RulePackage (org.drools.verifier.components.RulePackage)2 VerifierData (org.drools.verifier.data.VerifierData)2 AlwaysTrue (org.drools.verifier.report.components.AlwaysTrue)2