Thanks for the tip. The "not Building()" works just fine, so long as I
don't assert the null building anyway.
I guess I was going for pure abstraction of all the rules, including
null even though deep down I knew it didn't make sense to assert a
null. The workaround is to hard code the null case like this:
private void validateGetBuilding( Building building ) throws BOException
// set up an exception
boException = new BOException();
// send the exception into the BRE
FactHandle boFact = businessRuleSession.insert( boException );
// send the building into the BRE
FactHandle buildingFact = null;
if( building != null )
buildingFact = businessRuleSession.insert( building );
// trigger the validate building agenda items
businessRuleSession.setFocus("validate delete or get building");
// retract items
if( buildingFact != null )
// check on the exception (is set in the rule)
if( boException.getCode() != null )
log.debug("Exception for building=" + building);
String message = BOMessages.getProperty( boException.getCode() );
With the rule in question being reconfigured to this:
rule "building is null"
agenda-group "validate delete or get building"
boException : BOException()
This ends up throwing the expected BOException:
08:16:26,093 DEBUG BuildingBO:288 = Exception for building=null
08:16:26,119 ERROR InCastAPI:73 = BO-0008: The building is null
Don't you just love the green bar in junit?
Thanks for you help -- really enjoying developing this app with Rules.
On 8/14/07, Edson Tirelli <tirelli(a)post.com> wrote:
I don't think it makes sense to assert null into working memory... null does not
matches any object type anyway...
Maybe what you want to do is to check for the non-existance of a fact:
So, don't ever assert null into working memory.
2007/8/14, Stuart Moffatt <stuart.moffatt(a)utah.edu >:
> The incoming building was initialized like this:
> Building building = null;
> FactHandle buildingFact = businessRuleSession.insert( building );
> businessRuleSession.setFocus("validate delete or get building");
> Can drools test for this null building?
> What should the rule look like?
> rule "building is null"
> agenda-group "validate delete or get building"
> salience 10
> boException : BOException()
> Building() == null /* this is the problem here -- not sure what this should
look like */
> rules-users mailing list
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
rules-users mailing list
Disaster Resistant University
University of Utah