KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
// start a new process instance
ProcessInstance processInstance = (ProcessInstance) ksession.startProcess("org.drools.dynamic");
DynamicNodeInstance dynamicContext = (DynamicNodeInstance)
((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("TaskName", "Dynamic Task");
assertNull(handler.getWorkItem());
assertEquals(0, dynamicContext.getNodeInstances().size());
DynamicUtils.addDynamicWorkItem(dynamicContext, ksession, "Human Task", parameters);
assertNotNull(handler.getWorkItem());
assertEquals(1, dynamicContext.getNodeInstances().size());
logger.close();
}