Prefer KieHelper over a KieContainer classpath
While testing, the use of a KieContainer
classpath—the one you get from invoking KieServices.Factory.get().getKieClasspathContainer()
—is not always the best approach. The thing with a KieContainer
classpath is that it will scan the entire classpath looking for any META-INF/kmodule.xml
file.
If we are only interested in testing a single rule or a subset of the rules present in the application's classpath, there is no need to scan the entire classpath looking for all the kmodule.xml
files present.
There are different ways in Drools to create narrow containers with only the specific resources required for the specific scenario that we are testing. Probably, the easiest way is to make use of the org.kie.internal.utils.KieHelper
class. The KieHelper
class is a utility class that allows us to programmatically create a KIEContainer
by specifying the resources that we want to include in it. We have already seen examples making use of this class in the...