Search in sources :

Example 1 with Attachment

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

the class UpdateTaskAttachmentsAccTest method testRemoveAttachment.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testRemoveAttachment() throws TaskNotFoundException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    task.addAttachment(attachment);
    task = taskService.updateTask(task);
    assertTrue(task.getPriority() == 99);
    assertTrue(task.getDue().equals(task.getPlanned().plus(Duration.ofDays(1))));
    int attachmentCount = task.getAttachments().size();
    Attachment attachmentToRemove = task.getAttachments().get(0);
    task.removeAttachment(attachmentToRemove.getId());
    task = taskService.updateTask(task);
    // locally, removed and not persisted
    assertThat(task.getAttachments().size(), equalTo(attachmentCount - 1));
    task = taskService.getTask(task.getId());
    // persisted, values removed
    assertThat(task.getAttachments().size(), equalTo(attachmentCount - 1));
    assertTrue(task.getPriority() == 1);
    assertTrue(task.getDue().equals(task.getPlanned().plus(Duration.ofDays(1))));
}
Also used : Attachment(pro.taskana.Attachment) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 2 with Attachment

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

the class UpdateTaskAttachmentsAccTest method replaceExistingAttachments.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void replaceExistingAttachments() throws TaskNotFoundException, ClassificationNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    // setup test
    assertThat(task.getAttachments().size(), equalTo(0));
    task.addAttachment(attachment);
    Attachment attachment2 = createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_B", "SYSTEM_C", "INSTANCE_C", "ArchiveId", "ABC45678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(4));
    task.addAttachment(attachment2);
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertThat(task.getAttachments().size(), equalTo(2));
    assertThat(task.getAttachments().get(0).getClassificationSummary().getKey(), equalTo("DOCTYPE_DEFAULT"));
    Attachment attachment3 = createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_C", "SYSTEM_7", "INSTANCE_7", "ArchiveId", "ABC4567890123456789012345678901234567890DEF"), "DHL", "2018-01-15", createSimpleCustomProperties(4));
    // replace existing attachments by new via addAttachment call
    task.getAttachments().clear();
    task.addAttachment(attachment3);
    task = taskService.updateTask(task);
    assertThat(task.getAttachments().size(), equalTo(1));
    assertThat(task.getAttachments().get(0).getChannel(), equalTo("DHL"));
    // setup environment for 2nd version of replacement (list.add call)
    task.getAttachments().add(attachment2);
    task = taskService.updateTask(task);
    assertThat(task.getAttachments().size(), equalTo(2));
    assertThat(task.getAttachments().get(1).getChannel(), equalTo("E-MAIL"));
    // replace attachments
    task.getAttachments().clear();
    task.getAttachments().add(attachment3);
    task = taskService.updateTask(task);
    assertThat(task.getAttachments().size(), equalTo(1));
    assertThat(task.getAttachments().get(0).getChannel(), equalTo("DHL"));
}
Also used : Attachment(pro.taskana.Attachment) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 3 with Attachment

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

the class UpdateTaskAttachmentsAccTest method testAddExistingAttachmentAgainWillDoNothingWhenEqual.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testAddExistingAttachmentAgainWillDoNothingWhenEqual() throws TaskNotFoundException, ClassificationNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    // Add Attachment before
    int attachmentCount = task.getAttachments().size();
    ((AttachmentImpl) attachment).setId("TAI:0001");
    task.addAttachment(attachment);
    // overwrite, same id
    task.addAttachment(attachment);
    // overwrite, same id
    task.addAttachment(attachment);
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertThat(task.getAttachments().size(), equalTo(attachmentCount + 1));
    // Add same again - ignored
    attachmentCount = task.getAttachments().size();
    Attachment redundantAttachment = task.getAttachments().get(0);
    task.addAttachment(redundantAttachment);
    task = taskService.updateTask(task);
    assertThat(task.getAttachments().size(), equalTo(attachmentCount));
}
Also used : AttachmentImpl(pro.taskana.impl.AttachmentImpl) Attachment(pro.taskana.Attachment) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 4 with Attachment

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

the class UpdateTaskAttachmentsAccTest method testUpdateAttachment.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testUpdateAttachment() throws TaskNotFoundException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    ((TaskImpl) task).setAttachments(new ArrayList<>());
    task = taskService.updateTask(task);
    assertTrue(task.getPriority() == 1);
    assertTrue(task.getDue().equals(task.getPlanned().plus(Duration.ofDays(1))));
    Attachment attachment = this.attachment;
    task.addAttachment(attachment);
    task = taskService.updateTask(task);
    assertTrue(task.getPriority() == 99);
    assertTrue(task.getDue().equals(task.getPlanned().plus(Duration.ofDays(1))));
    int attachmentCount = task.getAttachments().size();
    String newChannel = attachment.getChannel() + "-X";
    task.getAttachments().get(0).setChannel(newChannel);
    Classification newClassification = taskanaEngine.getClassificationService().getClassification(// Prio 999, SL PT5H
    "CLI:000000000000000000000000000000000001");
    task.getAttachments().get(0).setClassificationSummary(newClassification.asSummary());
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertThat(task.getAttachments().size(), equalTo(attachmentCount));
    assertThat(task.getAttachments().get(0).getChannel(), equalTo(newChannel));
    assertTrue(task.getPriority() == 999);
    assertTrue(task.getDue().equals(task.getPlanned()));
}
Also used : TaskImpl(pro.taskana.impl.TaskImpl) Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 5 with Attachment

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

the class UpdateTaskAttachmentsAccTest method testAddExistingAttachmentAgainWillUpdateWhenNotEqual.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testAddExistingAttachmentAgainWillUpdateWhenNotEqual() throws TaskNotFoundException, ClassificationNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    // Add attachment before
    task = taskService.getTask(task.getId());
    int attachmentCount = task.getAttachments().size();
    task.addAttachment(attachment);
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertThat(task.getAttachments().size(), equalTo(attachmentCount + 1));
    // Change sth. and add same (id) again - override/update
    String newChannel = "UPDATED EXTERNAL SINCE LAST ADD";
    attachmentCount = task.getAttachments().size();
    Attachment updatedAttachment = task.getAttachments().get(0);
    updatedAttachment.setChannel(newChannel);
    Classification newClassification = taskanaEngine.getClassificationService().getClassification(// Prio 999, SL PT5H
    "CLI:000000000000000000000000000000000001");
    updatedAttachment.setClassificationSummary(newClassification.asSummary());
    task.addAttachment(updatedAttachment);
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertThat(task.getAttachments().size(), equalTo(attachmentCount));
    assertThat(task.getAttachments().get(0).getChannel(), equalTo(newChannel));
    assertTrue(task.getPriority() == 999);
    assertTrue(task.getDue().equals(task.getPlanned()));
}
Also used : Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

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