Search in sources :

Example 21 with TaskFluent

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

the class TaskAuditBaseTest method testVariableIndexInputAndUpdateOutput.

@Test
public void testVariableIndexInputAndUpdateOutput() {
    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());
    // update task output
    Map<String, Object> outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", "updated content");
    outputVariables.put("age", 25);
    taskService.addOutputContentFromUser(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"));
    // Check is Complete
    outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", "completed content");
    outputVariables.put("age", 44);
    outputVariables.put("reason", "rework, please");
    taskService.complete(taskId, "Darth Vader", outputVariables);
    outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
    assertNotNull(outputVars);
    assertEquals(3, outputVars.size());
    outvars = collectVariableNameAndValue(outputVars);
    assertTrue(outvars.containsKey("reply"));
    assertTrue(outvars.containsKey("age"));
    assertTrue(outvars.containsKey("reason"));
    assertEquals("completed content", outvars.get("reply"));
    assertEquals("44", outvars.get("age"));
    assertEquals("rework, please", outvars.get("reason"));
}
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) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 22 with TaskFluent

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

the class TaskAuditBaseTest method testLifeCycleWithBAM.

@Test
public void testLifeCycleWithBAM() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<AuditTask> allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    taskService.release(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("InProgress", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "InProgress");
    taskService.stop(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    taskService.start(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("InProgress", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "InProgress");
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", null);
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Completed", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Completed");
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    Assertions.assertThat(taskEvents).hasSize(8);
    Assertions.assertThat(taskEvents.get(0).getType()).isEqualTo(TaskEventType.ADDED);
    Assertions.assertThat(taskEvents.get(0).getUserId()).isNull();
    Assertions.assertThat(taskEvents.get(1).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(1).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(2).getType()).isEqualTo(TaskEventType.RELEASED);
    Assertions.assertThat(taskEvents.get(2).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(3).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(3).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(4).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(4).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(5).getType()).isEqualTo(TaskEventType.STOPPED);
    Assertions.assertThat(taskEvents.get(5).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(6).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(6).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(7).getType()).isEqualTo(TaskEventType.COMPLETED);
    Assertions.assertThat(taskEvents.get(7).getUserId()).isEqualTo("Darth Vader");
}
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) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 23 with TaskFluent

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

the class TaskAuditBaseTest method testNameUpdate.

private void testNameUpdate(String oldName, String newName, boolean changeExpected) {
    Task task = new TaskFluent().setName(oldName).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<I18NText> taskNames = new ArrayList<I18NText>();
    taskNames.add(new I18NTextImpl("", newName));
    taskService.setTaskNames(taskId, taskNames);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getName()).isEqualTo(newName);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getName()).isEqualTo(newName);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldName), String.valueOf(newName));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) I18NText(org.kie.api.task.model.I18NText) TaskFluent(org.jbpm.services.task.utils.TaskFluent) ArrayList(java.util.ArrayList) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) TaskEvent(org.kie.internal.task.api.model.TaskEvent)

Example 24 with TaskFluent

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

the class TaskAuditBaseTest method testLifeCycleWithBAMEndWithFailed.

@Test
public void testLifeCycleWithBAMEndWithFailed() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<AuditTask> allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    taskService.release(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllGroupAuditTasksByUser("Knights Templer", new QueryFilter());
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatus().equals("Ready"));
    assertBAMTask(taskId, "Ready");
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Reserved", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Reserved");
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("InProgress", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "InProgress");
    taskService.fail(taskId, "Darth Vader", null);
    allGroupAuditTasks = taskAuditService.getAllAuditTasksByUser("Darth Vader", new QueryFilter());
    ;
    assertEquals(1, allGroupAuditTasks.size());
    assertEquals("Failed", allGroupAuditTasks.get(0).getStatus());
    assertBAMTask(taskId, "Failed");
}
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) AuditTask(org.kie.internal.task.api.AuditTask) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 25 with TaskFluent

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

the class TaskAuditBaseTest method testDescriptionUpdate.

private void testDescriptionUpdate(String oldDescription, String newDescription, boolean changeExpected) {
    Task task = new TaskFluent().setDescription(oldDescription).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<I18NText> descriptions = new ArrayList<I18NText>();
    descriptions.add(new I18NTextImpl("", newDescription));
    taskService.setDescriptions(taskId, descriptions);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getDescription()).isEqualTo(newDescription);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getDescription()).isEqualTo(newDescription);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldDescription), String.valueOf(newDescription));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) I18NText(org.kie.api.task.model.I18NText) TaskFluent(org.jbpm.services.task.utils.TaskFluent) ArrayList(java.util.ArrayList) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) TaskEvent(org.kie.internal.task.api.model.TaskEvent)

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