Search in sources :

Example 11 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testUpdateTaskRemovingAttachment.

@Test
public void testUpdateTaskRemovingAttachment() throws TaskNotFoundException, SystemException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException {
    Classification classification = createDummyClassification();
    Workbasket wb = createWorkbasket("WB-ID", "WB-Key");
    Attachment attachment = JunitHelper.createDefaultAttachment();
    ObjectReference objectReference = JunitHelper.createDefaultObjRef();
    TaskImpl taskBefore = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    taskBefore.setPrimaryObjRef(objectReference);
    taskBefore.addAttachment(attachment);
    TaskImpl task = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    task.setPrimaryObjRef(objectReference);
    taskBefore.setModified(null);
    taskBefore.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBefore.getCreated());
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    doReturn(taskBefore).when(cutSpy).getTask(task.getId());
    Task actualTask = cutSpy.updateTask(task);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(cutSpy, times(1)).getTask(task.getId());
    verify(attachmentMapperMock, times(1)).deleteAttachment(attachment.getId());
    verify(taskanaEngineMock, times(1)).returnConnection();
    assertThat(actualTask.getAttachments().size(), equalTo(0));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) Workbasket(pro.taskana.Workbasket) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testSetTaskReadWIthExistingTask.

@Test
public void testSetTaskReadWIthExistingTask() throws TaskNotFoundException, ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    task.setModified(null);
    doReturn(task).when(cutSpy).getTask(task.getId());
    doNothing().when(taskMapperMock).update(task);
    Task actualTask = cutSpy.setTaskRead("1", true);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(taskMapperMock, times(1)).update(task);
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask.getModified(), not(equalTo(null)));
    assertThat(actualTask.isRead(), equalTo(true));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testTransferNotAuthorizationOnWorkbasketAppend.

@Test(expected = NotAuthorizedException.class)
public void testTransferNotAuthorizationOnWorkbasketAppend() 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());
    doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
    try {
        cutSpy.transfer(task.getId(), destinationWorkbasketId);
    } catch (Exception e) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
        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 14 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testTransferTaskDoesNotExist.

@Test(expected = TaskNotFoundException.class)
public void testTransferTaskDoesNotExist() throws Exception {
    Classification dummyClassification = createDummyClassification();
    Task task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
    try {
        cutSpy.transfer(task.getId(), "2");
    } 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 : 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 15 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testUpdateTaskAddingValidAttachment.

@Test
public void testUpdateTaskAddingValidAttachment() throws TaskNotFoundException, SystemException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException {
    Classification classification = createDummyClassification();
    Workbasket wb = createWorkbasket("WB-ID", "WB-Key");
    Attachment attachment = JunitHelper.createDefaultAttachment();
    ObjectReference objectReference = JunitHelper.createDefaultObjRef();
    TaskImpl taskBeforeAttachment = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    TaskImpl task = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    task.setPrimaryObjRef(objectReference);
    task.addAttachment(attachment);
    taskBeforeAttachment.setModified(null);
    taskBeforeAttachment.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBeforeAttachment.getCreated());
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    doReturn(taskBeforeAttachment).when(cutSpy).getTask(task.getId());
    Task actualTask = cutSpy.updateTask(task);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(cutSpy, times(1)).getTask(task.getId());
    verify(attachmentMapperMock, times(1)).insert(((AttachmentImpl) attachment));
    verify(taskanaEngineMock, times(1)).returnConnection();
    assertThat(actualTask.getAttachments().size(), equalTo(1));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) Workbasket(pro.taskana.Workbasket) 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