}
@Test
public void moreLogicalTMSApproach() {
Person person = new Person("salaboy");
person.addPhone(new Phone(person.getId(), "555-1235"));
StatefulKnowledgeSession ksession = createKSessionMoreLogical();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
Validation validation = new Validation("My Validation");
ksession.insert(validation);
if (person.getAddresses() != null) {
for (Address address : person.getAddresses()) {
ksession.insert(address);
}
}
if (person.getPhones() != null) {
for (Phone phone : person.getPhones()) {
ksession.insert(phone);
}
}
ksession.insert(person);
ksession.fireAllRules();
//Result for All Errors = 1
org.drools.runtime.rule.QueryResults results =
ksession.getQueryResults("getAllErrors", new Object[]{});
assertEquals(1, results.size());
//Corrections should be 1
results =
ksession.getQueryResults("getAllCorrectionRequest", new Object[]{});
assertEquals(1, results.size());
for (QueryResultsRow row : results) {
System.out.println(">>> Error ( " + ((CorrectionRequest) row.get("$correction")).getError().toString() + ")");
assertEquals("No Address or No Phone", ((CorrectionRequest) row.get("$correction")).getError().getMessage());
}
ksession.insert(new Address(person.getId(), "7th", 123, "92013"));
// I've already fix the problem
results =
ksession.getQueryResults("getAllCorrectionRequest", new Object[]{});
assertEquals(0, results.size());