use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImplTest method testGetTaskByIdWithExistingTask.
@Test
public void testGetTaskByIdWithExistingTask() throws TaskNotFoundException, ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException {
Classification dummyClassification = createDummyClassification();
Task expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(expectedTask.getId());
doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
List<WorkbasketSummary> wbList = new ArrayList<>();
WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
wb.setDomain("dummy-domain");
wbList.add(wb);
doReturn(wbList).when(workbasketQueryImplMock).list();
List<ClassificationSummaryImpl> classificationList = Arrays.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
doReturn(classificationList).when(classificationQueryImplMock).list();
Task actualTask = cut.getTask(expectedTask.getId());
verify(taskanaEngineMock, times(1)).openConnection();
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
verify(attachmentMapperMock, times(1)).findAttachmentsByTaskId(expectedTask.getId());
verify(classificationServiceImplMock, times(1)).createClassificationQuery();
verify(classificationQueryImplMock, times(1)).idIn(any());
verify(classificationQueryImplMock, times(1)).list();
verify(workbasketServiceMock, times(1)).createWorkbasketQuery();
verify(workbasketQueryImplMock, times(1)).idIn(any());
verify(workbasketQueryImplMock, times(1)).list();
verify(taskanaEngineMock, times(1)).returnConnection();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
assertThat(actualTask, equalTo(expectedTask));
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImplTest method testCreateTaskThrowingAlreadyExistException.
@Test(expected = TaskAlreadyExistException.class)
public void testCreateTaskThrowingAlreadyExistException() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, TaskAlreadyExistException, TaskNotFoundException, InvalidWorkbasketException, InvalidArgumentException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("12", "Task Name", "1", dummyClassification);
doReturn(task).when(cutSpy).getTask(task.getId());
try {
cutSpy.createTask(task);
} catch (TaskAlreadyExistException ex) {
verify(taskanaEngineMock, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).returnConnection();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock, classificationServiceImplMock);
throw ex;
}
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImplTest method testCompleteTaskDefault.
@Test
public void testCompleteTaskDefault() throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, InterruptedException, ClassificationNotFoundException, NotAuthorizedException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
final long sleepTime = 100L;
final boolean isForced = false;
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
Thread.sleep(sleepTime);
task.setState(TaskState.CLAIMED);
task.setClaimed(Instant.now());
task.setOwner(CurrentUserContext.getUserid());
doReturn(task).when(taskMapperMock).findById(task.getId());
doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(task.getId());
doReturn(task).when(cutSpy).completeTask(task.getId(), isForced);
doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
doReturn(new ArrayList<>()).when(classificationQueryImplMock).list();
List<ClassificationSummaryImpl> classificationList = Arrays.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
doReturn(classificationList).when(classificationQueryImplMock).list();
doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
List<WorkbasketSummary> wbList = new ArrayList<>();
WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
wb.setDomain("dummy-domain");
wbList.add(wb);
doReturn(wbList).when(workbasketQueryImplMock).list();
Task actualTask = cut.completeTask(task.getId());
verify(taskanaEngineMock, times(2)).openConnection();
verify(taskMapperMock, times(1)).findById(task.getId());
verify(attachmentMapperMock, times(1)).findAttachmentsByTaskId(task.getId());
verify(classificationServiceImplMock, times(1)).createClassificationQuery();
verify(classificationQueryImplMock, times(1)).idIn(any());
verify(classificationQueryImplMock, times(1)).list();
verify(taskMapperMock, times(1)).update(any());
verify(taskanaEngineMock, times(2)).returnConnection();
verify(workbasketServiceMock, times(1)).createWorkbasketQuery();
verify(workbasketQueryImplMock, times(1)).idIn(any());
verify(workbasketQueryImplMock, times(1)).list();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
assertThat(actualTask.getState(), equalTo(TaskState.COMPLETED));
assertThat(actualTask.getCreated(), not(equalTo(task.getModified())));
assertThat(actualTask.getCompleted(), not(equalTo(null)));
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImplTest method testTransferNotAuthorizationOnWorkbasketTransfer.
@Test(expected = NotAuthorizedException.class)
public void testTransferNotAuthorizationOnWorkbasketTransfer() throws Exception {
String destinationWorkbasketId = "2";
Classification dummyClassification = createDummyClassification();
Task task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
TaskServiceImpl cutSpy = Mockito.spy(cut);
doReturn(task).when(cutSpy).getTask(task.getId());
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.TRANSFER);
try {
cutSpy.transfer(task.getId(), destinationWorkbasketId);
} catch (Exception e) {
verify(taskanaEngineMock, times(1)).openConnection();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.TRANSFER);
verify(taskanaEngineMock, times(1)).returnConnection();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
throw e;
}
}
use of pro.taskana.Classification in project taskana by Taskana.
the class TaskServiceImplTest method testSetTaskReadTaskNotBeFound.
@Test(expected = TaskNotFoundException.class)
public void testSetTaskReadTaskNotBeFound() throws Exception {
TaskServiceImpl cutSpy = Mockito.spy(cut);
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
task.setModified(null);
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
try {
cutSpy.setTaskRead("1", true);
} catch (Exception e) {
verify(taskanaEngineMock, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).returnConnection();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
throw e;
}
}
Aggregations