Package org.kie.api.runtime

Examples of org.kie.api.runtime.StatelessKieSession


        assertNotNull(kbase);
    }

    @Test
    public void testDecisionTableRules() throws Exception {
        StatelessKieSession ksession = (StatelessKieSession) context.getBean("ksession-table-1");

        assertNotNull(ksession);

        // Cheeses selection
        Cheese cheese = new Cheese();
        cheese.setPrice(250);
        cheese.setType("cheddar");

        // Young person
        Person person = new Person();
        person.setName("Young Scott");
        person.setAge(21);

        List cmds = new ArrayList();
        cmds.add( CommandFactory.newSetGlobal("list", new ArrayList(), true) );
        cmds.add( CommandFactory.newInsert(person,"yscott"));
        cmds.add( CommandFactory.newInsert(cheese,"cheddar"));
        cmds.add( CommandFactory.newFireAllRules());

        // Execute the list
        ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(cmds));
        List list = (List) results.getValue("list");
        assertEquals(1, list.size());
        assertTrue(list.contains("Young man cheddar"));

        // Old person
        person = new Person();
        person.setName("Old Scott");
        person.setAge(42);

        cheese = new Cheese();
        cheese.setPrice(150);
        cheese.setType("stilton");

        cmds = new ArrayList();
        cmds.add( CommandFactory.newSetGlobal("list", new ArrayList(), true) );
        cmds.add( CommandFactory.newInsert(person,"oscott"));
        cmds.add( CommandFactory.newInsert(cheese,"stilton"));
        cmds.add( CommandFactory.newFireAllRules());

        // Execute the list
        results = ksession.execute(CommandFactory.newBatchExecution(cmds));
        list = (List) results.getValue("list");
        assertEquals(1, list.size());
        assertTrue(list.contains("Old man stilton"));

    }
View Full Code Here


        inXml += "      <oldPrice>0</oldPrice>";
        inXml += "    </org.kie.camel.testdomain.Cheese>";
        inXml += "  </insert-elements>";
        inXml += "</batch-execution>";

        StatelessKieSession ksession = getStatelessKieSession( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        setExec( ksession );

        String outXml = template.requestBody( "direct:exec",
                                              inXml,
                                              String.class );
View Full Code Here

        inXml += "      <oldPrice>0</oldPrice>";
        inXml += "  </org.kie.camel.testdomain.Cheese>";
        inXml += "  </insert>";
        inXml += "</batch-execution>";

        StatelessKieSession ksession = getStatelessKieSession( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        setExec( ksession );

        String outXml = template.requestBody( "direct:exec",
                                              inXml,
                                              String.class );
View Full Code Here

        inXml += "    </org.kie.camel.testdomain.Cheese>";
        inXml += "  </insert>";
        inXml += "  <get-global identifier='list' out-identifier='out-list'/>";
        inXml += "</batch-execution>";

        StatelessKieSession ksession = getStatelessKieSession( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        setExec( ksession );

        String outXml = template.requestBody( "direct:exec",
                                              inXml,
                                              String.class );
View Full Code Here

        inXml += "    </org.kie.camel.testdomain.Cheese>";
        inXml += "  </insert-elements>";
        inXml += "  <get-objects out-identifier='list' />";
        inXml += "</batch-execution>";

        StatelessKieSession ksession = getStatelessKieSession( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        setExec( ksession );

        String outXml = template.requestBody( "direct:exec",
                                              inXml,
                                              String.class );
View Full Code Here

        str += "    <connection from=\"1\" to=\"2\" />\n";
        str += "    <connection from=\"2\" to=\"3\" />\n";
        str += "  </connections>\n" + "\n";
        str += "</process>";

        StatelessKieSession ksession = getStatelessKieSessionFromResource(ResourceFactory.newByteArrayResource(str.getBytes())
                                                                                         .setSourcePath("src/main/resources/rule.rf")
                                                                                         .setResourceType(ResourceType.DRF));

        setExec( ksession );
        List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list",
                            list );
        TestVariable person = new TestVariable( "John Doe" );

        String inXml = "";
        inXml += "<batch-execution>";
View Full Code Here

        inXml += "   {   \"org.kie.camel.testdomain.Cheese\":{\"type\":\"stilton\",\"price\":30,\"oldPrice\":0}} ";
        inXml += "   ]}}";
        inXml += ",  {\"get-objects\":{\"out-identifier\":\"list1\"}}";
        inXml += "]}}";

        StatelessKieSession ksession = getStatelessKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
        setExec( ksession );

        String outXml = execContent( "testGetObjects.in.1" );

        // Can't compare content a hashmap of objects keeps changing order
View Full Code Here

        str += "  then \n";
        str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
        str += "    list1.add( $c );";
        str += "end\n";

        StatelessKieSession ksession = getStatelessKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
        setExec( ksession );

        String outXml = execContent( "testManualFireAllRules.in.1" );

        ExecutionResults result = unmarshalOutXml( outXml,
View Full Code Here

        str += "    <connection from=\"1\" to=\"2\" />\n";
        str += "    <connection from=\"2\" to=\"3\" />\n";
        str += "  </connections>\n" + "\n";
        str += "</process>";

        StatelessKieSession ksession = getStatelessKieSessionFromResource(ResourceFactory.newByteArrayResource(str.getBytes())
                                                                                         .setSourcePath("src/main/resources/rule.rf")
                                                                                         .setResourceType(ResourceType.DRF));
        List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list1",
                            list );
        setExec( ksession );

        String outXml = execContent( "testProcess.in.1" );
View Full Code Here

        assertNotNull(kbase);
    }

    @Test
    public void testKieSession() throws Exception {
        StatelessKieSession ksession = (StatelessKieSession) container.getComponentInstance("statelessWithGroupedListeners");
        assertNotNull(ksession);
    }
View Full Code Here

TOP

Related Classes of org.kie.api.runtime.StatelessKieSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.