use of org.drools.verifier.report.components.VerifierMessageBase 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.report.components.VerifierMessageBase in project drools by kiegroup.
the class NamedConsequencesTest method testMissingConsequence.
@Test
public void testMissingConsequence() throws Exception {
InputStream in = getClass().getResourceAsStream("NamedConsequences.drl");
KieSession session = getStatelessKieSession(in);
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("ConsequenceTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("No action - possibly commented out"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.NOTE).iterator();
Set<String> rulesThatHadErrors = new HashSet<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
VerifierMessage message = (VerifierMessage) o;
rulesThatHadErrors.addAll(message.getImpactedRules().values());
}
}
assertFalse(rulesThatHadErrors.contains("This one is has an unused named consequence"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class AlwaysTrueRuleTest method testPatterns.
@Test
public void testPatterns() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Rules.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<Object> data = new ArrayList<Object>();
session.setGlobal("result", result);
// This rule is always true.
VerifierRule rule1 = VerifierComponentMockFactory.createRule1();
SubRule rp1 = new SubRule(rule1, 0);
AlwaysTrue alwaysTrue1 = new AlwaysTrue(rp1);
SubRule rp2 = new SubRule(rule1, 1);
AlwaysTrue alwaysTrue2 = new AlwaysTrue(rp2);
// This rule is okay.
VerifierRule rule2 = VerifierComponentMockFactory.createRule2();
SubRule rp3 = new SubRule(rule2, 0);
SubRule rp4 = new SubRule(rule2, 1);
AlwaysTrue alwaysTrue4 = new AlwaysTrue(rp4);
data.add(rule1);
data.add(rp1);
data.add(rp2);
data.add(alwaysTrue1);
data.add(alwaysTrue2);
data.add(rule2);
data.add(rp3);
data.add(rp4);
data.add(alwaysTrue4);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Rule that is always true"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
boolean works = false;
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
VerifierMessage message = (VerifierMessage) o;
if (message.getFaulty().equals(rule1)) {
works = true;
} else {
fail("There can be only one. (And this is not the one)");
}
}
}
assertEquals(0, result.getBySeverity(Severity.ERROR).size());
assertEquals(1, result.getBySeverity(Severity.WARNING).size());
assertEquals(0, result.getBySeverity(Severity.NOTE).size());
assertTrue(works);
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class ConsequenceTest method testMissingConsequence.
@Test
public void testMissingConsequence() throws Exception {
InputStream in = getClass().getResourceAsStream("Consequence.drl");
KieSession session = getStatelessKieSession(in);
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("ConsequenceTest2.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("No action - possibly commented out"));
Iterator<VerifierMessageBase> iterator = result.getBySeverity(Severity.WARNING).iterator();
Set<String> rulesThatHadErrors = new HashSet<String>();
while (iterator.hasNext()) {
Object o = iterator.next();
if (o instanceof VerifierMessage) {
VerifierMessage message = (VerifierMessage) o;
rulesThatHadErrors.addAll(message.getImpactedRules().values());
}
}
assertFalse(rulesThatHadErrors.contains("Has a consequence 1"));
assertTrue(rulesThatHadErrors.remove("Missing consequence 1"));
assertTrue(rulesThatHadErrors.remove("Missing consequence 2"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables.
@Test
public void testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables() 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 or unequal variables"));
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 11"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
Aggregations