[jboss-user] [Beginners Corner] - [Jboss Rules] - using constraints in LHS

viben2512 do-not-reply at jboss.com
Thu May 29 11:34:30 EDT 2008


I am discovering jboss rules (drools 4.0.7). I try to reproduce the example 'State' of drools. 
The drools version works fine.
But in my version, the rules are not fired and I do not understand why .... It is so basic I do not see where my mistake is. Please help

the rule

  | package examples.statemachine
  |  
  | import com.corp.drools.examples.statemachine.State;
  |  
  | rule Bootstrap
  | 	when
  | 		a : State(name == "A" )
  | 	then
  | 		System.out.println(a.getName() + " finished" );
  | 		a.setState( State.STATE_FINISHED );
  | end
  | 
 

the class State 
    
  | public static final Integer STATE_NOTRUN  = new Integer(0);
  | public static final Integer STATE_FINISHED = new Integer(1);
  | 
  | public State(final String name) {
  |   this.name = name;
  |   this.state = State.STATE_NOTRUN;
  | }
  | 
  | private String name;
  | private Integer state;
  | // ... getter, setter 
  | 

the test case :

  | public void test2() throws Exception {
  |   final PackageBuilder builder = new PackageBuilder();
  |   builder.addPackageFromDrl(new InputStreamReader(
  | this.getClass().getClassLoader().getResourceAsStream("examples/statemachine/rules.drl")));
  | 
  |   RuleBase ruleBase = RuleBaseFactory.newRuleBase();
  |   ruleBase.addPackage(builder.getPackage());
  |   StatefulSession session = ruleBase.newStatefulSession();
  | 
  |   WorkingMemoryConsoleLogger logger = new WorkingMemoryConsoleLogger(session);
  | 
  |   State[] objects = new State[] { new State("A") };
  |   session.insert(objects[0]);
  |   session.fireAllRules();
  |  
  |   session.dispose();
  |   Assert.assertEquals(State.STATE_FINISHED, objects[0].getState());
  | }
  | 

the test case output :
OBJECT ASSERTED value:A-0 factId: 1


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4154364#4154364

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4154364



More information about the jboss-user mailing list