I have a java pojo class TestRule having variable ExpectedResultCode with appropriate getter and setter. I am using decision table drools
Now I want to access this set value of ExpectedResultCode in java.
Action: call setResultCode setter of the TestRule class and set the appropriate parameter from excel
TestRule.java-
public class TestRule {
public String ExpectedResultCode;
public String getResultCode() {
return ExpectedResultCode;
}
public void setResultCode(String ExpectedResultCode) {
this.ExpectedResultCode = ExpectedResultCode;
}
}
Drools Code:
KieContainer kieContainer = kieServices
.newKieContainer(kieServices.getRepository()
.getDefaultReleaseId());
kieSession = kieContainer.newKieSession();
TestRule testrule = new TestRule();
kieSession.insert(testrule);
System.out.println("Output of Result Code:" + testrule.getResultCode()); --> I'm getting Null Value here.
kieSession.fireAllRules();
In decision table, I changed action to testrule.setResultCode($param)
I want to get "Result1" as output, but I'm getting Null value.
You display the object before firing the rules:
kieSession = kieContainer.newKieSession();
// create a TestRule object: ExpectedResultCode is null
TestRule testrule = new TestRule();
// insert the TestRule object: ExpectedResultCode is still null
kieSession.insert(testrule);
// display TestRule's ExpectedResultCode, which is still null
System.out.println("Output of Result Code:" + testrule.getResultCode());
// fire the rules
kieSession.fireAllRules();
Print the value after firing the rules:
// now the object TestRule's ExpectedResultCode should have changed.
System.out.println("Output of Result Code:" + testrule.getResultCode());