Search in sources :

Example 16 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class SubsumptantSubPatternsTest method testSubpatternSubsumption3.

/**
 * Different sources
 *
 * @throws Exception
 */
@Test
public void testSubpatternSubsumption3() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns3.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    int count = 0;
    for (Object object : subsumptionList) {
        // System.out.println( " * " + ((Subsumption) object) );
        if (((VerifierComponent) ((Subsumption) object).getLeft()).getVerifierComponentType().equals(VerifierComponentType.SUB_PATTERN)) {
            count++;
        }
    }
    assertEquals(1, count);
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 17 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class AlwaysFalseTest method testAlwaysFalse.

@Test
public void testAlwaysFalse() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("AlwaysFalseTest.drl", getClass()), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<VerifierMessageBase> notes = verifier.getResult().getBySeverity(Severity.ERROR);
    assertEquals(1, containsMessageType(notes, MessageType.ALWAYS_FALSE));
    verifier.dispose();
}
Also used : VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 18 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class EquivalentRulesTest method testVerifierLiteralRestrictionRedundancy.

@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testVerifierLiteralRestrictionRedundancy() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("EquivalentRules.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.EQUIVALANCE)) {
            // System.out.println( message );
            counter++;
        }
    }
    // Has at least one item.
    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 19 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class IncoherentRestrictionsTest method testApprovedTrueAndNotTrue.

@Test
public void testApprovedTrueAndNotTrue() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    String str = "";
    str += "package mortgages\n";
    str += "rule \"Bankruptcy history\"\n";
    str += "salience 10\n";
    str += "dialect \"mvel\"\n";
    str += "when\n";
    str += "Applicant( approved == \"true\" , approved != \"true\" )\n";
    str += "then\n";
    str += "end";
    DefaultVerifierConfiguration conf = new DefaultVerifierConfiguration();
    Verifier verifier = VerifierBuilderFactory.newVerifierBuilder().newVerifier(conf);
    verifier.addResourcesToVerify(ResourceFactory.newReaderResource(new StringReader(str)), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, ScopesAgendaFilter.VERIFYING_SCOPE_KNOWLEDGE_PACKAGE));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(3, result.getBySeverity(Severity.ERROR).size());
    assertEquals(1, result.getBySeverity(Severity.WARNING).size());
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
}
Also used : DefaultVerifierConfiguration(org.drools.verifier.DefaultVerifierConfiguration) ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) StringReader(java.io.StringReader) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Aggregations

Verifier (org.drools.verifier.Verifier)19 Test (org.junit.Test)19 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)18 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)12 Subsumption (org.drools.verifier.report.components.Subsumption)11 Ignore (org.junit.Ignore)5 VerifierReport (org.drools.verifier.data.VerifierReport)4 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 DrlParser (org.drools.compiler.compiler.DrlParser)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 DefaultVerifierConfiguration (org.drools.verifier.DefaultVerifierConfiguration)1 VerifierError (org.drools.verifier.VerifierError)1 ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)1