APITaskConverter extends ListConverter<org.activiti.engine.task.Task, Task> implements ModelConverter<org.activiti.engine.task.Task, Task> { @Override public Task from(org.activiti.engine.task.Task internalTask) { return from(internalTask, calculateStatus(internalTask)); } @Autowired  APITaskConverter(TaskService taskService); @Override Task from(org.activiti.engine.task.Task internalTask); Task fromWithCandidates(org.activiti.engine.task.Task internalTask); Task from(org.activiti.engine.task.Task internalTask,
        Task.TaskStatus status); Task fromWithCompletedBy(org.activiti.engine.task.Task internalTask,
        Task.TaskStatus status, String completedBy);  }
@Test public void should_convertTask_when_allFieldsAreSet() { Date now = new Date(); Task convertedTask = taskConverter.from( taskBuilder() .withId("testTaskId") .withAssignee("testUser") .withName("testTaskName") .withDescription("testTaskDescription") .withCreatedDate(now) .withClaimedDate(now) .withDueDate(now) .withPriority(112) .withProcessDefinitionId("testProcessDefinitionId") .withProcessInstanceId("testProcessInstanceId") .withParentTaskId("testParentTaskId") .withFormKey("testFormKey") .withTaskDefinitionKey("taskDefinitionKey") .withAppVersion(1) .withBusinessKey("businessKey") .build() ); assertThat(convertedTask) .isNotNull() .extracting(Task::getId, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getClaimedDate, Task::getDueDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getStatus, Task::getTaskDefinitionKey, Task::getAppVersion, Task::getBusinessKey) .containsExactly("testTaskId", "testUser", "testTaskName", "testTaskDescription", now, now, now, 112, "testProcessDefinitionId", "testProcessInstanceId", "testParentTaskId", "testFormKey", ASSIGNED, "taskDefinitionKey", "1", "businessKey"); }
@Test public void should_convertTask_when_appVersionNull() { Task convertedTask = taskConverter.from(taskBuilder().withAppVersion(null).build()); assertThat(convertedTask) .isNotNull() .extracting(Task::getAppVersion) .isNull(); }
@Test public void calculateStatusForACancelledTaskShouldReturnCancelled() { assertThat(taskConverter.from(taskEntityBuilder().withCancelled(true).build())) .isNotNull() .extracting(Task::getStatus) .isEqualTo(CANCELLED); }
@Test public void calculateStatusForASuspendedTaskShouldReturnSuspended() { assertThat(taskConverter.from(taskEntityBuilder().withSuspended(true).build())) .isNotNull() .extracting(Task::getStatus) .isEqualTo(SUSPENDED); }
@Test public void calculateStatusForAnAssignedTaskShouldReturnAssigned() { assertThat(taskConverter.from(taskBuilder().withAssignee("testUser").build())) .isNotNull() .extracting(Task::getStatus) .isEqualTo(ASSIGNED); }
@Test public void calculateStatusCreatedAndNotAssignedTaskShouldReturnCreated() { assertThat(taskConverter.from(taskBuilder().build())) .isNotNull() .extracting(Task::getStatus) .isEqualTo(CREATED); }