Search in sources :

Example 6 with ExecutableCommand

use of org.kie.api.command.ExecutableCommand in project drools by kiegroup.

the class StatelessSessionTest method testInsertObject.

@Test
public void testInsertObject() throws Exception {
    String str = "";
    str += "package org.kie \n";
    str += "import org.drools.mvel.compiler.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( 30 ); \n";
    str += "end\n";
    Cheese stilton = new Cheese("stilton", 5);
    final StatelessKieSession ksession = getSession2(ResourceFactory.newByteArrayResource(str.getBytes()));
    final ExecutableCommand cmd = (ExecutableCommand) CommandFactory.newInsert(stilton, "outStilton");
    final BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl(Arrays.asList(new ExecutableCommand<?>[] { cmd }));
    final ExecutionResults result = (ExecutionResults) ksession.execute(batch);
    stilton = (Cheese) result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());
}
Also used : BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) ExecutionResults(org.kie.api.runtime.ExecutionResults) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) ExecutableCommand(org.kie.api.command.ExecutableCommand) Cheese(org.drools.mvel.compiler.Cheese) Test(org.junit.Test)

Aggregations

ExecutableCommand (org.kie.api.command.ExecutableCommand)6 Command (org.kie.api.command.Command)3 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ContextImpl (org.drools.core.command.impl.ContextImpl)1 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)1 Cheese (org.drools.mvel.compiler.Cheese)1 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)1 ScenarioResult (org.drools.scenariosimulation.backend.runner.model.ScenarioResult)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 RequestContext (org.kie.api.runtime.RequestContext)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 RegistryContext (org.kie.internal.command.RegistryContext)1 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1