KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
//NEW WORKING MEMORY
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
Applicant applicant = new Applicant();
applicant.setAge(10);
session.insert(applicant);
//session.addEventListener(new DebugWorkingMemoryEventListener());
session.fireAllRules();
session.dispose();
//occupation = 0, age = 30, validLicence -1, initialScore=100
assertEquals(129.0,applicant.getTotalScore());
assertTrue(applicant.getReasonCodes().size() > 0);
session = kbase.newStatefulKnowledgeSession();
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());
session = kbase.newStatefulKnowledgeSession();
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());
}