@Test public void testCancelNonRegisteredWorkItemHandler() { String processId = "org.drools.actions"; String workName = "Unnexistent Task"; RuleFlowProcess process = getWorkItemProcess(processId, workName); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); ((AbstractRuleBase) ((InternalKnowledgeBase) kbase).getRuleBase()).addProcess(process); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); ksession.getWorkItemManager().registerWorkItemHandler(workName, new DoNothingWorkItemHandler()); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("UserName", "John Doe"); parameters.put("Person", new Person("John Doe")); ProcessInstance processInstance = ksession.startProcess("org.drools.actions", parameters); long processInstanceId = processInstance.getId(); Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); ksession.getWorkItemManager().registerWorkItemHandler(workName, null); try { ksession.abortProcessInstance(processInstanceId); Assert.fail("should fail if WorkItemHandler for" + workName + "is not registered"); } catch (WorkItemHandlerNotFoundException wihnfe) { } Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState()); }
@Test public void testPersistenceWorkItems() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); int origNumObjects = ksession.getObjects().size(); long id = ksession.getIdentifier(); ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess"); ksession.insert("TestString"); logger.debug("Started process instance " + processInstance.getId()); TestWorkItemHandler handler = TestWorkItemHandler.getInstance(); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertEquals(origNumObjects + 1, ksession.getObjects().size()); for (Object o : ksession.getObjects()) { logger.debug(o.toString()); } assertNull(processInstance); }
@Test public void testPersistenceWorkItems2() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); int id = ksession.getId(); UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); ut.begin(); ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess"); ksession.insert("TestString"); logger.debug("Started process instance {}", processInstance.getId()); TestWorkItemHandler handler = TestWorkItemHandler.getInstance(); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); ut.commit(); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNull(workItem); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertEquals(1, ksession.getObjects().size()); for (Object o : ksession.getObjects()) { logger.debug(o.toString()); } assertNull(processInstance); }
@Test public void testPersistenceVariables() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("VariablesProcess.rf"), ResourceType.DRF); for (KnowledgeBuilderError error : kbuilder.getErrors()) { logger.debug(error.toString()); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); long id = ksession.getIdentifier(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("name", "John Doe"); ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess", parameters); TestWorkItemHandler handler = TestWorkItemHandler.getInstance(); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); assertEquals("John Doe", workItem.getParameter("name")); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); assertEquals("John Doe", workItem.getParameter("text")); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNull(processInstance); }
@Test public void testPersistenceSubProcess() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("SuperProcess.rf"), ResourceType.DRF); kbuilder.add(new ClassPathResource("SubProcess.rf"), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); long id = ksession.getIdentifier(); ProcessInstance processInstance = ksession.startProcess("com.sample.SuperProcess"); logger.debug("Started process instance " + processInstance.getId()); TestWorkItemHandler handler = TestWorkItemHandler.getInstance(); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); workItem = handler.getWorkItem(); assertNull(workItem); ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNull("Process did not complete.", processInstance); }
@Test public void testPersistenceWorkItems3() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new SystemOutWorkItemHandler()); ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess"); ksession.insert("TestString"); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); }
@Test public void testPersistenceEvents() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(new ClassPathResource("EventsProcess.rf"), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); int id = ksession.getId(); ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess"); logger.debug("Started process instance {}", processInstance.getId()); TestWorkItemHandler handler = TestWorkItemHandler.getInstance(); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession.signalEvent("MyEvent1", null, processInstance.getId()); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNotNull(processInstance); ksession.signalEvent("MyEvent2", null, processInstance.getId()); ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env); processInstance = ksession.getProcessInstance(processInstance.getId()); assertNull(processInstance); }
public static final void main(String[] args) { try { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); final KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000); final HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession); Runtime.getRuntime() .addShutdownHook( new Thread() { public void run() { if (logger != null) { try { hornetQHTWorkItemHandler.dispose(); } catch (Exception ex) { Logger.getLogger(EvaluationExample.class.getName()) .log(Level.SEVERE, null, ex); } logger.close(); System.exit(0); } } }); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler); // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("employee", "krisv"); params.put("reason", "Yearly performance evaluation"); ksession.startProcess("com.sample.evaluation", params); } catch (Throwable t) { t.printStackTrace(); } }
private void createKnowledgeSessionStartProcessEtc(KieBase kbase) { logger.info("session count=" + kbase.getKieSessions().size()); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, getKnowledgeSessionConfiguration(), env); addEventListenersToSession(ksession); /** * The following log line caused the memory leak. The specific (reverse-ordered) stack trace is * the following: * * <p>MemoryLeakTest.createKnowledgeSessionStartProcessEtc(KnowledgeBase) calls * kbase.getKieSessions() .. KnowledgeBaseImpl.getStatefulKnowledgeSessions() line: 186 * StatefulKnowledgeSessionImpl.<init>(ReteooWorkingMemory, KnowledgeBase) line: 121 * ReteooStatefulSession(AbstractWorkingMemory).setKnowledgeRuntime(InternalKnowledgeRuntime) * line: 1268 ReteooStatefulSession(AbstractWorkingMemory).createProcessRuntime() line: 342 * ProcessRuntimeFactory.newProcessRuntime(AbstractWorkingMemory) line: 12 * ProcessRuntimeFactoryServiceImpl.newProcessRuntime(AbstractWorkingMemory) line: 1 * ProcessRuntimeFactoryServiceImpl.newProcessRuntime(AbstractWorkingMemory) line: 10 * ProcessRuntimeImpl.<init>(AbstractWorkingMemory) line: 84 * ProcessRuntimeImpl.initProcessEventListeners() line: 215 * * <p>And ProcessRuntimeImpl.initProcessEventListeners() is what adds a new listener to * AbstractRuleBase.eventSupport.listeners via this line (235): * kruntime.getKnowledgeBase().addEventListener(knowledgeBaseListener); * * <p>The StatefulKnowledgeSessionImpl instance created in this .getStatefulKnowledgeSessions() * method is obviously never disposed, which means that the listener is never removed. The * listener then contains a link to a field (signalManager) of the ProcessRuntimeImpl, which * contains a link to the StatefulKnowledgeSessionImpl instance created here. etc.. */ logger.info("session count=" + kbase.getKieSessions().size()); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); try { // create process instance, insert into session and start process Map<String, Object> processParams = new HashMap<String, Object>(); String[] fireballVarHolder = new String[1]; processParams.put("fireball", fireballVarHolder); ProcessInstance processInstance = ksession.createProcessInstance(PROCESS_NAME, processParams); ksession.insert(processInstance); ksession.startProcessInstance(processInstance.getId()); // after the log line has been added, the DefaultProcessEventListener registered // in the addEventListenersToSession() method no longer works?!? ksession.fireAllRules(); // test process variables String[] procVar = (String[]) ((WorkflowProcessInstance) processInstance).getVariable("fireball"); assertEquals("Rule task did NOT fire or complete.", "boom!", procVar[0]); // complete task and process Map<String, Object> results = new HashMap<String, Object>(); results.put("chaerg", new SerializableResult("zhrini", 302l, "F", "A", "T")); ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), results); assertNull(ksession.getProcessInstance(processInstance.getId())); } finally { // This should clean up all listeners, but doesn't -> see docs above ksession.dispose(); } }
public static final void main(String[] args) { try { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000); HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler); // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("employee", "krisv"); params.put("reason", "Yearly performance evaluation"); ksession.startProcess("com.sample.evaluation", params); SystemEventListenerFactory.setSystemEventListener(new SystemEventListener()); TaskService taskClient = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient("EvaluationExample2-testClient")); taskClient.connect("127.0.0.1", 5153); Thread.sleep(1000); // "krisv" executes his own performance evaluation TaskSummary task1 = taskClient.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0); System.out.println( "Krisv executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")"); taskClient.start(task1.getId(), "krisv"); taskClient.complete(task1.getId(), "krisv", null); Thread.sleep(1000); // "john", part of the "PM" group, executes a performance evaluation List<String> groups = new ArrayList<String>(); groups.add("PM"); TaskSummary task2 = taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK").get(0); System.out.println( "John executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")"); taskClient.claim(task2.getId(), "john", groups); taskClient.start(task2.getId(), "john"); taskClient.complete(task2.getId(), "john", null); Thread.sleep(1000); // "mary", part of the "HR" group, delegates a performance evaluation groups = new ArrayList<String>(); groups.add("HR"); TaskSummary task3 = taskClient.getTasksAssignedAsPotentialOwner("mary", groups, "en-UK").get(0); System.out.println( "Mary delegating task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ") to krisv"); taskClient.claim(task3.getId(), "mary", groups); taskClient.delegate(task3.getId(), "mary", "krisv"); // "administrator" delegates the task back to mary System.out.println("Administrator delegating task back to mary"); taskClient.delegate(task3.getId(), "Administrator", "mary"); Thread.sleep(1000); // mary executing the task TaskSummary task3b = taskClient.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0); System.out.println( "Mary executing task " + task3b.getName() + "(" + task3b.getId() + ": " + task3b.getDescription() + ")"); taskClient.start(task3b.getId(), "mary"); taskClient.complete(task3b.getId(), "mary", null); taskClient.disconnect(); hornetQHTWorkItemHandler.dispose(); Thread.sleep(1000); logger.close(); System.exit(0); } catch (Throwable t) { t.printStackTrace(); } }
public void testWorkItem() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"UserName\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </variable>\n" + " <variable name=\"Person\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.Person\" />\n" + " </variable>\n" + " <variable name=\"MyObject\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " <variable name=\"Number\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.IntegerDataType\" />\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <workItem id=\"2\" name=\"HumanTask\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>#{UserName}</value>\n" + " </parameter>\n" + " <parameter name=\"Content\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>#{Person.name}</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Attachment\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " <mapping type=\"in\" from=\"MyObject\" to=\"Attachment\" />" + " <mapping type=\"in\" from=\"Person.name\" to=\"Comment\" />" + " <mapping type=\"out\" from=\"Result\" to=\"MyObject\" />" + " <mapping type=\"out\" from=\"Result.length()\" to=\"Number\" />" + " </workItem>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>"); kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("UserName", "John Doe"); Person person = new Person(); person.setName("John Doe"); parameters.put("Person", person); WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); WorkItem workItem = handler.getWorkItem(); assertNotNull(workItem); assertEquals("John Doe", workItem.getParameter("ActorId")); assertEquals("John Doe", workItem.getParameter("Content")); assertEquals("John Doe", workItem.getParameter("Comment")); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); parameters = new HashMap<String, Object>(); parameters.put("UserName", "Jane Doe"); parameters.put("MyObject", "SomeString"); person = new Person(); person.setName("Jane Doe"); parameters.put("Person", person); processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); workItem = handler.getWorkItem(); assertNotNull(workItem); assertEquals("Jane Doe", workItem.getParameter("ActorId")); assertEquals("SomeString", workItem.getParameter("Attachment")); assertEquals("Jane Doe", workItem.getParameter("Content")); assertEquals("Jane Doe", workItem.getParameter("Comment")); Map<String, Object> results = new HashMap<String, Object>(); results.put("Result", "SomeOtherString"); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); assertEquals("SomeOtherString", processInstance.getVariable("MyObject")); assertEquals(15, processInstance.getVariable("Number")); }