Search in sources :

Example 1 with UpdateTaskPayload

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");
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateTaskPayload

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);
}
Also used : Task(org.activiti.engine.task.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) TaskQuery(org.activiti.engine.task.TaskQuery) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateTaskPayload

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);
}
Also used : Task(org.activiti.engine.task.Task) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateTaskPayload

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);
}
Also used : Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Test(org.junit.jupiter.api.Test)

Example 5 with UpdateTaskPayload

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()));
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UpdateTaskPayload (org.activiti.api.task.model.payloads.UpdateTaskPayload)6 Test (org.junit.jupiter.api.Test)6 Date (java.util.Date)3 Task (org.activiti.api.task.model.Task)3 Task (org.activiti.engine.task.Task)3 TaskImpl (org.activiti.api.task.model.impl.TaskImpl)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2