Search in sources :

Example 31 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class DataDictionaryTest method testEntryPoints.

@Test
public void testEntryPoints() throws Exception {
    setKSession(getModelSession(source, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType gender = getKbase().getFactType(packageName, "Gender");
    FactType noclaims = getKbase().getFactType(packageName, "NoOfClaims");
    FactType scrambled = getKbase().getFactType(packageName, "Scrambled");
    FactType domicile = getKbase().getFactType(packageName, "Domicile");
    FactType agecar = getKbase().getFactType(packageName, "AgeOfCar");
    FactType amklaims = getKbase().getFactType(packageName, "AmountOfClaims");
    assertEquals(7, getKSession().getEntryPoints().size());
    EntryPoint gender_ep = getKSession().getEntryPoint("in_Gender");
    Assert.assertNotNull(gender_ep);
    EntryPoint noclaims_ep = getKSession().getEntryPoint("in_NoOfClaims");
    Assert.assertNotNull(noclaims_ep);
    EntryPoint scrambled_ep = getKSession().getEntryPoint("in_Scrambled");
    Assert.assertNotNull(scrambled_ep);
    EntryPoint domicile_ep = getKSession().getEntryPoint("in_Domicile");
    Assert.assertNotNull(domicile_ep);
    EntryPoint agecar_ep = getKSession().getEntryPoint("in_AgeOfCar");
    Assert.assertNotNull(agecar_ep);
    EntryPoint amklaims_ep = getKSession().getEntryPoint("in_AmountOfClaims");
    Assert.assertNotNull(amklaims_ep);
    gender_ep.insert("M");
    noclaims_ep.insert("> 4");
    scrambled_ep.insert(4);
    domicile_ep.insert("way out");
    agecar_ep.insert(new Double("3.4"));
    amklaims_ep.insert(9);
    getKSession().fireAllRules();
    assertEquals(6, getKSession().getObjects().size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(gender.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(noclaims.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(scrambled.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(domicile.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(agecar.getFactClass())).size());
    assertEquals(1, getKSession().getObjects(new ClassObjectFilter(amklaims.getFactClass())).size());
    checkFirstDataFieldOfTypeStatus(amklaims, true, false, null, 9);
    checkFirstDataFieldOfTypeStatus(domicile, false, false, null, "way out");
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) EntryPoint(org.kie.api.runtime.rule.EntryPoint) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 32 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class OverlappingRestrictionsTest method testOverlap.

// TODO: Add this feature
@Test
@Ignore
public void testOverlap() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("RestrictionsTest.drl", getClass()), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> overlaps = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Overlap.class));
    for (Object object : overlaps) {
        System.out.println(object);
    }
    assertEquals(3, overlaps.size());
    verifier.dispose();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Overlap(org.drools.verifier.report.components.Overlap) Verifier(org.drools.verifier.Verifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class RedundancyTest method testVerifierLiteralRestrictionRedundancy.

@Test
public void testVerifierLiteralRestrictionRedundancy() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("RedundantRestrictions.drl", getClass()), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    Collection<? extends Object> redundancyList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Redundancy.class));
    assertEquals(2, subsumptionList.size());
    assertEquals(1, redundancyList.size());
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) Redundancy(org.drools.verifier.report.components.Redundancy) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 34 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter in project drools by kiegroup.

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy2.

@Test
public void testVerifierLiteralRestrictionRedundancy2() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction2.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 35 with ClassObjectFilter

use of org.kie.api.runtime.ClassObjectFilter 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)

Aggregations

ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)51 Test (org.junit.Test)44 KieSession (org.kie.api.runtime.KieSession)24 FactType (org.kie.api.definition.type.FactType)16 Verifier (org.drools.verifier.Verifier)12 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)12 Subsumption (org.drools.verifier.report.components.Subsumption)11 FactHandle (org.kie.api.runtime.rule.FactHandle)11 KieBase (org.kie.api.KieBase)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 DroolsAbstractPMMLTest (org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest)9 KieServices (org.kie.api.KieServices)9 Iterator (java.util.Iterator)7 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)7 Map (java.util.Map)5 KieBuilder (org.kie.api.builder.KieBuilder)5 KieFileSystem (org.kie.api.builder.KieFileSystem)5 KieContainer (org.kie.api.runtime.KieContainer)5 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)5