Search in sources :

Example 41 with VerifierReport

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

the class RangeCheckDatesTest method testEqualAndSmallerThan.

@Test
public void testEqualAndSmallerThan() 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 smaller 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 6b"));
    assertTrue(rulesThatHadErrors.remove("Date gap rule 2"));
    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 42 with VerifierReport

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

the class RangeCheckDoublesTest method testEqualAndGreaterThan.

@Test
public void testEqualAndGreaterThan() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Doubles.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDoubles.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for doubles, 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("Double gap rule 1"));
    assertTrue(rulesThatHadErrors.remove("Double gap rule 7b"));
    assertTrue(rulesThatHadErrors.remove("Double gap rule 3"));
    assertTrue(rulesThatHadErrors.remove("Double gap rule 9b"));
    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) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 43 with VerifierReport

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

the class RangeCheckIntegersTest method testGreaterOrEqual.

@Test
public void testGreaterOrEqual() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Integers.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForInts.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for integers, 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("Integer gap rule 4b"));
    assertTrue(rulesThatHadErrors.remove("Integer 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) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with VerifierReport

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

the class RangeCheckTest 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("RangeTest.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);
    for (VerifierMessageBase message : result.getBySeverity(Severity.ERROR)) {
        System.out.println(message);
    }
    // This rule should not have errors, evereververevernever!
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 45 with VerifierReport

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

the class VerifierTest method testFactTypesFromJarAndDeclarations.

@Test
public void testFactTypesFromJarAndDeclarations() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    try {
        JarInputStream jar = new JarInputStream(this.getClass().getResourceAsStream("model.jar"));
        verifier.addObjectModel(jar);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    verifier.addResourcesToVerify(new ClassPathResource("importsAndDeclarations.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    Collection<ObjectType> objectTypes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
    for (ObjectType objectType : objectTypes) {
        if (objectType.getName().equals("VoiceCall")) {
            assertEquals(4, objectType.getMetadata().keySet().size());
        }
    }
    assertNotNull(objectTypes);
    assertEquals(4, objectTypes.size());
    Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
    assertNotNull(fields);
    assertEquals(11, fields.size());
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) JarInputStream(java.util.jar.JarInputStream) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) IOException(java.io.IOException) ClassPathResource(org.drools.core.io.impl.ClassPathResource) 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