Search in sources :

Example 1 with Workbasket

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

the class CreateWorkbasketAccTest method testCreateWorkbasketNotAuthorized.

@WithAccessId(userName = "dummy")
@Test(expected = NotAuthorizedException.class)
public void testCreateWorkbasketNotAuthorized() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket workbasket = workbasketService.newWorkbasket("key3", "DOMAIN_A");
    workbasket.setName("Megabasket");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    workbasketService.createWorkbasket(workbasket);
    fail("NotAuthorizedException should have been thrown");
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 2 with Workbasket

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

the class CreateWorkbasketAccTest method testCreateWorkbasketWithInvalidDomain.

@WithAccessId(userName = "user_1_2", groupNames = { "businessadmin" })
@Test(expected = DomainNotFoundException.class)
public void testCreateWorkbasketWithInvalidDomain() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket workbasket = workbasketService.newWorkbasket("key3", "UNKNOWN_DOMAIN");
    workbasket.setName("Megabasket");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    workbasketService.createWorkbasket(workbasket);
    fail("DomainNotFoundException should have been thrown");
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 3 with Workbasket

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

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

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

Aggregations

Workbasket (pro.taskana.Workbasket)62 Test (org.junit.Test)47 WithAccessId (pro.taskana.security.WithAccessId)23 AbstractAccTest (acceptance.AbstractAccTest)18 Task (pro.taskana.Task)18 Classification (pro.taskana.Classification)17 WorkbasketService (pro.taskana.WorkbasketService)13 ArrayList (java.util.ArrayList)11 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)10 WorkbasketSummary (pro.taskana.WorkbasketSummary)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)7 Attachment (pro.taskana.Attachment)6 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)6 Instant (java.time.Instant)5 Transactional (org.springframework.transaction.annotation.Transactional)5 WorkbasketResource (pro.taskana.rest.resource.WorkbasketResource)5 Connection (java.sql.Connection)4