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);
}
}
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"));
}
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);
}
}
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");
}
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);
}
Aggregations