use of org.drools.verifier.components.VerifierRule 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.components.VerifierRule 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.components.VerifierRule in project drools by kiegroup.
the class VerifierImpl method addDrlRulesData.
private void addDrlRulesData(List<DrlRuleParser> rules) {
for (DrlRuleParser rData : rules) {
VerifierRule rule = this.result.getVerifierData().getRuleByName(rData.getName());
if (rule != null) {
rule.getHeader().addAll(rData.getHeader());
rule.getLhsRows().addAll(rData.getLhs());
rule.getRhsRows().addAll(rData.getRhs());
rule.setDescription(rData.getDescription());
rule.getCommentMetadata().addAll(rData.getMetadata());
rule.getOtherInfo().putAll(rData.getOtherInformation());
}
}
}
use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.
the class ComponentsReportVisitor method visitField.
public static String visitField(String sourceFolder, Field field, VerifierReport result) {
VerifierData data = result.getVerifierData();
ObjectType objectType = data.getVerifierObject(VerifierComponentType.OBJECT_TYPE, field.getObjectTypePath());
Collection<VerifierRule> rules = data.getRulesByFieldPath(field.getPath());
Map<String, Object> map = new HashMap<String, Object>();
map.put("sourceFolder", sourceFolder);
map.put("ruleFolder", UrlFactory.RULE_FOLDER);
map.put("objectTypeFolder", UrlFactory.OBJECT_TYPE_FOLDER);
map.put("fieldFolder", UrlFactory.FIELD_FOLDER);
map.put("field", field);
map.put("objectType", objectType);
map.put("rules", rules);
if (field.getFieldType() == Field.DOUBLE || field.getFieldType() == Field.DATE || field.getFieldType() == Field.INT) {
Collection<MissingRange> causes = result.getRangeCheckCausesByFieldPath(field.getPath());
Collection<Restriction> restrictions = data.getRestrictionsByFieldPath(field.getPath());
map.put("ranges", "Ranges:" + MissingRangesReportVisitor.visitRanges(UrlFactory.PREVIOUS_FOLDER, restrictions, causes));
} else {
map.put("ranges", "");
}
String myTemplate = readFile("field.htm");
return String.valueOf(TemplateRuntime.eval(myTemplate, map));
}
use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.
the class HTMLReportWriter method writeReport.
public void writeReport(OutputStream out, VerifierReport result) throws IOException {
zout = new ZipOutputStream(out);
VerifierData data = result.getVerifierData();
// Base files
// index.htm
writeToFile(UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.HTML_FILE_INDEX, formPage(UrlFactory.THIS_FOLDER, ComponentsReportVisitor.visitObjectTypeCollection(UrlFactory.THIS_FOLDER, data.<ObjectType>getAll(VerifierComponentType.OBJECT_TYPE))));
// packages.htm
writeToFile(UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.HTML_FILE_PACKAGES, formPage(UrlFactory.THIS_FOLDER, ComponentsReportVisitor.visitRulePackageCollection(UrlFactory.THIS_FOLDER, data.<RulePackage>getAll(VerifierComponentType.RULE_PACKAGE))));
// Rules
String ruleFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.RULE_FOLDER;
for (VerifierRule rule : data.<VerifierRule>getAll(VerifierComponentType.RULE)) {
writeToFile(ruleFolder + File.separator + rule.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitRule(UrlFactory.PREVIOUS_FOLDER, rule, data)));
}
// ObjectTypes
String objectTypeFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.OBJECT_TYPE_FOLDER;
for (ObjectType objectType : data.<ObjectType>getAll(VerifierComponentType.OBJECT_TYPE)) {
writeToFile(objectTypeFolder + File.separator + objectType.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitObjectType(UrlFactory.PREVIOUS_FOLDER, objectType, data)));
}
// Fields
String fieldFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.FIELD_FOLDER;
for (Field field : data.<Field>getAll(VerifierComponentType.FIELD)) {
writeToFile(fieldFolder + File.separator + field.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitField(UrlFactory.PREVIOUS_FOLDER, field, result)));
}
// Verifier messages
writeMessages(result);
// css files
String cssFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.CSS_FOLDER;
writeToFile(cssFolder + File.separator + UrlFactory.CSS_BASIC, ComponentsReportVisitor.getCss(UrlFactory.CSS_BASIC));
// Image files
String imagesFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.IMAGES_FOLDER;
copyFile(imagesFolder, "hdrlogo_drools50px.gif");
copyFile(imagesFolder, "jbossrules_hdrbkg_blue.gif");
zout.close();
}
Aggregations