Search in sources :

Example 6 with Verifier

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

the class SubsumptantSubPatternsTest method testSubpatternSubsumption5.

/**
 * Different sources
 *
 * @throws Exception
 */
@Test
public void testSubpatternSubsumption5() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns5.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(8, 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 7 with Verifier

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

the class SubsumptantSubPatternsTest method testSubpatternSubsumption1.

@Test
public void testSubpatternSubsumption1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    if (!noProblems) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
    }
    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)) {
            // System.out.println( " ** " + ((SubPattern) ((Subsumption) object).getLeft()).getItems() + " - " + ((SubPattern) ((Subsumption) object).getRight()).getItems() );
            count++;
        }
    }
    assertEquals(1, count);
    verifier.dispose();
}
Also used : VerifierError(org.drools.verifier.VerifierError) 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 8 with Verifier

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

the class SubsumptantSubPatternsTest method testSubpatternSubsumption2.

/**
 * Empty pattern
 *
 * @throws Exception
 */
@Test
public void testSubpatternSubsumption2() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns2.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 9 with Verifier

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

the class SubsumptantSubRulesTest method testSubruleSubsumption1.

@Test
public void testSubruleSubsumption1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubRules1.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_RULE)) {
            // System.out.println( " ** " + ((SubRule) ((Subsumption) object).getLeft()).getItems() + " - " + ((SubRule) ((Subsumption) object).getRight()).getItems() );
            count++;
        }
    }
    assertEquals(2, 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 10 with Verifier

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

the class VerifierComponentTest method testVisit.

@Test
public void testVisit() throws Exception {
    // Drools Package description from Drl file
    Reader drlReader = new InputStreamReader(Verifier.class.getResourceAsStream("Misc3.drl"));
    PackageDescr descr = new DrlParser(LanguageLevelOption.DRL5).parse(drlReader);
    // Drools Verifier objects
    VerifierData verifierData = VerifierReportFactory.newVerifierData();
    PackageDescrVisitor visitor = new PackageDescrVisitor(verifierData, Collections.EMPTY_LIST);
    visitor.visitPackageDescr(descr);
    // Collect the results.
    Collection<VerifierComponent> datas = verifierData.getAll();
    VerifierComponent[] components = datas.toArray(new VerifierComponent[datas.size()]);
    // Misc3.drl
    assertVerifierComponent((TextConsequence) components[0], 51);
    assertVerifierComponent((TextConsequence) components[1], 42);
    assertVerifierComponent((Field) components[2], 48);
    assertVerifierComponent((Field) components[3], 39);
    assertVerifierComponent((Field) components[4], 40);
    assertVerifierComponent((Field) components[5], 41);
    assertVerifierComponent((Import) components[6], 19);
    assertVerifierComponent((ObjectType) components[7], 48);
    assertVerifierComponent((ObjectType) components[8], 19);
    assertVerifierComponent((ObjectType) components[9], 39);
    assertVerifierComponent((ObjectType) components[10], 40);
    assertVerifierComponent((ObjectType) components[11], 41);
    assertVerifierComponent((RuleOperatorDescr) components[12], 48);
    assertVerifierComponent((PatternOperatorDescr) components[13], 48);
    assertVerifierComponent((PatternOperatorDescr) components[14], 49);
    assertVerifierComponent((PatternOperatorDescr) components[15], 50);
    assertVerifierComponent((RuleOperatorDescr) components[16], 39);
    assertVerifierComponent((PatternOperatorDescr) components[17], 39);
    assertVerifierComponent((PatternOperatorDescr) components[18], 40);
    assertVerifierComponent((PatternOperatorDescr) components[19], 41);
    assertVerifierComponent((Pattern) components[20], 48);
    assertVerifierComponent((Pattern) components[21], 49);
    assertVerifierComponent((Pattern) components[22], 50);
    assertVerifierComponent((Pattern) components[23], 39);
    assertVerifierComponent((Pattern) components[24], 40);
    assertVerifierComponent((Pattern) components[25], 41);
    assertVerifierComponent((NumberRestriction) components[26], 48);
    assertVerifierComponent((NumberRestriction) components[27], 49);
    assertVerifierComponent((NumberRestriction) components[28], 50);
    assertVerifierComponent((NumberRestriction) components[29], 39);
    assertVerifierComponent((NumberRestriction) components[30], 40);
    assertVerifierComponent((NumberRestriction) components[31], 41);
    assertVerifierComponent((NumberRestriction) components[32], 41);
    assertVerifierComponent((VerifierRule) components[33], 46);
    assertVerifierComponent((VerifierRule) components[34], 37);
    assertVerifierComponent((RulePackage) components[35], 17);
    assertVerifierComponent((SubPattern) components[36], 48);
    assertVerifierComponent((SubPattern) components[37], 49);
    assertVerifierComponent((SubPattern) components[38], 50);
    assertVerifierComponent((SubPattern) components[39], 39);
    assertVerifierComponent((SubPattern) components[40], 40);
    assertVerifierComponent((SubPattern) components[41], 41);
    assertVerifierComponent((SubRule) components[42], 46);
    assertVerifierComponent((SubRule) components[43], 37);
    assertVerifierComponent((WorkingMemory) components[44], -1);
}
Also used : InputStreamReader(java.io.InputStreamReader) VerifierData(org.drools.verifier.data.VerifierData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DrlParser(org.drools.compiler.compiler.DrlParser) Verifier(org.drools.verifier.Verifier) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierComponent(org.drools.verifier.data.VerifierComponent) 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