Search in sources :

Example 1 with WithAccessId

use of pro.taskana.security.WithAccessId 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 WithAccessId

use of pro.taskana.security.WithAccessId 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 WithAccessId

use of pro.taskana.security.WithAccessId 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 WithAccessId

use of pro.taskana.security.WithAccessId 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 WithAccessId

use of pro.taskana.security.WithAccessId 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

Test (org.junit.Test)216 WithAccessId (pro.taskana.security.WithAccessId)216 AbstractAccTest (acceptance.AbstractAccTest)201 TaskService (pro.taskana.TaskService)100 WorkbasketService (pro.taskana.WorkbasketService)78 Task (pro.taskana.Task)57 WorkbasketSummary (pro.taskana.WorkbasketSummary)51 TaskSummary (pro.taskana.TaskSummary)47 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)34 Workbasket (pro.taskana.Workbasket)23 Classification (pro.taskana.Classification)21 KeyDomain (pro.taskana.KeyDomain)19 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)19 ArrayList (java.util.ArrayList)17 Instant (java.time.Instant)16 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)16 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)15 Connection (java.sql.Connection)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 TimeInterval (pro.taskana.TimeInterval)8