Search in sources :

Example 6 with Attachment

use of pro.taskana.Attachment 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 7 with Attachment

use of pro.taskana.Attachment 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)

Example 8 with Attachment

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

the class TaskServiceImplTest method testUpdateTaskAddingAttachmentWithSameIdForcedUsingingListMethod.

@Test(expected = AttachmentPersistenceException.class)
public void testUpdateTaskAddingAttachmentWithSameIdForcedUsingingListMethod() 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);
    taskBeforeAttachment.setModified(null);
    taskBeforeAttachment.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBeforeAttachment.getCreated());
    task.setPrimaryObjRef(objectReference);
    task.setAttachments(new ArrayList<>());
    task.getAttachments().add(attachment);
    task.getAttachments().add(attachment);
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    doReturn(taskBeforeAttachment).when(cutSpy).getTask(task.getId());
    doThrow(PersistenceException.class).when(attachmentMapperMock).insert(any());
    try {
        cutSpy.updateTask(task);
    } catch (AttachmentPersistenceException e) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(cutSpy, times(1)).getTask(task.getId());
        verify(attachmentMapperMock, times(1)).insert(((AttachmentImpl) attachment));
        verify(taskanaEngineMock, times(1)).returnConnection();
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) Workbasket(pro.taskana.Workbasket) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Attachment

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

the class TaskServiceImplTest method testUpdateTaskAddingValidAttachmentTwice.

@Test
public void testUpdateTaskAddingValidAttachmentTwice() 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);
    taskBeforeAttachment.setModified(null);
    taskBeforeAttachment.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBeforeAttachment.getCreated());
    task.setPrimaryObjRef(objectReference);
    task.addAttachment(attachment);
    task.addAttachment(attachment);
    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)

Example 10 with Attachment

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

the class TaskServiceImplTest method testUpdateTaskUpdateAttachment.

@Test
public void testUpdateTaskUpdateAttachment() throws TaskNotFoundException, SystemException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException {
    String channelUpdate = "OTHER CHANNEL";
    Classification classification = createDummyClassification();
    Workbasket wb = createWorkbasket("WB-ID", "WB-Key");
    Attachment attachment = JunitHelper.createDefaultAttachment();
    Attachment attachmentToUpdate = JunitHelper.createDefaultAttachment();
    attachmentToUpdate.setChannel(channelUpdate);
    ObjectReference objectReference = JunitHelper.createDefaultObjRef();
    TaskImpl taskBefore = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    taskBefore.addAttachment(attachment);
    TaskImpl task = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    taskBefore.setModified(null);
    taskBefore.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBefore.getCreated());
    task.addAttachment(taskBefore.getAttachments().get(0));
    task.setPrimaryObjRef(objectReference);
    // should override old one and differ at comparison
    task.addAttachment(attachmentToUpdate);
    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)).update(((AttachmentImpl) attachmentToUpdate));
    verify(taskanaEngineMock, times(1)).returnConnection();
    assertThat(actualTask.getAttachments().size(), equalTo(1));
    assertThat(actualTask.getAttachments().get(0).getChannel(), equalTo(channelUpdate));
}
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

Attachment (pro.taskana.Attachment)28 Test (org.junit.Test)17 Classification (pro.taskana.Classification)9 AbstractAccTest (acceptance.AbstractAccTest)7 ClassificationSummary (pro.taskana.ClassificationSummary)7 WithAccessId (pro.taskana.security.WithAccessId)7 Task (pro.taskana.Task)6 Workbasket (pro.taskana.Workbasket)6 Duration (java.time.Duration)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)4 SystemException (pro.taskana.exceptions.SystemException)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)3 AttachmentSummary (pro.taskana.AttachmentSummary)2 TaskService (pro.taskana.TaskService)2 TaskSummary (pro.taskana.TaskSummary)2 WorkbasketSummary (pro.taskana.WorkbasketSummary)2