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));
}
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));
}
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;
}
}
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));
}
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));
}
Aggregations