[jboss-jira] [JBoss JIRA] (DROOLS-4776) Conditional Consequence after an accumulate with multiple patterns

Luca Molteni (Jira) issues at jboss.org
Mon Nov 18 07:56:08 EST 2019


     [ https://issues.jboss.org/browse/DROOLS-4776?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

{code:java}
    @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();
{code}

        List results = ( List )result.getValue();
        assertEquals(1, results.size());
        assertEquals("greater", results.get(0));
    }}}

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

{code:java}
    @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));
    }}}



> Conditional Consequence after an accumulate with multiple patterns
> ------------------------------------------------------------------
>
>                 Key: DROOLS-4776
>                 URL: https://issues.jboss.org/browse/DROOLS-4776
>             Project: Drools
>          Issue Type: Bug
>          Components: executable model
>            Reporter: Luca Molteni
>            Assignee: Mario Fusco
>            Priority: Major
>
>  It's similar to https://issues.jboss.org/browse/DROOLS-4684 but using multiple patterns in the accumulate
> {code:java}
>     @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();
> {code}
>         List results = ( List )result.getValue();
>         assertEquals(1, results.size());
>         assertEquals("greater", results.get(0));
>     }}}



--
This message was sent by Atlassian Jira
(v7.13.8#713008)


More information about the jboss-jira mailing list