Search in sources :

Example 16 with VerifierRule

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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with VerifierRule

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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with VerifierRule

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());
        }
    }
}
Also used : VerifierRule(org.drools.verifier.components.VerifierRule) DrlRuleParser(org.drools.verifier.misc.DrlRuleParser)

Example 19 with VerifierRule

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));
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Restriction(org.drools.verifier.components.Restriction) MissingRange(org.drools.verifier.report.components.MissingRange) VerifierData(org.drools.verifier.data.VerifierData) HashMap(java.util.HashMap) VerifierRule(org.drools.verifier.components.VerifierRule)

Example 20 with VerifierRule

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();
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) VerifierData(org.drools.verifier.data.VerifierData) ZipOutputStream(java.util.zip.ZipOutputStream) VerifierRule(org.drools.verifier.components.VerifierRule)

Aggregations

VerifierRule (org.drools.verifier.components.VerifierRule)20 Test (org.junit.Test)15 VerifierReport (org.drools.verifier.data.VerifierReport)11 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)10 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)10 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)10 KieSession (org.kie.api.runtime.KieSession)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)5 ObjectType (org.drools.verifier.components.ObjectType)5 Pattern (org.drools.verifier.components.Pattern)5 SubPattern (org.drools.verifier.components.SubPattern)5 SubRule (org.drools.verifier.components.SubRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Restriction (org.drools.verifier.components.Restriction)3 Field (org.drools.verifier.components.Field)2 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)2 RulePackage (org.drools.verifier.components.RulePackage)2 VerifierData (org.drools.verifier.data.VerifierData)2 AlwaysTrue (org.drools.verifier.report.components.AlwaysTrue)2