Search in sources :

Example 66 with Classification

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

the class TaskServiceImplIntExplicitTest method testCreateTaskInTaskanaWithDefaultDb.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testCreateTaskInTaskanaWithDefaultDb() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(ds, false);
    TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
    TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
    Connection connection = ds.getConnection();
    te.setConnection(connection);
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
    WorkbasketServiceImpl workBasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService();
    ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
    Workbasket workbasket = workbasketService.newWorkbasket("K99", "DOMAIN_A");
    workbasket.setName("workbasket");
    workbasket.setName("workbasket99");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket = workBasketServiceImpl.createWorkbasket(workbasket);
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    classification = classificationServiceImpl.createClassification(classification);
    Task task = taskServiceImpl.newTask(workbasket.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task.addAttachment(null);
    task = taskServiceImpl.createTask(task);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
    connection.commit();
    te.setConnection(null);
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Task(pro.taskana.Task) ClassificationServiceImpl(pro.taskana.impl.ClassificationServiceImpl) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) WorkbasketServiceImpl(pro.taskana.impl.WorkbasketServiceImpl) DBCleaner(pro.taskana.impl.configuration.DBCleaner) Workbasket(pro.taskana.Workbasket) DataSource(javax.sql.DataSource) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 67 with Classification

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

the class TaskServiceImplIntExplicitTest method testStartTransactionFail.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    generateSampleAccessItems();
    WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("k1", "DOMAIN_A");
    workbasket.setName("workbasket");
    // workbasket.setId("1 "); // set id manually for authorization tests
    // set id manually for authorization tests
    workbasket.setId("1");
    workbasket.setType(WorkbasketType.GROUP);
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    taskanaEngineImpl.getWorkbasketService().createWorkbasket(workbasket);
    taskanaEngineImpl.getClassificationService().createClassification(classification);
    connection.commit();
    Task task = taskServiceImpl.newTask(workbasket.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = taskServiceImpl.createTask(task);
    connection.commit();
    task = taskServiceImpl.getTask(task.getId());
    TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
    TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
    taskServiceImpl2.getTask(workbasket.getId());
    connection.commit();
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskanaEngineImpl(pro.taskana.impl.TaskanaEngineImpl) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 68 with Classification

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

the class TaskServiceImplTest method testCompleteTaskNotForcedInvalidOwnerException.

@Test(expected = InvalidOwnerException.class)
public void testCompleteTaskNotForcedInvalidOwnerException() throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException, NotAuthorizedException {
    final boolean isForced = false;
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    task.setOwner("Dummy-Owner-ID: 10");
    task.setState(TaskState.CLAIMED);
    task.setClaimed(Instant.now());
    doReturn(task).when(cutSpy).getTask(task.getId());
    try {
        cutSpy.completeTask(task.getId(), isForced);
    } catch (InvalidOwnerException e) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(cutSpy, times(1)).getTask(task.getId());
        verify(taskanaEngineMock, times(1)).returnConnection();
        verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 69 with Classification

use of pro.taskana.Classification 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 70 with Classification

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

the class TaskServiceImplTest method testCompleteForcedAndAlreadyClaimed.

@Test
public void testCompleteForcedAndAlreadyClaimed() throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, InterruptedException, ClassificationNotFoundException, NotAuthorizedException {
    final boolean isForced = true;
    final long sleepTime = 100L;
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    // created and modify should be able to be different.
    Thread.sleep(sleepTime);
    task.setState(TaskState.CLAIMED);
    task.setClaimed(Instant.now());
    doReturn(task).when(cutSpy).getTask(task.getId());
    doNothing().when(taskMapperMock).update(task);
    Task actualTask = cutSpy.completeTask(task.getId(), isForced);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(cutSpy, times(1)).getTask(task.getId());
    verify(taskMapperMock, times(1)).update(task);
    verify(taskanaEngineMock, times(1)).returnConnection();
    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)));
    assertThat(actualTask.getCompleted(), equalTo(actualTask.getModified()));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Classification (pro.taskana.Classification)102 Test (org.junit.Test)88 Task (pro.taskana.Task)32 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 AbstractAccTest (acceptance.AbstractAccTest)23 WithAccessId (pro.taskana.security.WithAccessId)21 ClassificationSummary (pro.taskana.ClassificationSummary)20 Workbasket (pro.taskana.Workbasket)18 Connection (java.sql.Connection)14 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)13 TaskAlreadyExistException (pro.taskana.exceptions.TaskAlreadyExistException)11 ClassificationService (pro.taskana.ClassificationService)10 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)10 ConcurrencyException (pro.taskana.exceptions.ConcurrencyException)10 InvalidOwnerException (pro.taskana.exceptions.InvalidOwnerException)10 InvalidStateException (pro.taskana.exceptions.InvalidStateException)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)10 SystemException (pro.taskana.exceptions.SystemException)10