Search in sources :

Example 6 with TaskImpl

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);
}
Also used : Task(org.activiti.api.task.model.Task) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskAdminRuntime(org.activiti.api.task.runtime.TaskAdminRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) TaskCleanUpUtil(org.activiti.spring.boot.test.util.TaskCleanUpUtil) Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with TaskImpl

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);
}
Also used : Task(org.activiti.api.task.model.Task) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskAdminRuntime(org.activiti.api.task.runtime.TaskAdminRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) TaskCleanUpUtil(org.activiti.spring.boot.test.util.TaskCleanUpUtil) Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with TaskImpl

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);
}
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 9 with TaskImpl

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;
}
Also used : TaskImpl(org.activiti.api.task.model.impl.TaskImpl)

Example 10 with TaskImpl

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

Aggregations

TaskImpl (org.activiti.api.task.model.impl.TaskImpl)11 Task (org.activiti.api.task.model.Task)7 Test (org.junit.jupiter.api.Test)5 List (java.util.List)2 TaskPayloadBuilder (org.activiti.api.task.model.builders.TaskPayloadBuilder)2 UpdateTaskPayload (org.activiti.api.task.model.payloads.UpdateTaskPayload)2 TaskAdminRuntime (org.activiti.api.task.runtime.TaskAdminRuntime)2 TaskRuntime (org.activiti.api.task.runtime.TaskRuntime)2 Task (org.activiti.engine.task.Task)2 RuntimeTestConfiguration (org.activiti.spring.boot.RuntimeTestConfiguration)2 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)2 TaskCleanUpUtil (org.activiti.spring.boot.test.util.TaskCleanUpUtil)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TaskCancelledEvent (org.activiti.api.task.runtime.events.TaskCancelledEvent)1 ActivitiEntityEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl)1 TaskQuery (org.activiti.engine.task.TaskQuery)1