use of org.activiti.api.task.model.payloads.UpdateTaskPayload in project Activiti by Activiti.
the class TaskRuntimeHelperTest method applyUpdateTaskPayloadShouldThrowExceptionWhenAssigneeIsNotSetAndIsNotAdmin.
@Test
public void applyUpdateTaskPayloadShouldThrowExceptionWhenAssigneeIsNotSetAndIsNotAdmin() {
// given
TaskQuery taskQuery = mock(TaskQuery.class);
given(taskService.createTaskQuery()).willReturn(taskQuery);
given(taskQuery.taskCandidateOrAssigned(any(), any())).willReturn(taskQuery);
given(taskQuery.taskId("taskId")).willReturn(taskQuery);
Task internalTask = mock(Task.class);
doReturn(internalTask).when(taskRuntimeHelper).getInternalTaskWithChecks("taskId");
UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").build();
// when
Throwable throwable = catchThrowable(() -> taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload));
// then
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("You cannot update a task where you are not the assignee");
}
use of org.activiti.api.task.model.payloads.UpdateTaskPayload 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.payloads.UpdateTaskPayload in project Activiti by Activiti.
the class TaskRuntimeHelperTest method updateShouldSetAllFieldsAndSaveChangesWhenAssignee.
@Test
public void updateShouldSetAllFieldsAndSaveChangesWhenAssignee() {
// given
Date now = new Date();
UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").withName("New name").withPriority(42).withDueDate(now).withFormKey("new form key").build();
Task internalTask = buildInternalTask(AUTHENTICATED_USER);
doReturn(internalTask).when(taskRuntimeHelper).getInternalTaskWithChecks("taskId");
doReturn(internalTask).when(taskRuntimeHelper).getInternalTask("taskId");
// when
taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload);
// then
verify(internalTask).setDescription("new description");
verify(internalTask).setName("New name");
verify(internalTask).setPriority(42);
verify(internalTask).setDueDate(now);
verify(internalTask).setFormKey("new form key");
verify(taskService).saveTask(internalTask);
}
use of org.activiti.api.task.model.payloads.UpdateTaskPayload 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);
}
use of org.activiti.api.task.model.payloads.UpdateTaskPayload in project Activiti by Activiti.
the class TaskRuntimeUpdateTaskTest method createClaimAndUpdateStandaloneTask.
@Test
public void createClaimAndUpdateStandaloneTask() {
securityUtil.logInAs("garth");
// create
Task standaloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("test task update").withDescription("test task update description").withDueDate(new Date()).withPriority(50).withCandidateUsers("garth").build());
assertThat(RuntimeTestConfiguration.createdTasks).contains(standaloneTask.getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).extracting("status", "id").contains(tuple(Task.TaskStatus.CREATED, standaloneTask.getId()));
final UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId(standaloneTask.getId()).withName(standaloneTask.getName() + " [UPDATED]").withPriority(60).withDueDate(new Date()).withDescription(standaloneTask.getDescription() + " [UPDATED]").build();
// try update
// task should be claimed before be updated
Throwable thrown = catchThrowable(() -> taskRuntime.update(updateTaskPayload));
assertThat(thrown).isInstanceOf(IllegalStateException.class).hasMessage("You cannot update a task where you are not the assignee");
// claim
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(standaloneTask.getId()).build());
// update
final Task updatedTask = taskRuntime.update(updateTaskPayload);
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(RuntimeTestConfiguration.updatedTasks).contains(updatedTask.getId());
assertThat(tasks.getContent()).extracting("status", "id").contains(tuple(Task.TaskStatus.ASSIGNED, standaloneTask.getId()));
}
Aggregations