Search in sources :

Example 71 with Classification

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));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) ArrayList(java.util.ArrayList) WorkbasketSummary(pro.taskana.WorkbasketSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 72 with Classification

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;
    }
}
Also used : TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with Classification

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)));
}
Also used : Task(pro.taskana.Task) ArrayList(java.util.ArrayList) Classification(pro.taskana.Classification) WorkbasketSummary(pro.taskana.WorkbasketSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with Classification

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;
    }
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) SystemException(pro.taskana.exceptions.SystemException) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 75 with Classification

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;
    }
}
Also used : Classification(pro.taskana.Classification) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) SystemException(pro.taskana.exceptions.SystemException) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Classification (pro.taskana.Classification)102 Test (org.junit.Test)88 Task (pro.taskana.Task)32 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 AbstractAccTest (acceptance.AbstractAccTest)23 WithAccessId (pro.taskana.security.WithAccessId)21 ClassificationSummary (pro.taskana.ClassificationSummary)20 Workbasket (pro.taskana.Workbasket)18 Connection (java.sql.Connection)14 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)13 TaskAlreadyExistException (pro.taskana.exceptions.TaskAlreadyExistException)11 ClassificationService (pro.taskana.ClassificationService)10 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)10 ConcurrencyException (pro.taskana.exceptions.ConcurrencyException)10 InvalidOwnerException (pro.taskana.exceptions.InvalidOwnerException)10 InvalidStateException (pro.taskana.exceptions.InvalidStateException)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)10 SystemException (pro.taskana.exceptions.SystemException)10