Hi,
I've migrated from 3.0.6 to 4.0.4 of drools and an existing test case is now failing.
The test case tests dynamically changing the rules by adding a rule file to the existing
rulesBase that is a completely new package, then asserting that the existing rules fire
and the newly added rules fire. Up to this point it works as expected, the original
package of base rules fire and the newly added package of rules fires also. Next it adds
new rules that essentially replace the ones just added and fires the rules again. This
time only the newest rules added fire and the existing rules that did not change at all
and are in a completely different package then the rules just added DIDN'T fire. Upon
some debugging it looks like the ruleBase has both packages, the existing package and the
latest updated rules package, in it.
any advice appreciated please!!!!
thanks in advance!
here the test:
public void testUpdatingPackage() throws Exception {
logger.info("--------- testUpdatingPackage ----------");
//reinitialize ruleBaseBuilder - some base rules that i always want to run
ruleBaseBuilder.setRuleFile("com/xxx/coreservice/um/rules/um.drl");
String userName = "user";
CsUser user = Helpers.createUser(userName, userName, null);
// Set the displayname to null. If the default rules fire,
// it should be populated after running the rules.
user.setDisplayName(null);
user.setDescription("base");
// Add product's rules on the fly - some new rules
ruleBaseBuilder.addRulesFile("com/xxx/coreservice/um/ext/rules/p1.drl");
ruleInterceptor.addUser(user);
// assert that the default rule is invoked by checking the display name
assertEquals(user.getSurname() + ", " + user.getGivenName(),
user.getDisplayName());
// Check that the product extension did run
logger.info("User's description: " + user.getDescription());
assertTrue(user.getDescription().indexOf("p1ext") > 0);
// now update product's rules on the fly - change some of the new rules!
ruleBaseBuilder.addRulesFile("com/xxx/coreservice/um/ext/rules/p1updated.drl");
user = Helpers.createUser(userName, userName, null);
// Set the displayname to null. If the default rules fire,
// it should be populated after running the rules.
user.setDisplayName(null);
user.setDescription("base");
ruleInterceptor.addUser(user);
// assert that the default rule is invoked by checking the display name -
ASSERTION FAILS HERE because the original base rules dont fire and they are supposed to
fill in displayName
assertEquals(user.getSurname() + ", " + user.getGivenName(),
user.getDisplayName());
// Check that the updated product extension did run
logger.info("User's description: " + user.getDescription());
assertTrue(user.getDescription().indexOf("p1extupdated") > 0);
// This is to check that the old rule didn't run.
assertEquals(user.getDescription().indexOf("p1extupdated"),
user.getDescription().indexOf("p1ext"));
}
and the rules:
//---------------------p1updated-------------------------
package com.xxx.coreservice.um.ext.rules
import com.xxx.coreservice.persistence.user.CsUser;
import com.xxx.common.logging.client.Logger;
// TODO: Can these globals be inherited?
global Logger logger;
// TODO: Can this method be put into a helper?
// The disadvantage with that is that now we don't really know which rule file the
log
// was coming from.
function void log(Logger logger, String msg) {
if (logger.isFineEnabled()) {
logger.fine(msg);
}
}
rule "testRule"
no-loop true
agenda-group "um_add"
when
user : CsUser()
then
log(logger, "P1 updated test rule");
user.setDescription(user.getDescription() + ".p1extupdated");
end
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ