Search in sources :

Example 16 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy4.

@Test
public void testVerifierLiteralRestrictionRedundancy4() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction4.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));
    // for ( Object object : subsumptionList ) {
    // System.out.println( object );
    // }
    assertEquals(4, subsumptionList.size());
    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 VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy1.

@Test
public void testVerifierLiteralRestrictionRedundancy1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction1.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));
    assertEquals(9, subsumptionList.size());
    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 18 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder 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 19 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder 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 20 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder 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

VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)27 Test (org.junit.Test)27 Verifier (org.drools.verifier.Verifier)18 VerifierReport (org.drools.verifier.data.VerifierReport)13 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)12 ClassPathResource (org.drools.core.io.impl.ClassPathResource)11 Subsumption (org.drools.verifier.report.components.Subsumption)11 Ignore (org.junit.Ignore)5 ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)4 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)4 IOException (java.io.IOException)2 JarInputStream (java.util.jar.JarInputStream)2 Field (org.drools.verifier.components.Field)2 ObjectType (org.drools.verifier.components.ObjectType)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 DefaultVerifierConfiguration (org.drools.verifier.DefaultVerifierConfiguration)1 VerifierError (org.drools.verifier.VerifierError)1