Search in sources :

Example 26 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testPriorityUpdate.

private void testPriorityUpdate(int oldPriority, int newPriority, boolean changeExpected) {
    Task task = new TaskFluent().setPriority(oldPriority).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    taskService.setPriority(taskId, newPriority);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getPriority()).isEqualTo(newPriority);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getPriority()).isEqualTo(newPriority);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldPriority), String.valueOf(newPriority));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) TaskEvent(org.kie.internal.task.api.model.TaskEvent) AuditTask(org.kie.internal.task.api.AuditTask)

Example 27 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testVariableIndexInputAndOutput.

@Test
public void testVariableIndexInputAndOutput() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("firstVariable", "string content");
    inputVariables.put("number", 1234);
    taskService.addTask(task, inputVariables);
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    List<TaskVariable> inputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.INPUT).build().getResultList();
    assertNotNull(inputVars);
    assertEquals(2, inputVars.size());
    Map<String, String> vars = collectVariableNameAndValue(inputVars);
    assertTrue(vars.containsKey("firstVariable"));
    assertTrue(vars.containsKey("number"));
    assertEquals("string content", vars.get("firstVariable"));
    assertEquals("1234", vars.get("number"));
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Reserved"));
    taskService.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    Map<String, Object> outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", "updated content");
    outputVariables.put("age", 25);
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", outputVariables);
    List<TaskVariable> outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
    assertNotNull(outputVars);
    assertEquals(2, outputVars.size());
    Map<String, String> outvars = collectVariableNameAndValue(outputVars);
    assertTrue(outvars.containsKey("reply"));
    assertTrue(outvars.containsKey("age"));
    assertEquals("updated content", outvars.get("reply"));
    assertEquals("25", outvars.get("age"));
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) TaskVariable(org.kie.internal.task.api.TaskVariable) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 28 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TotalCompletionTimeAssignmentStrategyTest method forceBAMEntries.

/**
 * Creates tasks and completes them so that there is
 * BAMTaskSummary data
 */
private void forceBAMEntries() {
    for (int count = 0; count < 10; count++) {
        TaskFluent task1 = new TaskFluent().setName("MultiUserLoadBalanceTask1").addPotentialUser(BOBBA_FET).addPotentialUser(DARTH_VADER).addPotentialUser(LUKE_CAGE).setAdminUser("Administrator").setDeploymentID(DEPLOYMENT_ID).setProcessId(PROCESS_ID);
        long taskId = createTaskWithoutAssert(task1);
        int waitTime = 100;
        if (count % 3 == 0) {
            waitTime = 230;
        } else if (count % 2 == 0) {
            waitTime = 180;
        }
        completeTask(taskId, waitTime);
    }
    for (int count = 0; count < 10; count++) {
        TaskFluent task2 = new TaskFluent().setName("MultiUserLoadBalanceTask2").addPotentialUser(BOBBA_FET).addPotentialUser(DARTH_VADER).addPotentialUser(LUKE_CAGE).setAdminUser("Administrator").setDeploymentID(DEPLOYMENT_ID).setProcessId(PROCESS_ID);
        long taskId = createTaskWithoutAssert(task2);
        int waitTime = 1000;
        if (count % 3 == 0) {
            waitTime = 2300;
        } else if (count % 2 == 0) {
            waitTime = 1800;
        }
        completeTask(taskId, waitTime);
    }
}
Also used : TaskFluent(org.jbpm.services.task.utils.TaskFluent)

Example 29 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TotalCompletionTimeAssignmentStrategyTest method testMultipleUser.

@Test
public void testMultipleUser() {
    String[] expectedOwners = Arrays.array(BOBBA_FET, DARTH_VADER, LUKE_CAGE);
    // Everyone gets two of these tasks to start
    for (int x = 0; x < 6; x++) {
        TaskFluent task1 = new TaskFluent().setName("MultiUserLoadBalanceTask1").addPotentialUser(BOBBA_FET).addPotentialUser(DARTH_VADER).addPotentialUser(LUKE_CAGE).setDeploymentID(DEPLOYMENT_ID).setProcessId(PROCESS_ID).setAdminUser("Administrator");
        taskIds[x] = createAndAssertTask(task1, expectedOwners[x % 3]);
    }
    // Complete Darth's first task
    completeTask(taskIds[1], 500);
    // Darth moves to the front since
    // he has less active tasks
    TaskFluent task2 = new TaskFluent().setName("MultiUserLoadBalanceTask2").addPotentialUser(BOBBA_FET).addPotentialUser(DARTH_VADER).addPotentialUser(LUKE_CAGE).setDeploymentID(DEPLOYMENT_ID).setProcessId(PROCESS_ID).setAdminUser("Administrator");
    createAndAssertTask(task2, DARTH_VADER);
    logger.info("testMultipleUser completed");
}
Also used : TaskFluent(org.jbpm.services.task.utils.TaskFluent) Test(org.junit.Test)

Example 30 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class AuditTaskDeleteTest method produceTaskInstances.

private void produceTaskInstances() {
    InternalTaskService taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    Calendar cal = randomCal();
    String processId = "process";
    taskTestData = new Task[10];
    List<ProcessInstanceLog> pLogs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").setProcessId(processId + i).setProcessInstanceId(i).setCreatedOn(cal.getTime()).getTask();
        taskService.addTask(task, new HashMap<String, Object>());
        taskTestData[i] = task;
        ProcessInstanceLog plog = buildCompletedProcessInstance(i);
        pLogs.add(plog);
    }
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    Object tx = jtaHelper.joinTransaction(em);
    pLogs.forEach(pl -> {
        em.persist(pl);
    });
    jtaHelper.leaveTransaction(em, tx);
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskFluent(org.jbpm.services.task.utils.TaskFluent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) EntityManager(javax.persistence.EntityManager) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Aggregations

TaskFluent (org.jbpm.services.task.utils.TaskFluent)31 Task (org.kie.api.task.model.Task)26 AuditTask (org.kie.internal.task.api.AuditTask)25 Test (org.junit.Test)24 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)20 QueryFilter (org.kie.internal.query.QueryFilter)17 TaskSummary (org.kie.api.task.model.TaskSummary)14 HashMap (java.util.HashMap)9 TaskEvent (org.kie.internal.task.api.model.TaskEvent)8 TaskVariable (org.kie.internal.task.api.TaskVariable)7 ArrayList (java.util.ArrayList)4 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)2 I18NText (org.kie.api.task.model.I18NText)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 EntityManager (javax.persistence.EntityManager)1 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)1 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)1 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)1