use of org.activiti.api.task.model.impl.TaskImpl 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.impl.TaskImpl 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);
}
use of org.activiti.api.task.model.impl.TaskImpl in project Activiti by Activiti.
the class TaskRuntimeHelperTest method updateShouldBeAbleToUpdateDescriptionOnly.
@Test
public void updateShouldBeAbleToUpdateDescriptionOnly() {
// given
TaskImpl task = new TaskImpl();
String assignee = AUTHENTICATED_USER;
task.setAssignee(assignee);
Task internalTask = buildInternalTask(assignee);
doReturn(internalTask).when(taskRuntimeHelper).getInternalTaskWithChecks("taskId");
doReturn(internalTask).when(taskRuntimeHelper).getInternalTask("taskId");
TaskQuery taskQuery = mock(TaskQuery.class);
given(taskQuery.taskId("taskId")).willReturn(taskQuery);
given(taskService.createTaskQuery()).willReturn(taskQuery);
TaskRuntimeHelper taskUpdater = mock(TaskRuntimeHelper.class);
given(taskQuery.singleResult()).willReturn(internalTask);
when(taskUpdater.getInternalTaskWithChecks(any())).thenReturn(internalTask);
when(taskConverter.from(any(Task.class))).thenReturn(task);
UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").build();
// when
taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload);
// then
verify(internalTask).getDescription();
verify(internalTask).setDescription("new description");
verify(taskService).saveTask(internalTask);
}
use of org.activiti.api.task.model.impl.TaskImpl in project Activiti by Activiti.
the class APITaskConverter method from.
public Task from(org.activiti.engine.task.Task internalTask, Task.TaskStatus status) {
TaskImpl task = new TaskImpl(internalTask.getId(), internalTask.getName(), status);
task.setProcessDefinitionId(internalTask.getProcessDefinitionId());
task.setProcessInstanceId(internalTask.getProcessInstanceId());
task.setAssignee(internalTask.getAssignee());
task.setClaimedDate(internalTask.getClaimTime());
task.setCreatedDate(internalTask.getCreateTime());
task.setDueDate(internalTask.getDueDate());
task.setDescription(internalTask.getDescription());
task.setOwner(internalTask.getOwner());
task.setParentTaskId(internalTask.getParentTaskId());
task.setPriority(internalTask.getPriority());
task.setFormKey(internalTask.getFormKey());
task.setTaskDefinitionKey(internalTask.getTaskDefinitionKey());
task.setAppVersion(Objects.toString(internalTask.getAppVersion(), null));
task.setBusinessKey(internalTask.getBusinessKey());
return task;
}
use of org.activiti.api.task.model.impl.TaskImpl in project Activiti by Activiti.
the class TaskRuntimeImplTest method should_returnResultOfHelper_when_updateTask.
@Test
public void should_returnResultOfHelper_when_updateTask() {
// given
UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").build();
TaskImpl updatedTask = new TaskImpl();
given(taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload)).willReturn(updatedTask);
// when
Task retrievedTask = taskRuntime.update(updateTaskPayload);
// then
assertThat(retrievedTask).isEqualTo(updatedTask);
}
Aggregations