Search in sources :

Example 21 with VerifierMessageBase

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

the class RestrictionOrderTest method testRestrictionOrderInsideOperator.

@Test
public void testRestrictionOrderInsideOperator() 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());
    // for ( Object object : testData ) {
    // if ( object instanceof SubPattern ) {
    // SubPattern s = (SubPattern) object;
    // System.out.println( " - " + s );
    // for ( PatternComponent o : s.getItems() ) {
    // System.out.println( " -- " + o + " : " + o.getOrderNumber() );
    // }
    // }
    // }
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise restrictions 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 Restriction[2])[0].getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Wrong descr 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 22 with VerifierMessageBase

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

the class NotesTest method testRedundantRestrictionsInPatternPossibilities.

@Test
public void testRedundantRestrictionsInPatternPossibilities() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    Collection<Object> objects = new ArrayList<Object>();
    LiteralRestriction left = LiteralRestriction.createRestriction(pattern, "");
    LiteralRestriction right = LiteralRestriction.createRestriction(pattern, "");
    Redundancy redundancy = new Redundancy(left, right);
    SubPattern possibility = new SubPattern(pattern, 0);
    possibility.add(left);
    possibility.add(right);
    objects.add(left);
    objects.add(right);
    objects.add(redundancy);
    objects.add(possibility);
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    session.setGlobal("result", result);
    for (Object o : objects) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant restrictions from pattern possibilities"));
    Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
    // Has at least one item.
    assertEquals(1, notes.size());
    VerifierMessageBase note = notes.iterator().next();
    Iterator<Cause> causes = note.getCauses().iterator();
    assertEquals(left, causes.next());
    assertEquals(right, causes.next());
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Redundancy(org.drools.verifier.report.components.Redundancy) ArrayList(java.util.ArrayList) 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 23 with VerifierMessageBase

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

the class NotesTest method testRedundantPatternPossibilitiesInRulePossibilities.

@Test
public void testRedundantPatternPossibilitiesInRulePossibilities() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    Collection<Object> objects = new ArrayList<Object>();
    SubPattern left = new SubPattern(pattern, 0);
    SubPattern right = new SubPattern(pattern, 1);
    Redundancy redundancy = new Redundancy(left, right);
    SubRule possibility = new SubRule(rule, 0);
    possibility.add(left);
    possibility.add(right);
    objects.add(left);
    objects.add(right);
    objects.add(redundancy);
    objects.add(possibility);
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    session.setGlobal("result", result);
    for (Object o : objects) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant pattern possibilities from rule possibilities"));
    Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
    // Has at least one item.
    assertEquals(1, notes.size());
    VerifierMessageBase note = notes.iterator().next();
    Iterator<Cause> causes = note.getCauses().iterator();
    assertEquals(left, causes.next());
    assertEquals(right, causes.next());
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Redundancy(org.drools.verifier.report.components.Redundancy) ArrayList(java.util.ArrayList) 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 24 with VerifierMessageBase

use of org.drools.verifier.report.components.VerifierMessageBase 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 25 with VerifierMessageBase

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

the class VerifierTest method testCustomRule.

@Test
public void testCustomRule() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("FindPatterns.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    if (!works) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
        fail("Could not run verifier");
    }
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(6, result.getBySeverity(Severity.NOTE).size());
    for (VerifierMessageBase m : result.getBySeverity(Severity.NOTE)) {
        assertEquals("This pattern was found.", m.getMessage());
    }
}
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)

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