I am upgrading Drools from an ancient version, which means I'm basically starting over. I have an existing spreadsheet that looks like this:
Here is the unit test which I am running:
@Test
public void getKieContainer() {
PoolInfo poolInfo = PoolInfoTest.getPool();
poolInfo.setCourtLocation("001");
PostponementRequest postponementRequest = new PostponementRequest();
GregorianCalendar requestDate = new GregorianCalendar(2025, GregorianCalendar.MAY, 5);
postponementRequest.setRequestDate(requestDate);
assertEquals("001", poolInfo.getCourtLocation());
assertEquals(2, postponementRequest.getRequestedDayOfWeek());
KieContainer kieContainer = droolsUtil.getKieContainer(POSTPONE_RULES);
StatelessKieSession kieSession = kieContainer.newStatelessKieSession();
List<Object> parms = Arrays.asList(poolInfo, postponementRequest);
kieSession.execute(parms);
assertTrue(postponementRequest.isAllowed());
}
The last assertTrue
is failing in my test. Here's the code of droolsUtil.getKieContainer()
:
public KieContainer getKieContainer(final String decisionTableFilename){
KieServices kieServices = KieServices.Factory.get();
Resource resource = ResourceFactory.newClassPathResource(decisionTableFilename, getClass());
KieFileSystem kieFileSystem = kieServices.newKieFileSystem().write(resource);
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
KieRepository kieRepository = kieServices.getRepository();
ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId();
KieContainer kieContainer = kieServices.newKieContainer(krDefaultReleaseId);
return kieContainer;
}
This all looks correct to me, but clearly there's an issue.
EDIT
Based on research, I have added debug listeners as follows:
StatelessKieSession kieSession = kieContainer.newStatelessKieSession();
kieSession.addEventListener( new DebugAgendaEventListener() );
kieSession.addEventListener( new DebugProcessEventListener() );
kieSession.addEventListener( new DebugRuleRuntimeEventListener() );
List<Object> parms = Arrays.asList(poolInfo, postponementRequest);
and then reran. This produced the following output:
[main] INFO org.drools.core.event.DebugRuleRuntimeEventListener - ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:1:488898339:1539934131:1:DEFAULT:NON_TRAIT:com.gs.jxx.bo.PoolInfo:Participant#:666666666|Pool#:444444444|Seq#:2165
Court Loc:001|Status:1|FTA:0|Deferral Count:0|SummonsDate:2025-06-07;07:21:01.660|Days B4 Summons:30|Division:1|Active:Y|PostponeDate:|PostponeDateRequest:], getObject()=Participant#:666666666|Pool#:444444444|Seq#:2165
Court Loc:001|Status:1|FTA:0|Deferral Count:0|SummonsDate:2025-06-07;07:21:01.660|Days B4 Summons:30|Division:1|Active:Y|PostponeDate:|PostponeDateRequest:, getKnowledgeRuntime()=KieSession[0], getPropagationContext()=PhreakPropagationContext [entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:1:488898339:1539934131:1:DEFAULT:NON_TRAIT:com.gs.jxx.bo.PoolInfo:Participant#:666666666|Pool#:444444444|Seq#:2165
Court Loc:001|Status:1|FTA:0|Deferral Count:0|SummonsDate:2025-06-07;07:21:01.660|Days B4 Summons:30|Division:1|Active:Y|PostponeDate:|PostponeDateRequest:], propagationNumber=2, rule=null, type=INSERTION]]
[main] INFO org.drools.core.event.DebugRuleRuntimeEventListener - ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:550424075:550424075:2:DEFAULT:NON_TRAIT:com.gs.jxx.request.PostponementRequest:
Pool:666666666:Ford Prefect|PendingIndicator:null|reason:null
RequestDate:5/5/2025|RequestTime:721|RequestDaysAfterSummons:-1|RequestedDayOfWeek:2|RequestedDayOfMonth:5], getObject()=
Pool:666666666:Ford Prefect|PendingIndicator:null|reason:null
RequestDate:5/5/2025|RequestTime:721|RequestDaysAfterSummons:-1|RequestedDayOfWeek:2|RequestedDayOfMonth:5, getKnowledgeRuntime()=KieSession[0], getPropagationContext()=PhreakPropagationContext [entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:550424075:550424075:2:DEFAULT:NON_TRAIT:com.gs.jxx.request.PostponementRequest:
Pool:666666666:Ford Prefect|PendingIndicator:null|reason:null
RequestDate:5/5/2025|RequestTime:721|RequestDaysAfterSummons:-1|RequestedDayOfWeek:2|RequestedDayOfMonth:5], propagationNumber=3, rule=null, type=INSERTION]]
I'm not sure how this helps.
I have compiled the spreadsheet into drools using the following code:
InputStream is = getClass().getClassLoader().getResourceAsStream(POSTPONE_RULES);
SpreadsheetCompiler compiler = new SpreadsheetCompiler();
String str = compiler.compile(is, InputType.XLS);
System.err.println(str);
and when I ran it, it produced:
package postponementRules;
//generated from Decision Table
import com.gs.juror.bo.PoolInfo;
import com.gs.juror.request.PostponementRequest;
// rule values at B10, header at B5
rule "postponePart_10"
when
PoolInfo(courtLocation == "001")
postponementRequest: PostponementRequest(requestedDayOfWeek >= 2, requestedDayOfWeek <= 2)
then
postponementRequest.setAllowed(true);
end
Which, I think, looks like what I expected. So the problem must be in the code running it.
Well, again, a lot of this issue was classpath issues that aren't reported as classpath issues.
Once I got through them, I had an issue I found here with the resolution: No files found for KieBase defaultKieBase - Drool-8.33.0.Final about the answer here: https://docs.drools.org/8.37.0.Final/drools-docs/docs-website/drools/release-notes/index.html#_spreadsheet_decision_tables_file_extensions
So I renamed the spreadsheet to *.drl.xls and it started working.