Search in sources :

Example 16 with Classification

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

the class TaskServiceImplTest method testCompleteTaskNotForcedWorking.

@Test
public void testCompleteTaskNotForcedWorking() throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, 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);
    // created and modify should be able to be different.
    Thread.sleep(sleepTime);
    task.setState(TaskState.CLAIMED);
    task.setClaimed(Instant.now());
    task.setOwner(CurrentUserContext.getUserid());
    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)

Example 17 with Classification

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

the class TaskServiceImplTest method testCreateThrowsWorkbasketNotFoundException.

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

Example 18 with Classification

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

the class TaskServiceImplTest method testCreateSimpleTaskWithObjectReferenceIsNull.

@Test
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, TaskNotFoundException, InvalidWorkbasketException, InvalidArgumentException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    ObjectReference expectedObjectReference = JunitHelper.createDefaultObjRef();
    WorkbasketImpl wb = new WorkbasketImpl();
    wb.setId("1");
    wb.setKey("key1");
    wb.setName("workbasket");
    wb.setDomain("dummy-domain");
    doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getKey(), wb.getDomain());
    Classification dummyClassification = createDummyClassification();
    TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "key1", dummyClassification);
    expectedTask.setPrimaryObjRef(expectedObjectReference);
    ClassificationSummary classification = expectedTask.getClassificationSummary();
    doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
    doReturn(dummyClassification).when(classificationServiceImplMock).getClassification(classification.getKey(), classification.getDomain());
    doNothing().when(taskMapperMock).insert(expectedTask);
    doNothing().when(objectReferenceMapperMock).insert(expectedObjectReference);
    doReturn(null).when(objectReferenceMapperMock).findByObjectReference(expectedTask.getPrimaryObjRef());
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    Task actualTask = cutSpy.createTask(expectedTask);
    // get only new ID
    expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId());
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketKey(), expectedTask.getDomain());
    verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
    verify(classificationServiceImplMock, times(1)).getClassification(classification.getKey(), wb.getDomain());
    verify(taskanaEngineMock, times(1)).getConfiguration();
    verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
    verify(taskMapperMock, times(1)).insert(expectedTask);
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock, classificationServiceImplMock);
    assertNull(actualTask.getOwner());
    assertNotNull(actualTask.getCreated());
    assertNotNull(actualTask.getModified());
    assertNull(actualTask.getCompleted());
    assertThat(actualTask.getWorkbasketKey(), equalTo(expectedTask.getWorkbasketKey()));
    assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
    assertThat(actualTask.getState(), equalTo(TaskState.READY));
    assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
}
Also used : Task(pro.taskana.Task) ClassificationSummary(pro.taskana.ClassificationSummary) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with Classification

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

Example 20 with Classification

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

the class TaskServiceImplTest method testUpdateTaskAddingValidAttachmentTwice.

@Test
public void testUpdateTaskAddingValidAttachmentTwice() 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.addAttachment(attachment);
    task.addAttachment(attachment);
    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)

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