Search in sources :

Example 1 with GenericHTWorkItemHandler

use of org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler in project jBPM5-Developer-Guide by Salaboy.

the class ProcessAndHumanTasksTest method testProcessWithHumanTasks.

@Test
public void testProcessWithHumanTasks() throws InterruptedException {
    StatefulKnowledgeSession ksession = this.initializeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    GenericHTWorkItemHandler htHandler = this.createTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);
    Map<String, Object> initialParams = new HashMap<String, Object>();
    initialParams.put("user_self_evaluation", "calcacuervo");
    ProcessInstance processInstance = ksession.startProcess("chapter_07_simple_review", initialParams);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    // first, calcacuervo will make its own review..
    List<TaskSummary> tasks = this.service.getTasksAssignedAsPotentialOwner("calcacuervo", "en-UK");
    assertEquals(1, tasks.size());
    this.service.start(tasks.get(0).getId(), "calcacuervo");
    this.service.complete(tasks.get(0).getId(), "calcacuervo", null);
    // now, a user with role TL will see the task.. esteban is one of them
    List<TaskSummary> estebanTasks = this.service.getTasksAssignedAsPotentialOwner("esteban", "en-UK");
    Assert.assertEquals(1, estebanTasks.size());
    this.service.claim(estebanTasks.get(0).getId(), "esteban");
    this.service.start(estebanTasks.get(0).getId(), "esteban");
    this.service.complete(estebanTasks.get(0).getId(), "esteban", null);
    // now, a user with role HR will see the task.. mariano is one of them
    List<TaskSummary> marianoTasks = this.service.getTasksAssignedAsPotentialOwner("mariano", "en-UK");
    Assert.assertEquals(1, marianoTasks.size());
    this.service.claim(marianoTasks.get(0).getId(), "mariano");
    this.service.start(marianoTasks.get(0).getId(), "mariano");
    this.service.complete(marianoTasks.get(0).getId(), "mariano", null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : GenericHTWorkItemHandler(org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) TaskSummary(org.jbpm.task.query.TaskSummary) ProcessInstance(org.drools.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)1 ProcessInstance (org.drools.runtime.process.ProcessInstance)1 GenericHTWorkItemHandler (org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler)1 TaskSummary (org.jbpm.task.query.TaskSummary)1 Test (org.junit.Test)1