Search in sources :

Example 11 with Workbasket

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

the class TransferTaskAccTest method testBulkTransferTaskToWorkbasketById.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1" })
@Test
public void testBulkTransferTaskToWorkbasketById() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, InvalidStateException, InvalidOwnerException {
    Instant before = Instant.now();
    TaskService taskService = taskanaEngine.getTaskService();
    ArrayList<String> taskIdList = new ArrayList<>();
    taskIdList.add("TKI:000000000000000000000000000000000004");
    taskIdList.add("TKI:000000000000000000000000000000000005");
    BulkOperationResults<String, TaskanaException> results = taskService.transferTasks("WBI:100000000000000000000000000000000006", taskIdList);
    assertFalse(results.containsErrors());
    Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket("USER_1_1", "DOMAIN_A");
    Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000004");
    assertNotNull(transferredTask);
    assertTrue(transferredTask.isTransferred());
    assertFalse(transferredTask.isRead());
    assertEquals(TaskState.READY, transferredTask.getState());
    assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
    assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
    assertFalse(transferredTask.getModified().isBefore(before));
    assertThat(transferredTask.getOwner(), equalTo(null));
    transferredTask = taskService.getTask("TKI:000000000000000000000000000000000005");
    assertNotNull(transferredTask);
    assertTrue(transferredTask.isTransferred());
    assertFalse(transferredTask.isRead());
    assertEquals(TaskState.READY, transferredTask.getState());
    assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
    assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
    assertFalse(transferredTask.getModified().isBefore(before));
    assertThat(transferredTask.getOwner(), equalTo(null));
}
Also used : Task(pro.taskana.Task) TaskService(pro.taskana.TaskService) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) TaskanaException(pro.taskana.exceptions.TaskanaException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 12 with Workbasket

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

the class WorkbasketServiceImplTest method testGetWorkbasketById.

@Test
public void testGetWorkbasketById() throws NotAuthorizedException, WorkbasketNotFoundException {
    String wbId = "ID-1";
    Workbasket wb = createTestWorkbasket(wbId, "key-1");
    WorkbasketPermission authorization = WorkbasketPermission.READ;
    doReturn(wb).when(workbasketMapperMock).findById(wbId);
    doNothing().when(cutSpy).checkAuthorization(wb.getId(), authorization);
    Workbasket actualWb = cutSpy.getWorkbasket(wbId);
    verify(taskanaEngineImplMock, times(1)).openConnection();
    verify(workbasketMapperMock, times(1)).findById(wbId);
    verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
    verify(taskanaEngineImplMock, times(1)).returnConnection();
    verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
    verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
    assertThat(actualWb, equalTo(wb));
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 13 with Workbasket

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

the class WorkbasketServiceImplTest method testGetWorkbasketById_NonAuthorizedUser.

@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketById_NonAuthorizedUser() throws WorkbasketNotFoundException, NotAuthorizedException {
    String wbId = "ID-1";
    Workbasket wb = createTestWorkbasket(wbId, "Key-1");
    WorkbasketPermission authorization = WorkbasketPermission.READ;
    doReturn(wb).when(workbasketMapperMock).findById(wbId);
    doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wb.getId(), authorization);
    try {
        cutSpy.getWorkbasket(wbId);
    } catch (NotAuthorizedException ex) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(workbasketMapperMock, times(1)).findById(wbId);
        verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
        verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
        throw ex;
    }
}
Also used : WorkbasketPermission(pro.taskana.WorkbasketPermission) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 14 with Workbasket

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

the class WorkbasketServiceImplTest method testCreateWorkbasket_WithDistibutionTargets.

@Test
public void testCreateWorkbasket_WithDistibutionTargets() throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    final int distTargetAmount = 2;
    WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
    doNothing().when(workbasketMapperMock).insert(expectedWb);
    doReturn(expectedWb).when(cutSpy).getWorkbasket(any());
    doReturn(true).when(taskanaEngineImplMock).domainExists(any());
    Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
    cutSpy.setDistributionTargets(expectedWb.getId(), createTestDistributionTargets(distTargetAmount));
    verify(taskanaEngineImplMock, times(4)).openConnection();
    verify(workbasketMapperMock, times(3)).insert(any());
    verify(cutSpy, times(distTargetAmount + 1)).getWorkbasket(any());
    verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any());
    verify(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any());
    verify(workbasketMapperMock, times(3)).findByKeyAndDomain(any(), any());
    verify(workbasketMapperMock, times(1)).update(any());
    verify(taskanaEngineImplMock, times(4)).returnConnection();
    verify(taskanaEngineImplMock, times(4)).checkRoleMembership(any());
    verify(taskanaEngineImplMock, times(3)).domainExists(any());
    verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
    assertThat(actualWb.getId(), not(equalTo(null)));
    assertThat(actualWb.getId(), startsWith("WBI"));
    assertThat(actualWb.getCreated(), not(equalTo(null)));
    assertThat(actualWb.getModified(), not(equalTo(null)));
}
Also used : Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 15 with Workbasket

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

the class WorkbasketServiceImplTest method testDeleteWorkbasket.

@Test
public void testDeleteWorkbasket() throws NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException, WorkbasketNotFoundException {
    Workbasket wb = createTestWorkbasket("WBI:0", "wb-key");
    doReturn(wb).when(cutSpy).getWorkbasket(wb.getId());
    doReturn(sqlSessionMock).when(taskanaEngineImplMock).getSqlSession();
    doReturn(taskMapperMock).when(sqlSessionMock).getMapper(TaskMapper.class);
    doReturn(new Long(0)).when(taskMapperMock).countTasksInWorkbasket(any());
    cutSpy.deleteWorkbasket(wb.getId());
    verify(taskanaEngineImplMock, times(1)).openConnection();
    verify(cutSpy, times(1)).getWorkbasket(wb.getId());
    verify(taskanaEngineImplMock, times(1)).getSqlSession();
    verify(sqlSessionMock, times(1)).getMapper(TaskMapper.class);
    verify(taskMapperMock, times(1)).countTasksInWorkbasket(any());
    verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(wb.getId());
    verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsByTargetId(wb.getId());
    verify(workbasketAccessMapperMock, times(1)).deleteAllAccessItemsForWorkbasketId(wb.getId());
    verify(workbasketMapperMock, times(1)).delete(wb.getId());
    verify(taskanaEngineImplMock, times(1)).returnConnection();
    verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
    verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
}
Also used : Workbasket(pro.taskana.Workbasket) 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