use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeIT method should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent.
@Test
public void should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent() {
// given
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("taskToInitiatorProcess").build());
// when
Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasksForProcess(processInstance).build());
// then
assertThat(taskPage.getContent()).extracting(Task::getName, Task::getAssignee).containsExactly(tuple("my-task", INITIATOR));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method createStandaloneTaskAndSaveWithUnAuthorizedUser.
@Test()
public void createStandaloneTaskAndSaveWithUnAuthorizedUser() {
// given
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").build());
// Complete should fail with a different user
securityUtil.logInAs("user");
// when
Throwable throwable = catchThrowable(() -> taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(standAloneTask.getId()).withVariable("name", "value").build()));
// then
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method testSaveCompleteReviewOutcomeTasksProcessWithVariables.
@Test()
public void testSaveCompleteReviewOutcomeTasksProcessWithVariables() {
// given
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("name", "");
// when
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(COMPLETE_REVIEW_TASK_PROCESS).withVariables(startVariables).build());
// complete task
securityUtil.logInAs("garth");
Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", ""));
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task1.getId()).withVariable("name", "wrong").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build());
// reject task
securityUtil.logInAs("user");
Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables1 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build());
assertThat(variables1).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "wrong"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).withVariable("approved", false).build());
// fix task
securityUtil.logInAs("garth");
Task task3 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task3.getId()).withVariable("name", "correct").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task3.getId()).build());
// approve task
securityUtil.logInAs("user");
Task task4 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables2 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task4.getId()).build());
assertThat(variables2).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("name", "correct"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task4.getId()).withVariable("approved", true).build());
// then process completes
Throwable throwable = catchThrowable(() -> assertThat(processRuntime.processInstance(processInstance.getId())).isNull());
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeCandidatesTest method should_addAndRemoveCandidateUser.
@Test
public void should_addAndRemoveCandidateUser() {
RuntimeTestConfiguration.taskCandidateUserRemovedEvents.clear();
RuntimeTestConfiguration.taskCandidateUserAddedEvents.clear();
securityUtil.logInAs("garth");
Task createTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withCandidateUsers("garth").withAssignee(// but he should still be assigned the task
"dean").build());
// Check the task should be visible for dean
securityUtil.logInAs("dean");
// the target user should be able to see the task as well
TaskImpl task = (TaskImpl) taskRuntime.task(createTask.getId());
assertThat(task.getAssignee()).isEqualTo("dean");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
List<String> userCandidatesOnTask = task.getCandidateUsers();
assertThat(userCandidatesOnTask).hasSize(1);
List<String> userCandidates = taskRuntime.userCandidates(createTask.getId());
assertThat(userCandidates).hasSize(1);
taskRuntime.deleteCandidateUsers(TaskPayloadBuilder.deleteCandidateUsers().withTaskId(task.getId()).withCandidateUser("garth").build());
assertThat(RuntimeTestConfiguration.taskCandidateUserRemovedEvents).hasSize(1);
assertThat(RuntimeTestConfiguration.taskCandidateUserRemovedEvents).extracting(event -> event.getEntity().getUserId()).contains("garth");
task = (TaskImpl) taskRuntime.task(createTask.getId());
userCandidatesOnTask = task.getCandidateUsers();
assertThat(userCandidatesOnTask).isEmpty();
userCandidates = taskRuntime.userCandidates(createTask.getId());
assertThat(userCandidates).isEmpty();
taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("garth").build());
assertThat(RuntimeTestConfiguration.taskCandidateUserAddedEvents).hasSize(2);
assertThat(RuntimeTestConfiguration.taskCandidateUserAddedEvents).extracting(event -> event.getEntity().getUserId()).contains("garth", "garth");
task = (TaskImpl) taskRuntime.task(createTask.getId());
userCandidatesOnTask = task.getCandidateUsers();
assertThat(userCandidatesOnTask).hasSize(1);
userCandidates = taskRuntime.userCandidates(createTask.getId());
assertThat(userCandidates).hasSize(1);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeCandidatesTest method should_addAndRemoveCandidateGroup.
@Test
public void should_addAndRemoveCandidateGroup() {
clearTaskCandidateEvents();
securityUtil.logInAs("garth");
Task createTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withAssignee("garth").build());
taskRuntime.addCandidateGroups(TaskPayloadBuilder.addCandidateGroups().withTaskId(createTask.getId()).withCandidateGroup("test").build());
assertThat(RuntimeTestConfiguration.taskCandidateGroupAddedEvents).hasSize(1);
assertThat(RuntimeTestConfiguration.taskCandidateGroupAddedEvents).extracting(event -> event.getEntity().getGroupId()).contains("test");
TaskImpl task = (TaskImpl) taskRuntime.task(createTask.getId());
List<String> groupCandidatesOnTask = task.getCandidateGroups();
assertThat(groupCandidatesOnTask).hasSize(1);
List<String> groupCandidates = taskRuntime.groupCandidates(createTask.getId());
assertThat(groupCandidates).hasSize(1);
taskRuntime.deleteCandidateGroups(TaskPayloadBuilder.deleteCandidateGroups().withTaskId(task.getId()).withCandidateGroup("test").build());
assertThat(RuntimeTestConfiguration.taskCandidateGroupRemovedEvents).hasSize(1);
assertThat(RuntimeTestConfiguration.taskCandidateGroupRemovedEvents).extracting(event -> event.getEntity().getGroupId()).contains("test");
task = (TaskImpl) taskRuntime.task(createTask.getId());
groupCandidatesOnTask = task.getCandidateGroups();
assertThat(groupCandidatesOnTask).isEmpty();
groupCandidates = taskRuntime.groupCandidates(createTask.getId());
assertThat(groupCandidates).isEmpty();
taskRuntime.addCandidateGroups(TaskPayloadBuilder.addCandidateGroups().withTaskId(createTask.getId()).withCandidateGroup("test").build());
task = (TaskImpl) taskRuntime.task(createTask.getId());
groupCandidatesOnTask = task.getCandidateGroups();
assertThat(groupCandidatesOnTask).hasSize(1);
groupCandidates = taskRuntime.groupCandidates(createTask.getId());
assertThat(groupCandidates).hasSize(1);
}
Aggregations