Search in sources :

Example 66 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions5.

@Test
public void testFunctions5() throws Exception {
    setKSession(getModelSession(source3, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge5 = getKbase().getFactType(packageName, "UserAge5");
    getKSession().getEntryPoint("in_Age").insert(10);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge5, true, false, null, 45.5);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 67 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions4.

@Test
public void testFunctions4() throws Exception {
    setKSession(getModelSession(source3, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge4 = getKbase().getFactType(packageName, "UserAge4");
    getKSession().getEntryPoint("in_Age").insert(10);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(userAge4, true, false, null, 24);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 68 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class UserDefinedFunctionsTest method testFunctions0Overwrite.

@Test
public void testFunctions0Overwrite() throws Exception {
    setKSession(getModelSession(source0, VERBOSE));
    setKbase(getKSession().getKieBase());
    FactType userAge1 = getKbase().getFactType(packageName, "UserAge");
    getKSession().getEntryPoint("in_Age").insert(8.4);
    getKSession().fireAllRules();
    getKSession().getEntryPoint("in_Age").insert(2.2);
    getKSession().fireAllRules();
    System.out.println(reportWMObjects(getKSession()));
    checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 22.0);
    checkGeneratedRules();
}
Also used : FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 69 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class ScorecardsKModuleTest method testScorecardFromKModule2.

@Test
public void testScorecardFromKModule2() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieBase kBase = kContainer.getKieBase("namedkiesession");
    assertNotNull(kBase);
    KieSession kSession = kContainer.newKieSession("ksession1");
    assertNotNull(kSession);
    FactType scorecardType = kBase.getFactType("org.drools.scorecards.example", "SampleScore");
    assertNotNull(scorecardType);
    Object scorecard = scorecardType.newInstance();
    assertNotNull(scorecard);
    scorecardType.set(scorecard, "age", 10);
    kSession.insert(scorecard);
    kSession.fireAllRules();
    kSession.dispose();
    // occupation = 5, age = 25, validLicence -1
    assertEquals(29.0, scorecardType.get(scorecard, "scorecard__calculatedScore"));
}
Also used : KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieContainer(org.kie.api.runtime.KieContainer) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 70 with FactType

use of org.kie.api.definition.type.FactType in project drools by kiegroup.

the class ScorecardsKModuleTest method testScorecardFromKBase2.

@Test
public void testScorecardFromKBase2() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieBase kBase = kContainer.getKieBase("kbase2");
    assertNotNull(kBase);
    KieSession kSession = kContainer.newKieSession("ksession2");
    assertNotNull(kSession);
    FactType scorecardType = kBase.getFactType("org.drools.scorecards.example", "SampleScore");
    assertNotNull(scorecardType);
    Object scorecard = scorecardType.newInstance();
    assertNotNull(scorecard);
    scorecardType.set(scorecard, "age", 50);
    scorecardType.set(scorecard, "validLicense", true);
    scorecardType.set(scorecard, "occupation", "PROGRAMMER");
    // occupation
    kSession.insert(scorecard);
    kSession.fireAllRules();
    kSession.dispose();
    // age = 25, validLicence 0, occupation=5
    assertEquals(30.0, scorecardType.get(scorecard, "scorecard__calculatedScore"));
}
Also used : KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieContainer(org.kie.api.runtime.KieContainer) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Aggregations

FactType (org.kie.api.definition.type.FactType)208 Test (org.junit.Test)193 KieSession (org.kie.api.runtime.KieSession)114 KieBase (org.kie.api.KieBase)63 DroolsAbstractPMMLTest (org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest)45 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)31 ArrayList (java.util.ArrayList)28 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)27 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)27 KieServices (org.kie.api.KieServices)22 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)18 Resource (org.kie.api.io.Resource)17 KieBuilder (org.kie.api.builder.KieBuilder)16 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)16 KieFileSystem (org.kie.api.builder.KieFileSystem)15 KieContainer (org.kie.api.runtime.KieContainer)15 List (java.util.List)10 Results (org.kie.api.builder.Results)10 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)9 LogicalTypeInconsistencyException (org.drools.core.factmodel.traits.LogicalTypeInconsistencyException)9