Search in sources :

Example 31 with WorkbasketSummary

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

the class TaskServiceImplTest method testGetTaskByIdWithExistingTask.

@Test
public void testGetTaskByIdWithExistingTask() throws TaskNotFoundException, ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException {
    Classification dummyClassification = createDummyClassification();
    Task expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
    doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
    doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(expectedTask.getId());
    doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
    doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
    doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
    doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
    List<WorkbasketSummary> wbList = new ArrayList<>();
    WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
    wb.setDomain("dummy-domain");
    wbList.add(wb);
    doReturn(wbList).when(workbasketQueryImplMock).list();
    List<ClassificationSummaryImpl> classificationList = Arrays.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
    doReturn(classificationList).when(classificationQueryImplMock).list();
    Task actualTask = cut.getTask(expectedTask.getId());
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(taskMapperMock, times(1)).findById(expectedTask.getId());
    verify(attachmentMapperMock, times(1)).findAttachmentsByTaskId(expectedTask.getId());
    verify(classificationServiceImplMock, times(1)).createClassificationQuery();
    verify(classificationQueryImplMock, times(1)).idIn(any());
    verify(classificationQueryImplMock, times(1)).list();
    verify(workbasketServiceMock, times(1)).createWorkbasketQuery();
    verify(workbasketQueryImplMock, times(1)).idIn(any());
    verify(workbasketQueryImplMock, times(1)).list();
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask, equalTo(expectedTask));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) ArrayList(java.util.ArrayList) WorkbasketSummary(pro.taskana.WorkbasketSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with WorkbasketSummary

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

the class TaskServiceImplTest method testCompleteTaskDefault.

@Test
public void testCompleteTaskDefault() throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, InterruptedException, ClassificationNotFoundException, NotAuthorizedException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    final long sleepTime = 100L;
    final boolean isForced = false;
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    Thread.sleep(sleepTime);
    task.setState(TaskState.CLAIMED);
    task.setClaimed(Instant.now());
    task.setOwner(CurrentUserContext.getUserid());
    doReturn(task).when(taskMapperMock).findById(task.getId());
    doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(task.getId());
    doReturn(task).when(cutSpy).completeTask(task.getId(), isForced);
    doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
    doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
    doReturn(new ArrayList<>()).when(classificationQueryImplMock).list();
    List<ClassificationSummaryImpl> classificationList = Arrays.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
    doReturn(classificationList).when(classificationQueryImplMock).list();
    doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
    doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
    List<WorkbasketSummary> wbList = new ArrayList<>();
    WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
    wb.setDomain("dummy-domain");
    wbList.add(wb);
    doReturn(wbList).when(workbasketQueryImplMock).list();
    Task actualTask = cut.completeTask(task.getId());
    verify(taskanaEngineMock, times(2)).openConnection();
    verify(taskMapperMock, times(1)).findById(task.getId());
    verify(attachmentMapperMock, times(1)).findAttachmentsByTaskId(task.getId());
    verify(classificationServiceImplMock, times(1)).createClassificationQuery();
    verify(classificationQueryImplMock, times(1)).idIn(any());
    verify(classificationQueryImplMock, times(1)).list();
    verify(taskMapperMock, times(1)).update(any());
    verify(taskanaEngineMock, times(2)).returnConnection();
    verify(workbasketServiceMock, times(1)).createWorkbasketQuery();
    verify(workbasketQueryImplMock, times(1)).idIn(any());
    verify(workbasketQueryImplMock, times(1)).list();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask.getState(), equalTo(TaskState.COMPLETED));
    assertThat(actualTask.getCreated(), not(equalTo(task.getModified())));
    assertThat(actualTask.getCompleted(), not(equalTo(null)));
}
Also used : Task(pro.taskana.Task) ArrayList(java.util.ArrayList) Classification(pro.taskana.Classification) WorkbasketSummary(pro.taskana.WorkbasketSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with WorkbasketSummary

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

the class WorkbasketServiceImplIntAutocommitTest method testUpdateWorkbasket.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testUpdateWorkbasket() throws Exception {
    String id0 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "DOMAIN_A", "Superbasket", WorkbasketType.GROUP);
    workbasket0 = workBasketService.createWorkbasket(workbasket0);
    createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
    String id1 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "DOMAIN_A", "Megabasket", WorkbasketType.GROUP);
    workbasket1 = workBasketService.createWorkbasket(workbasket1);
    createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
    String id2 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "DOMAIN_A", "Hyperbasket", WorkbasketType.GROUP);
    workbasket2 = workBasketService.createWorkbasket(workbasket2);
    createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
    List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
    String id3 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "DOMAIN_A", "hm ... irgend ein basket", WorkbasketType.GROUP);
    workbasket3 = workBasketService.createWorkbasket(workbasket3);
    createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
    List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
    Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
    List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
    Assert.assertEquals(1, distributionTargets.size());
    Assert.assertEquals(id3, distributionTargets.get(0).getId());
    Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(), workBasketService.getWorkbasket(id2).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(), workBasketService.getWorkbasket(id1).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(), workBasketService.getWorkbasket(id3).getModified());
}
Also used : ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 34 with WorkbasketSummary

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

the class QueryWorkbasketByPermissionAccTest method testQueryAllAvailableWorkbasketForOpeningForUserAndGroupFromSubject.

@WithAccessId(userName = "user_1_1")
@Test
public void testQueryAllAvailableWorkbasketForOpeningForUserAndGroupFromSubject() throws SQLException, NotAuthorizedException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery().callerHasPermission(WorkbasketPermission.READ).list();
    Assert.assertEquals(1, results.size());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 35 with WorkbasketSummary

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

the class QueryWorkbasketByPermissionAccTest method testQueryAllTransferTargetsForUserAndGroupSortedByNameDescending.

@WithAccessId(userName = "dummy", groupNames = { "businessadmin" })
@Test
public void testQueryAllTransferTargetsForUserAndGroupSortedByNameDescending() throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery().accessIdsHavePermission(WorkbasketPermission.APPEND, "user_1_1", "group_1").orderByName(desc).orderByKey(asc).list();
    Assert.assertEquals(6, results.size());
    Assert.assertEquals("USER_2_2", results.get(0).getKey());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

WorkbasketSummary (pro.taskana.WorkbasketSummary)66 Test (org.junit.Test)56 WorkbasketService (pro.taskana.WorkbasketService)53 AbstractAccTest (acceptance.AbstractAccTest)52 WithAccessId (pro.taskana.security.WithAccessId)51 ArrayList (java.util.ArrayList)15 Workbasket (pro.taskana.Workbasket)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)7 WorkbasketQuery (pro.taskana.WorkbasketQuery)5 Classification (pro.taskana.Classification)3 Task (pro.taskana.Task)3 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)3 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)3 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)2 Ignore (org.junit.Ignore)2