Search in sources :

Example 16 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.

the class IncoherentRestrictionsTest method testIncoherentLiteralRestrictionsInSubPatternImpossibleEqualityLess.

@Test
public void testIncoherentLiteralRestrictionsInSubPatternImpossibleEqualityLess() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("RestrictionsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent LiteralRestrictions with ranges in pattern possibility, impossible equality less or equal"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.ERROR).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Pattern pattern = (Pattern) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(pattern.getRuleName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent restrictions 9"));
    assertTrue(rulesThatHadErrors.remove("Incoherent restrictions 11"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Pattern(org.drools.verifier.components.Pattern) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.

the class IncoherentRestrictionsTest method testIncoherentLiteralRestrictionsInSubPattern.

@Test
public void testIncoherentLiteralRestrictionsInSubPattern() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(getClass().getResourceAsStream("RestrictionsTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent LiteralRestrictions in pattern possibility"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.ERROR).iterator();
    Set<String> rulesThatHadErrors = new HashSet<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Pattern pattern = (Pattern) ((VerifierMessage) o).getFaulty();
            rulesThatHadErrors.add(pattern.getRuleName());
        }
    }
    assertTrue(rulesThatHadErrors.remove("Incoherent restrictions 1"));
    assertTrue(rulesThatHadErrors.remove("Incoherent restrictions 2"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Pattern(org.drools.verifier.components.Pattern) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.

the class MissingEqualityTest method testMissingEqualityInVariableRestrictions.

@Test
public void testMissingEqualityInVariableRestrictions() 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, equal 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 5"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VariableRestriction(org.drools.verifier.components.VariableRestriction) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 19 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.

the class MissingEqualityTest method testMissingEqualityInVariableRestrictions3.

@Test
public void testMissingEqualityInVariableRestrictions3() 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, custom 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 3"));
    assertTrue(ruleNames.remove("Missing equality 4"));
    assertTrue(ruleNames.remove("Missing equality 6"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VariableRestriction(org.drools.verifier.components.VariableRestriction) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 20 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.

the class PatternOrderTest method testEvalOrderInsideOperator.

@Test
public void testEvalOrderInsideOperator() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("PatternOrder.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationPatternOrderTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise evals inside pattern"));
    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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) ArrayList(java.util.ArrayList) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)34 VerifierReport (org.drools.verifier.data.VerifierReport)32 Test (org.junit.Test)31 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)27 KieSession (org.kie.api.runtime.KieSession)27 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)26 HashSet (java.util.HashSet)17 VerifierRule (org.drools.verifier.components.VerifierRule)10 ArrayList (java.util.ArrayList)8 Pattern (org.drools.verifier.components.Pattern)7 Cause (org.drools.verifier.report.components.Cause)7 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)4 VariableRestriction (org.drools.verifier.components.VariableRestriction)3 InputStream (java.io.InputStream)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 Verifier (org.drools.verifier.Verifier)2 Redundancy (org.drools.verifier.report.components.Redundancy)2 Ignore (org.junit.Ignore)2 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1