use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testAdHocProcessDynamicSubProcess.
@Test
public void testAdHocProcessDynamicSubProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-AdHocProcess.bpmn2", "BPMN2-MinimalProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ProcessInstance processInstance = ksession.startProcess("AdHocProcess");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
logger.debug("Triggering node");
ksession.signalEvent("Task1", null, processInstance.getId());
assertProcessInstanceActive(processInstance);
TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
DynamicUtils.addDynamicSubProcess(processInstance, ksession, "Minimal", new HashMap<String, Object>());
ksession = restoreSession(ksession, true);
ksession.signalEvent("User1", null, processInstance.getId());
assertProcessInstanceActive(processInstance);
ksession.insert(new Person());
ksession.signalEvent("Task3", null, processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class WorkItemPersistenceTest method testCancelNonRegisteredWorkItemHandler.
@Test
@Ignore
public void testCancelNonRegisteredWorkItemHandler() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
((KnowledgeBaseImpl) kbase).addProcess(process);
KieSession ksession = createSession(kbase);
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());
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class WorkItemPersistenceTest method testHumanTask.
@Test
public void testHumanTask() {
List<ProcessInstanceInfo> procInstInfoList = retrieveProcessInstanceInfo(emf);
int numProcInstInfos = procInstInfoList.size();
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.humantask\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <humanTask id=\"2\" name=\"HumanTask\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " </humanTask>\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>");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createSession(kbase);
final List<WorkItem> workItems = new ArrayList<WorkItem>();
DoNothingWorkItemHandler handler = new DoNothingWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
super.executeWorkItem(workItem, manager);
workItems.add(workItem);
}
};
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("org.drools.humantask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
int state = processInstance.getState();
switch(state) {
case ProcessInstance.STATE_ABORTED:
logger.debug("STATE_ABORTED");
break;
case ProcessInstance.STATE_ACTIVE:
logger.debug("STATE_ACTIVE");
break;
case ProcessInstance.STATE_COMPLETED:
logger.debug("STATE_COMPLETED");
break;
case ProcessInstance.STATE_PENDING:
logger.debug("STATE_PENDING");
break;
case ProcessInstance.STATE_SUSPENDED:
logger.debug("STATE_SUSPENDED");
break;
default:
logger.debug("Unknown state: {}", state);
}
procInstInfoList = retrieveProcessInstanceInfo(emf);
assertTrue((procInstInfoList.size() - numProcInstInfos) == 1);
ProcessInstanceInfo processInstanceInfoMadeInThisTest = procInstInfoList.get(numProcInstInfos);
assertNotNull("ByteArray of ProcessInstanceInfo from this test is not filled and null!", processInstanceInfoMadeInThisTest.getProcessInstanceByteArray());
assertTrue("ByteArray of ProcessInstanceInfo from this test is not filled and empty!", processInstanceInfoMadeInThisTest.getProcessInstanceByteArray().length > 0);
assertEquals(1, workItems.size());
ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), null);
ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
assertNull(pi);
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class CleanupLogCommandWithProcessTest method testRunProcessWithAsyncHandler.
@Test
public void testRunProcessWithAsyncHandler() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new DoNothingWorkItemHandler());
return handlers;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
assertEquals(0, getProcessLogSize("ScriptTask"));
assertEquals(0, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Date startDate = new Date();
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
scheduleLogCleanup(false, true, false, startDate, "ScriptTask", "yyyy-MM-dd", manager.getIdentifier());
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
runtime.getKieSession().abortProcessInstance(processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(6, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Thread.sleep(1000);
scheduleLogCleanup(false, false, false, new Date(), "ScriptTask", "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
assertEquals(0, getProcessLogSize("ScriptTask"));
assertEquals(0, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class TimerMigrationManagerTest method createRuntimeManagers.
protected void createRuntimeManagers(String processV1, String processV2, ProcessEventListener... eventListeners) {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource(processV1), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
for (ProcessEventListener lister : eventListeners) {
listeners.add(lister);
}
return listeners;
}
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("MyTask", new DoNothingWorkItemHandler());
return handlers;
}
}).get();
RuntimeEnvironment environment2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource(processV2), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
for (ProcessEventListener lister : eventListeners) {
listeners.add(lister);
}
return listeners;
}
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("MyTask", new DoNothingWorkItemHandler());
return handlers;
}
}).get();
createRuntimeManager(environment, environment2);
}
Aggregations