use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class RangeCheckIntegersTest method testSmallerOrEqual.
@Test
public void testSmallerOrEqual() 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 smaller 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 4a"));
assertTrue(rulesThatHadErrors.remove("Integer gap rule 5a"));
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 VerifierTest 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("Misc3.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);
assertEquals(0, result.getBySeverity(Severity.ERROR).size());
assertEquals(6, result.getBySeverity(Severity.WARNING).size());
assertEquals(1, result.getBySeverity(Severity.NOTE).size());
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class VerifierTest method testFactTypesFromJar.
@Test
public void testFactTypesFromJar() {
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("imports.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);
assertNotNull(objectTypes);
assertEquals(3, objectTypes.size());
Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
assertNotNull(fields);
assertEquals(10, fields.size());
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class VerifierTestStandalone method main.
public static final void main(String[] args) {
try {
Collection<String> fileNames = new ArrayList<String>();
// Test data
// fileNames.add("MissingRangesForDates.drl");
// fileNames.add("MissingRangesForDoubles.drl");
// fileNames.add("MissingRangesForInts.drl");
// fileNames.add("MissingRangesForVariables.drl");
// fileNames.add("Misc.drl");
// fileNames.add("Misc2.drl");
// fileNames.add("Misc3.drl");
fileNames.add("Enums.drl");
// fileNames.add("ConsequenceTest.drl");
// fileNames.add("optimisation/OptimisationRestrictionOrderTest.drl");
// fileNames.add("optimisation/OptimisationPatternOrderTest.drl");
Verifier verifier = VerifierBuilderFactory.newVerifierBuilder().newVerifier();
for (String s : fileNames) {
verifier.addResourcesToVerify(ResourceFactory.newClassPathResource(s, Verifier.class), ResourceType.DRL);
}
verifier.fireAnalysis();
// System.out.print(a.getResultAsPlainText());
// System.out.print(a.getResultAsXML());
// a.writeComponentsHTML("/stash/");
// a.writeComponentsHTML("/Users/michaelneale/foo.html");
// a.writeComponentsHTML("/home/trikkola/");
// a.writeComponentsHTML("c:/");
VerifierReport result = verifier.getResult();
VerifierReportWriter reportwriter = VerifierReportWriterFactory.newHTMLReportWriter();
FileOutputStream out = new FileOutputStream("/Users/rikkola/Desktop/testReport.zip");
reportwriter.writeReport(out, result);
Collection<VerifierMessageBase> msgs = result.getBySeverity(Severity.ERROR);
for (Iterator iterator = msgs.iterator(); iterator.hasNext(); ) {
VerifierMessageBase msg = (VerifierMessageBase) iterator.next();
System.out.println("ERR: " + msg.getMessage());
}
msgs = result.getBySeverity(Severity.WARNING);
for (Iterator iterator = msgs.iterator(); iterator.hasNext(); ) {
VerifierMessageBase msg = (VerifierMessageBase) iterator.next();
System.out.println("WARN (" + msg.getClass().getSimpleName() + "): " + msg.getMessage());
System.out.println("\t FAULT: [" + msg.getClass().getSimpleName() + "] " + msg.getFaulty());
if (msg instanceof VerifierMessage) {
System.out.println("\t CAUSES (message):");
VerifierMessage amsg = (VerifierMessage) msg;
for (Iterator iterator2 = amsg.getCauses().iterator(); iterator2.hasNext(); ) {
Cause c = (Cause) iterator2.next();
System.out.println("\t\t [" + c.getClass().getSimpleName() + "]" + c);
}
} else if (msg instanceof VerifierRangeCheckMessage) {
System.out.println("\t CAUSES (range):");
VerifierRangeCheckMessage amsg = (VerifierRangeCheckMessage) msg;
for (Iterator iterator2 = amsg.getCauses().iterator(); iterator2.hasNext(); ) {
Cause c = (Cause) iterator2.next();
System.out.println("\t\t" + c);
}
}
}
msgs = result.getBySeverity(Severity.NOTE);
for (Iterator iterator = msgs.iterator(); iterator.hasNext(); ) {
VerifierMessageBase msg = (VerifierMessageBase) iterator.next();
System.out.println("NOTE: " + msg.getMessage());
System.out.println("\t" + msg.getFaulty());
}
Collection<ObjectType> classes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
for (Iterator iterator = classes.iterator(); iterator.hasNext(); ) {
ObjectType c = (ObjectType) iterator.next();
Collection<VerifierRule> cr = result.getVerifierData().getRulesByObjectTypePath(c.getPath());
System.err.println("Class rules:" + cr);
Set<Field> flds = c.getFields();
for (Iterator iterator2 = flds.iterator(); iterator2.hasNext(); ) {
Field f = (Field) iterator2.next();
cr = result.getVerifierData().getRulesByFieldPath(f.getPath());
System.err.println("Field rules: " + cr);
}
}
// System.err.println(a.getResultAsPlainText());
// System.out.println(result.toString());
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class AlwaysFalseTest method testPatterns.
@Test
public void testPatterns() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<Object> data = new ArrayList<Object>();
session.setGlobal("result", result);
// This pattern has an error.
Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
Restriction r1 = LiteralRestriction.createRestriction(pattern1, "");
Restriction r2 = LiteralRestriction.createRestriction(pattern1, "");
Incompatibility i1 = new Incompatibility(r1, r2);
SubPattern pp1 = new SubPattern(pattern1, 0);
pp1.add(r1);
pp1.add(r2);
Restriction r3 = new VariableRestriction(pattern1);
Restriction r4 = new VariableRestriction(pattern1);
Incompatibility i2 = new Incompatibility(r1, r2);
SubPattern pp2 = new SubPattern(pattern1, 1);
pp2.add(r1);
pp2.add(r2);
// This pattern does not have an error.
Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
Restriction r5 = LiteralRestriction.createRestriction(pattern2, "");
Restriction r6 = LiteralRestriction.createRestriction(pattern2, "");
SubPattern pp3 = new SubPattern(pattern2, 0);
pp3.add(r5);
pp3.add(r6);
Restriction r7 = new VariableRestriction(pattern2);
Restriction r8 = new VariableRestriction(pattern2);
Incompatibility i4 = new Incompatibility(r7, r8);
SubPattern pp4 = new SubPattern(pattern2, 1);
pp4.add(r7);
pp4.add(r8);
data.add(VerifierComponentMockFactory.createRule1());
data.add(pattern1);
data.add(r1);
data.add(r2);
data.add(r3);
data.add(r4);
data.add(i1);
data.add(i2);
data.add(pp1);
data.add(pp2);
data.add(pattern2);
data.add(r5);
data.add(r6);
data.add(r7);
data.add(r8);
data.add(i4);
data.add(pp3);
data.add(pp4);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Pattern that is always false"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.ERROR).iterator();
boolean works = false;
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
VerifierMessage message = (VerifierMessage) o;
if (message.getFaulty().equals(pattern1)) {
works = true;
} else {
fail("There can be only one. (And this is not the one)");
}
}
}
assertEquals(1, result.getBySeverity(Severity.ERROR).size());
assertEquals(0, result.getBySeverity(Severity.WARNING).size());
assertEquals(0, result.getBySeverity(Severity.NOTE).size());
assertTrue(works);
}
Aggregations