0 Replies Latest reply on May 29, 2008 11:34 AM by benoit villaumie

    [Jboss Rules] - using constraints in LHS

    benoit villaumie Newbie

      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
       a : State(name == "A" )
       System.out.println(a.getName() + " finished" );
       a.setState( State.STATE_FINISHED );

      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(
       RuleBase ruleBase = RuleBaseFactory.newRuleBase();
       StatefulSession session = ruleBase.newStatefulSession();
       WorkingMemoryConsoleLogger logger = new WorkingMemoryConsoleLogger(session);
       State[] objects = new State[] { new State("A") };
       Assert.assertEquals(State.STATE_FINISHED, objects[0].getState());

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