KieBase kbase = kieContainer.getKieBase();
KieSession session = kbase.newKieSession();
FactType scorecardInternalsType = kbase.getFactType( PMML4Helper.pmmlDefaultPackageName(),"ScoreCard" );
Applicant applicant = new Applicant();
applicant.setAge(10);
session.insert(applicant);
//session.addEventListener(new DebugWorkingMemoryEventListener());
session.fireAllRules();
//occupation = 0, age = 30, validLicence -1, initialScore=100
assertEquals( 129.0,applicant.getTotalScore(), 0.0 );
assertEquals( "VL0099", applicant.getReasonCodes() );
Object scorecardInternals = session.getObjects( new ClassObjectFilter( scorecardInternalsType.getFactClass() ) ).iterator().next();
Assert.assertEquals( 129.0, scorecardInternalsType.get( scorecardInternals, "score" ) );
Map reasonCodesMap = (Map) scorecardInternalsType.get( scorecardInternals, "ranking" );
Assert.assertNotNull( reasonCodesMap );
Assert.assertEquals( Arrays.asList( "VL0099", "AGE02" ), new ArrayList( reasonCodesMap.keySet() ) );
session.dispose();
session = kbase.newKieSession();
applicant = new Applicant();
applicant.setOccupation("SKYDIVER");
applicant.setAge(0);
session.insert( applicant );
session.fireAllRules();
session.dispose();
//occupation = -10, age = +10, validLicense = -1, initialScore=100;
assertEquals(99.0, applicant.getTotalScore(), 0.0);
session = kbase.newKieSession();
applicant = new Applicant();
applicant.setResidenceState("AP");
applicant.setOccupation("TEACHER");
applicant.setAge(20);
applicant.setValidLicense(true);
session.insert( applicant );
session.fireAllRules();
session.dispose();
//occupation = +10, age = +40, state = -10, validLicense = 1, initialScore=100
assertEquals(141.0,applicant.getTotalScore(), 0.0);
}