Search in sources :

Example 36 with Workbasket

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

the class TaskServiceImplTest method testCreateThrowingAuthorizedOnWorkbasket.

@Test(expected = NotAuthorizedException.class)
public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, TaskNotFoundException, InvalidWorkbasketException, InvalidArgumentException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("", "dummyTask", "1", dummyClassification);
    Workbasket dummyWorkbasket = createWorkbasket("2", "k1");
    task.setWorkbasketSummary(dummyWorkbasket.asSummary());
    doReturn(dummyWorkbasket).when(workbasketServiceMock).getWorkbasket(any());
    doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
    doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
    try {
        cutSpy.createTask(task);
    } catch (NotAuthorizedException e) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketSummary().getId());
        verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
        verify(taskanaEngineMock, times(1)).returnConnection();
        verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock, classificationServiceImplMock);
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Workbasket

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

the class TaskServiceImplTest method testTransferTaskToDestinationWorkbasketWithoutSecurity.

@Test
public void testTransferTaskToDestinationWorkbasketWithoutSecurity() throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, InvalidWorkbasketException, ClassificationNotFoundException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Workbasket destinationWorkbasket = createWorkbasket("2", "k1");
    Workbasket sourceWorkbasket = createWorkbasket("47", "key47");
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "key47", dummyClassification);
    task.setWorkbasketSummary(sourceWorkbasket.asSummary());
    task.setRead(true);
    doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
    doReturn(sourceWorkbasket).when(workbasketServiceMock).getWorkbasket(sourceWorkbasket.getId());
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    doReturn(task).when(cutSpy).getTask(task.getId());
    doNothing().when(taskMapperMock).update(any());
    doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketPermission.APPEND);
    doNothing().when(workbasketServiceMock).checkAuthorization(sourceWorkbasket.getId(), WorkbasketPermission.TRANSFER);
    Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketPermission.APPEND);
    verify(workbasketServiceMock, times(1)).checkAuthorization(sourceWorkbasket.getId(), WorkbasketPermission.TRANSFER);
    verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId());
    verify(taskMapperMock, times(1)).update(any());
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask.isRead(), equalTo(false));
    assertThat(actualTask.getState(), equalTo(TaskState.READY));
    assertThat(actualTask.isTransferred(), equalTo(true));
    assertThat(actualTask.getWorkbasketKey(), equalTo(destinationWorkbasket.getKey()));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Workbasket(pro.taskana.Workbasket) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with Workbasket

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

the class TaskServiceImplIntAutocommitTest method shouldTransferTaskToOtherWorkbasket.

@Test
public void shouldTransferTaskToOtherWorkbasket() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Workbasket sourceWB;
    Workbasket destinationWB;
    WorkbasketImpl wb;
    ClassificationImpl classification;
    TaskImpl task;
    Task resultTask;
    final int sleepTime = 100;
    // Source Workbasket
    wb = (WorkbasketImpl) workbasketService.newWorkbasket("key1", "DOMAIN_A");
    wb.setName("Basic-Workbasket");
    wb.setDescription("Just used as base WB for Task here");
    wb.setType(WorkbasketType.GROUP);
    wb.setOwner("The Tester ID");
    sourceWB = workbasketService.createWorkbasket(wb);
    // Destination Workbasket
    wb = (WorkbasketImpl) workbasketService.newWorkbasket("k1", "DOMAIN_A");
    wb.setName("Desination-WorkBasket");
    wb.setType(WorkbasketType.CLEARANCE);
    wb.setDescription("Destination WB where Task should be transfered to");
    wb.setOwner("The Tester ID");
    destinationWB = workbasketService.createWorkbasket(wb);
    // Classification required for Task
    classification = (ClassificationImpl) classificationService.newClassification("KEY", "DOMAIN_A", "TASK");
    classification.setCategory("EXTERNAL");
    classification.setName("Transfert-Task Classification");
    classificationService.createClassification(classification);
    // Task which should be transfered
    task = (TaskImpl) taskServiceImpl.newTask(sourceWB.getId());
    task.setName("Task Name");
    task.setDescription("Task used for transfer Test");
    task.setRead(true);
    task.setTransferred(false);
    task.setModified(null);
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    // Sleep for modification-timestamp
    Thread.sleep(sleepTime);
    resultTask = taskServiceImpl.transfer(task.getId(), destinationWB.getId());
    assertThat(resultTask.isRead(), equalTo(false));
    assertThat(resultTask.isTransferred(), equalTo(true));
    assertThat(resultTask.getWorkbasketSummary().getId(), equalTo(destinationWB.getId()));
    assertThat(resultTask.getModified(), not(equalTo(null)));
    assertThat(resultTask.getModified(), not(equalTo(task.getModified())));
    assertThat(resultTask.getCreated(), not(equalTo(null)));
    assertThat(resultTask.getCreated(), equalTo(task.getCreated()));
}
Also used : Task(pro.taskana.Task) TaskImpl(pro.taskana.impl.TaskImpl) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) Workbasket(pro.taskana.Workbasket) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 39 with Workbasket

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

the class TaskServiceImplIntAutocommitTest method testStart.

@Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Workbasket wb = workbasketService.newWorkbasket("workbasket", "DOMAIN_A");
    wb.setName("workbasket");
    wb.setType(WorkbasketType.GROUP);
    taskanaEngine.getWorkbasketService().createWorkbasket(wb);
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    taskanaEngine.getClassificationService().createClassification(classification);
    Task task = taskServiceImpl.newTask(wb.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = taskServiceImpl.createTask(task);
    // skanaEngineImpl.getSqlSession().commit(); // needed so that the change is visible in the other session
    TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
    TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
    Task resultTask = taskServiceImpl2.getTask(task.getId());
    Assert.assertNotNull(resultTask);
}
Also used : Task(pro.taskana.Task) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) Workbasket(pro.taskana.Workbasket) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 40 with Workbasket

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

the class TaskServiceImplIntAutocommitTest method testCreateTaskInTaskanaWithDefaultDb.

@Test
public void testCreateTaskInTaskanaWithDefaultDb() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(TaskanaEngineConfiguration.createDefaultDataSource(), false);
    TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
    TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
    ((TaskanaEngineImpl) te).setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
    Workbasket wb = workbasketService.newWorkbasket("workbasket", "DOMAIN_A");
    wb.setName("workbasket");
    wb.setType(WorkbasketType.GROUP);
    te.getWorkbasketService().createWorkbasket(wb);
    Classification classification = te.getClassificationService().newClassification("TEST", "DOMAIN_A", "TASK");
    te.getClassificationService().createClassification(classification);
    Task task = taskServiceImpl.newTask(wb.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = taskServiceImpl.createTask(task);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Task(pro.taskana.Task) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) TaskanaEngineImpl(pro.taskana.impl.TaskanaEngineImpl) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) DBCleaner(pro.taskana.impl.configuration.DBCleaner) Workbasket(pro.taskana.Workbasket) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) 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