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

Conditional Consequence after an accumulate with multiple patterns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • executable model
    • None
    • 7
    • NEW
    • NEW

      It's similar to https://issues.jboss.org/browse/DROOLS-4684 but using multiple patterns in the accumulate

          @Test
          public void testIfAfterAccumulate() {
              String str =
                      "import " + Result.class.getCanonicalName() + ";\n" +
                      "import " + Person.class.getCanonicalName() + ";\n" +
                      "rule R when\n" +
                      "  $r : Result()\n" +
                      "  accumulate ( $p: Person ( getName().startsWith(\"M\")); \n" +
                      "                $sum : sum($p.getAge()),  \n" +
                      "                $sum2 : sum(70)  \n" +
                      "              )                          \n" +
                      "  if ($sum2 > 70) do[greater]\n" +
                      "  String()\n" +
                      "then\n" +
                      "  $r.addValue(\"default\");\n" +
                      "then[greater]\n" +
                      "  $r.addValue(\"greater\");\n" +
                      "end";
      
              KieSession ksession = getKieSession( str );
              Result result = new Result();
              ksession.insert( result );
      
              ksession.insert( new Person( "Mark", 37 ) );
              ksession.insert( new Person( "Edson", 35 ) );
              ksession.insert( new Person( "Mario", 40 ) );
              ksession.fireAllRules();
      
      
              List results = ( List )result.getValue();
              assertEquals(1, results.size());
              assertEquals("greater", results.get(0));
          }
      
      

              mfusco@redhat.com Mario Fusco
              lmolteni@redhat.com Luca Molteni
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: