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);
}
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));
}
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));
}
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.");
}
}
}
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.");
}
}
}
Aggregations