use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class MissingEqualityTest method testMissingEqualityInLiteralRestrictions.
@Test
public void testMissingEqualityInLiteralRestrictions() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in LiteralRestrictions"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Collection<String> ruleNames = new ArrayList<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
Cause cause = ((VerifierMessage) o).getFaulty();
String name = ((LiteralRestriction) cause).getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Missing equality 1"));
assertTrue(ruleNames.remove("Missing equality 2"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class MissingEqualityTest method testMissingEqualityInVariableRestrictions2.
@Test
public void testMissingEqualityInVariableRestrictions2() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in VariableRestrictions, unequal operator"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Set<String> ruleNames = new HashSet<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
Cause cause = ((VerifierMessage) o).getFaulty();
String name = ((VariableRestriction) cause).getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Missing equality 7"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class RestrictionOrderTest method testPredicateOrderInsideOperator.
@Test
public void testPredicateOrderInsideOperator() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("RestrictionOrder.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationRestrictionOrderTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise predicates inside operator"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.NOTE).iterator();
Collection<String> ruleNames = new ArrayList<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
String name = ((VerifierMessage) o).getCauses().toArray(new RuleComponent[2])[0].getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Wrong eval order 1"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class WarningsTest method testRedundantRules.
@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testRedundantRules() throws Exception {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("RedundantRules1.drl", getClass()), ResourceType.DRL);
// for ( VerifierError error : verifier.getMissingClasses() ) {
// System.out.println( error.getMessage() );
// }
assertFalse(verifier.hasErrors());
boolean noProblems = verifier.fireAnalysis();
assertTrue(noProblems);
VerifierReport result = verifier.getResult();
Collection<VerifierMessageBase> warnings = result.getBySeverity(Severity.WARNING);
int counter = 0;
for (VerifierMessageBase message : warnings) {
// System.out.println( message );
if (message.getMessageType().equals(MessageType.REDUNDANCY)) {
// System.out.println( message );
counter++;
}
}
assertEquals(1, counter);
verifier.dispose();
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class VerifierMessagesVisitor method visitVerifierMessagesCollection.
public static String visitVerifierMessagesCollection(String title, Collection<VerifierMessageBase> messages, VerifierData data) {
Map<String, Object> map = new HashMap<String, Object>();
Collection<String> messageTemplates = new ArrayList<String>();
String myTemplate = readFile(VERIFIER_MESSAGES_TEMPLATE);
for (VerifierMessageBase message : messages) {
messageTemplates.add(visitVerifierMessage(message, data));
}
map.put("title", title);
map.put("messages", messageTemplates);
return String.valueOf(TemplateRuntime.eval(myTemplate, map));
}
Aggregations