use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualValue.
@Test
public void testIncoherentPatternsInSubRuleRangesEqualValue() 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 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 16"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualVariable.
@Test
public void testIncoherentPatternsInSubRuleRangesEqualVariable() 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 variable"));
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 13"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.data.VerifierReport 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.data.VerifierReport in project drools by kiegroup.
the class IncoherentRestrictionsTest method testApprovedTrueAndNotTrue.
@Test
public void testApprovedTrueAndNotTrue() {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Check that the builder works.
assertFalse(vBuilder.hasErrors());
assertEquals(0, vBuilder.getErrors().size());
String str = "";
str += "package mortgages\n";
str += "rule \"Bankruptcy history\"\n";
str += "salience 10\n";
str += "dialect \"mvel\"\n";
str += "when\n";
str += "Applicant( approved == \"true\" , approved != \"true\" )\n";
str += "then\n";
str += "end";
DefaultVerifierConfiguration conf = new DefaultVerifierConfiguration();
Verifier verifier = VerifierBuilderFactory.newVerifierBuilder().newVerifier(conf);
verifier.addResourcesToVerify(ResourceFactory.newReaderResource(new StringReader(str)), ResourceType.DRL);
assertFalse(verifier.hasErrors());
assertEquals(0, verifier.getErrors().size());
boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, ScopesAgendaFilter.VERIFYING_SCOPE_KNOWLEDGE_PACKAGE));
assertTrue(works);
VerifierReport result = verifier.getResult();
assertNotNull(result);
assertEquals(3, result.getBySeverity(Severity.ERROR).size());
assertEquals(1, result.getBySeverity(Severity.WARNING).size());
assertEquals(0, result.getBySeverity(Severity.NOTE).size());
}
use of org.drools.verifier.data.VerifierReport 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