Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-5220

Make @watch annotation to also work with oopath

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • None
    • None
    • NEW
    • NEW

      Property reactivity is currently working on oopath as demostrated by this test case:

          @Test
          public void testPropertyReactivityWithOOPath() {
              String str =
                      "import " + Person.class.getCanonicalName() + ";" +
                      "import " + AdultUnit.class.getCanonicalName() + "\n" +
                      "rule Adult @Unit( AdultUnit.class ) when\n" +
                      "    $p : /persons[name == \"Mario\"]\n" +
                      "then\n" +
                      "    modify($p) { setAge($p.getAge()+1) };\n" +
                      "end\n";
      
              KieContainer kieContainer = getKieContainer( null, str );
              RuleUnitExecutor executor = RuleUnitExecutor.newRuleUnitExecutor( kieContainer );
      
              Person mario = new Person( "Mario", 45 );
              Person sofia = new Person( "Sofia", 8 );
      
              DataSource<Person> persons = DataSource.create( mario, sofia );
      
              AdultUnit unit = new AdultUnit(persons);
              assertEquals(1, executor.run( unit ) );
              assertEquals(46, mario.getAge() );
          }
      

      Conversely what it is not working (it doesn't compile at all) is the use of the @watch annotation like in

          @Test
          public void testPropertyReactivityWithOOPathAndWatch() {
              String str =
                      "import " + Person.class.getCanonicalName() + ";" +
                      "import " + AdultUnit.class.getCanonicalName() + "\n" +
                      "rule Adult @Unit( AdultUnit.class ) when\n" +
                      "    $p : /persons[$age : age, name == \"Mario\"] @watch( !age )\n" +
                      "then\n" +
                      "    modify($p) { setAge($age+1) };\n" +
                      "end\n";
      
              KieContainer kieContainer = getKieContainer( null, str );
              RuleUnitExecutor executor = RuleUnitExecutor.newRuleUnitExecutor( kieContainer );
      
              Person mario = new Person( "Mario", 45 );
              Person sofia = new Person( "Sofia", 8 );
      
              DataSource<Person> persons = DataSource.create( mario, sofia );
      
              AdultUnit unit = new AdultUnit(persons);
              assertEquals(1, executor.run( unit ) );
              assertEquals(46, mario.getAge() );
          }
      

      Of course this can work only on a one-level oopath. It has to be decided what to do (trigger a compile time error?) when trying to use that annotation on a oopath made of 2 or more chunks.

            mfusco@redhat.com Mario Fusco
            mfusco@redhat.com Mario Fusco
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: