Search in sources :

Example 6 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class ConditionalBranchDescrTest method testVerifier.

@Test
public void testVerifier() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(new ClassPathResource("ConditionalBranchDescrTest.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
// assertEquals( 0,
// result.getBySeverity( Severity.ERROR ).size() );
// assertEquals( 6,
// result.getBySeverity( Severity.WARNING ).size() );
// assertEquals( 1,
// result.getBySeverity( Severity.NOTE ).size() );
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 7 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class PatternSolverDRLTest method testOrInsidePattern.

@Test
public void testOrInsidePattern() throws Exception {
    StringBuffer rule = new StringBuffer();
    rule.append("rule \"Test rule\" ");
    rule.append("   when ");
    rule.append("       customer : Customer( status > 30 && < 50 ) ");
    rule.append("       order : OrderHeader( customer == customer , orderPriority == 3 || == 4 ) ");
    rule.append("   then ");
    rule.append("       order.setOrderDiscount( 6.0 ); ");
    rule.append("end");
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(new ByteArrayInputStream(rule.toString().getBytes()), result.getVerifierData());
    int patternCount = 0;
    // the right amount of items.
    for (Object o : testData) {
        if (o instanceof SubPattern) {
            SubPattern pp = (SubPattern) o;
            if (pp.getItems().size() == 2) {
                patternCount++;
            }
        }
    }
    assertEquals(3, patternCount);
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) ByteArrayInputStream(java.io.ByteArrayInputStream) SubPattern(org.drools.verifier.components.SubPattern) Test(org.junit.Test)

Example 8 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class RangeCheckDatesTest method testEqualAndGreaterThan.

@Test
public void testEqualAndGreaterThan() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Dates.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDates.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for dates, equal and greater than"));
    Set<String> rulesThatHadErrors = new HashSet<String>();
    for (Object o : session.getObjects()) {
        if (o instanceof Gap) {
            rulesThatHadErrors.add(((Gap) o).getRuleName());
        }
    // System.out.println(o);
    }
    assertTrue(rulesThatHadErrors.remove("Date gap rule 1"));
    assertTrue(rulesThatHadErrors.remove("Date gap rule 7b"));
    assertTrue(rulesThatHadErrors.remove("Date gap rule 3"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) Gap(org.drools.verifier.report.components.Gap) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class RangeCheckDatesTest method testGreaterOrEqual.

@Test
public void testGreaterOrEqual() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Dates.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDates.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for dates, if greater than or equal is missing"));
    Set<String> rulesThatHadErrors = new HashSet<String>();
    for (Object o : session.getObjects()) {
        if (o instanceof Gap) {
            rulesThatHadErrors.add(((Gap) o).getRuleName());
        }
    // System.out.println(o);
    }
    assertTrue(rulesThatHadErrors.remove("Date gap rule 4b"));
    assertTrue(rulesThatHadErrors.remove("Date gap rule 5b"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) Gap(org.drools.verifier.report.components.Gap) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with VerifierReport

use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.

the class RangeCheckDatesTest method testSmallerOrEqual.

@Test
public void testSmallerOrEqual() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Dates.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDates.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for dates, if smaller than or equal is missing"));
    Set<String> rulesThatHadErrors = new HashSet<String>();
    for (Object o : session.getObjects()) {
        if (o instanceof Gap) {
            rulesThatHadErrors.add(((Gap) o).getRuleName());
        }
    // System.out.println(o);
    }
    assertTrue(rulesThatHadErrors.remove("Date gap rule 4a"));
    assertTrue(rulesThatHadErrors.remove("Date gap rule 5a"));
    if (!rulesThatHadErrors.isEmpty()) {
        for (String string : rulesThatHadErrors) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) Gap(org.drools.verifier.report.components.Gap) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VerifierReport (org.drools.verifier.data.VerifierReport)60 Test (org.junit.Test)59 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)45 KieSession (org.kie.api.runtime.KieSession)45 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)32 HashSet (java.util.HashSet)29 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)26 ArrayList (java.util.ArrayList)14 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)13 Gap (org.drools.verifier.report.components.Gap)12 VerifierRule (org.drools.verifier.components.VerifierRule)11 ClassPathResource (org.drools.core.io.impl.ClassPathResource)10 Pattern (org.drools.verifier.components.Pattern)8 Cause (org.drools.verifier.report.components.Cause)7 Verifier (org.drools.verifier.Verifier)4 ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)4 Ignore (org.junit.Ignore)4 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)4 Field (org.drools.verifier.components.Field)3 ObjectType (org.drools.verifier.components.ObjectType)3