Search in sources :

Example 21 with Pattern

use of org.drools.verifier.components.Pattern 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 22 with Pattern

use of org.drools.verifier.components.Pattern 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 23 with Pattern

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

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllRestrictions.

@Test
public void testSaveVerifierComponentAndGetForAllRestrictions() {
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(LiteralRestriction.createRestriction(pattern, ""));
    saveVerifierComponentAndGet(new EnumRestriction(pattern));
    saveVerifierComponentAndGet(new QualifiedIdentifierRestriction(pattern));
    saveVerifierComponentAndGet(new ReturnValueRestriction(pattern));
    saveVerifierComponentAndGet(new ReturnValueRestriction(pattern));
    saveVerifierComponentAndGet(new VariableRestriction(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) VariableRestriction(org.drools.verifier.components.VariableRestriction) EnumRestriction(org.drools.verifier.components.EnumRestriction) ReturnValueRestriction(org.drools.verifier.components.ReturnValueRestriction) QualifiedIdentifierRestriction(org.drools.verifier.components.QualifiedIdentifierRestriction) Test(org.junit.Test)

Example 24 with Pattern

use of org.drools.verifier.components.Pattern 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 25 with Pattern

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

Aggregations

Pattern (org.drools.verifier.components.Pattern)25 Test (org.junit.Test)22 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)10 Set (java.util.Set)8 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)8 VerifierReport (org.drools.verifier.data.VerifierReport)8 KieSession (org.kie.api.runtime.KieSession)8 HashSet (java.util.HashSet)7 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)7 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)7 SubPattern (org.drools.verifier.components.SubPattern)6 VerifierRule (org.drools.verifier.components.VerifierRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 SubRule (org.drools.verifier.components.SubRule)4 ArrayList (java.util.ArrayList)3 Restriction (org.drools.verifier.components.Restriction)3 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)2 ObjectType (org.drools.verifier.components.ObjectType)2 PatternVariable (org.drools.verifier.components.PatternVariable)2 RulePackage (org.drools.verifier.components.RulePackage)2