Search in sources :

Example 1 with VerifierReport

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

the class MissingEqualityTest method testMissingEqualityInLiteralRestrictions.

@Test
public void testMissingEqualityInLiteralRestrictions() 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 LiteralRestrictions"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Collection<String> ruleNames = new ArrayList<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Cause cause = ((VerifierMessage) o).getFaulty();
            String name = ((LiteralRestriction) cause).getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Missing equality 1"));
    assertTrue(ruleNames.remove("Missing equality 2"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 2 with VerifierReport

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

the class MissingEqualityTest method testMissingEqualityInVariableRestrictions2.

@Test
public void testMissingEqualityInVariableRestrictions2() 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, unequal 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 7"));
    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 3 with VerifierReport

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

the class RestrictionOrderTest method testPredicateOrderInsideOperator.

@Test
public void testPredicateOrderInsideOperator() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("RestrictionOrder.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationRestrictionOrderTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise predicates inside operator"));
    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)

Example 4 with VerifierReport

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

the class WarningsTest method testRedundantRules.

@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testRedundantRules() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("RedundantRules1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    VerifierReport result = verifier.getResult();
    Collection<VerifierMessageBase> warnings = result.getBySeverity(Severity.WARNING);
    int counter = 0;
    for (VerifierMessageBase message : warnings) {
        // System.out.println( message );
        if (message.getMessageType().equals(MessageType.REDUNDANCY)) {
            // System.out.println( message );
            counter++;
        }
    }
    assertEquals(1, counter);
    verifier.dispose();
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) Verifier(org.drools.verifier.Verifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with VerifierReport

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

the class CauseTest method testCauseTrace.

@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testCauseTrace() throws Exception {
    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("Causes.drl", getClass()), 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());
    Collection<VerifierMessageBase> warnings = result.getBySeverity(Severity.WARNING);
    Collection<VerifierMessageBase> redundancyWarnings = new ArrayList<VerifierMessageBase>();
    for (VerifierMessageBase verifierMessageBase : warnings) {
        if (verifierMessageBase.getMessageType().equals(MessageType.REDUNDANCY)) {
            redundancyWarnings.add(verifierMessageBase);
        }
    }
    assertEquals(1, redundancyWarnings.size());
    VerifierMessage message = (VerifierMessage) redundancyWarnings.toArray()[0];
    // System.out.println( message );
    assertEquals(2, message.getImpactedRules().size());
    assertTrue(message.getImpactedRules().values().contains("Your First Rule"));
    assertTrue(message.getImpactedRules().values().contains("Your Second Rule"));
    Cause[] causes = message.getCauses().toArray(new Cause[message.getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(2, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(2, causes.length);
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) ArrayList(java.util.ArrayList) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Ignore(org.junit.Ignore) 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