use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class RangeCheckDatesTest method testEqualAndSmallerThan.
@Test
public void testEqualAndSmallerThan() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Dates.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDates.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for dates, equal and smaller than"));
Set<String> rulesThatHadErrors = new HashSet<String>();
for (Object o : session.getObjects()) {
if (o instanceof Gap) {
rulesThatHadErrors.add(((Gap) o).getRuleName());
}
// System.out.println(o);
}
assertTrue(rulesThatHadErrors.remove("Date gap rule 1"));
assertTrue(rulesThatHadErrors.remove("Date gap rule 6b"));
assertTrue(rulesThatHadErrors.remove("Date gap rule 2"));
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 RangeCheckDoublesTest method testEqualAndGreaterThan.
@Test
public void testEqualAndGreaterThan() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Doubles.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDoubles.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for doubles, equal and greater than"));
Set<String> rulesThatHadErrors = new HashSet<String>();
for (Object o : session.getObjects()) {
if (o instanceof Gap) {
rulesThatHadErrors.add(((Gap) o).getRuleName());
}
// System.out.println(o);
}
assertTrue(rulesThatHadErrors.remove("Double gap rule 1"));
assertTrue(rulesThatHadErrors.remove("Double gap rule 7b"));
assertTrue(rulesThatHadErrors.remove("Double gap rule 3"));
assertTrue(rulesThatHadErrors.remove("Double gap rule 9b"));
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 RangeCheckIntegersTest method testGreaterOrEqual.
@Test
public void testGreaterOrEqual() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Integers.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForInts.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for integers, if greater than or equal is missing"));
Set<String> rulesThatHadErrors = new HashSet<String>();
for (Object o : session.getObjects()) {
if (o instanceof Gap) {
rulesThatHadErrors.add(((Gap) o).getRuleName());
}
// System.out.println(o);
}
assertTrue(rulesThatHadErrors.remove("Integer gap rule 4b"));
assertTrue(rulesThatHadErrors.remove("Integer gap rule 5b"));
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 RangeCheckTest method testVerifier.
@Test
public void testVerifier() {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Check that the builder works.
assertFalse(vBuilder.hasErrors());
assertEquals(0, vBuilder.getErrors().size());
Verifier verifier = vBuilder.newVerifier();
verifier.addResourcesToVerify(new ClassPathResource("RangeTest.drl", Verifier.class), ResourceType.DRL);
assertFalse(verifier.hasErrors());
assertEquals(0, verifier.getErrors().size());
boolean works = verifier.fireAnalysis();
assertTrue(works);
VerifierReport result = verifier.getResult();
assertNotNull(result);
for (VerifierMessageBase message : result.getBySeverity(Severity.ERROR)) {
System.out.println(message);
}
// This rule should not have errors, evereververevernever!
assertEquals(0, result.getBySeverity(Severity.ERROR).size());
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class VerifierTest method testFactTypesFromJarAndDeclarations.
@Test
public void testFactTypesFromJarAndDeclarations() {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Check that the builder works.
assertFalse(vBuilder.hasErrors());
assertEquals(0, vBuilder.getErrors().size());
Verifier verifier = vBuilder.newVerifier();
try {
JarInputStream jar = new JarInputStream(this.getClass().getResourceAsStream("model.jar"));
verifier.addObjectModel(jar);
} catch (IOException e) {
fail(e.getMessage());
}
verifier.addResourcesToVerify(new ClassPathResource("importsAndDeclarations.drl", Verifier.class), ResourceType.DRL);
assertFalse(verifier.hasErrors());
assertEquals(0, verifier.getErrors().size());
boolean works = verifier.fireAnalysis();
assertTrue(works);
VerifierReport result = verifier.getResult();
Collection<ObjectType> objectTypes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
for (ObjectType objectType : objectTypes) {
if (objectType.getName().equals("VoiceCall")) {
assertEquals(4, objectType.getMetadata().keySet().size());
}
}
assertNotNull(objectTypes);
assertEquals(4, objectTypes.size());
Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
assertNotNull(fields);
assertEquals(11, fields.size());
}
Aggregations