Search in sources :

Example 21 with Classification

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

the class TaskServiceImplTest method testUpdateTaskUpdateAttachment.

@Test
public void testUpdateTaskUpdateAttachment() throws TaskNotFoundException, SystemException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, NotAuthorizedException, AttachmentPersistenceException {
    String channelUpdate = "OTHER CHANNEL";
    Classification classification = createDummyClassification();
    Workbasket wb = createWorkbasket("WB-ID", "WB-Key");
    Attachment attachment = JunitHelper.createDefaultAttachment();
    Attachment attachmentToUpdate = JunitHelper.createDefaultAttachment();
    attachmentToUpdate.setChannel(channelUpdate);
    ObjectReference objectReference = JunitHelper.createDefaultObjRef();
    TaskImpl taskBefore = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    taskBefore.addAttachment(attachment);
    TaskImpl task = createUnitTestTask("ID", "taskName", wb.getKey(), classification);
    taskBefore.setModified(null);
    taskBefore.setCreated(Instant.now());
    task.setModified(null);
    task.setCreated(taskBefore.getCreated());
    task.addAttachment(taskBefore.getAttachments().get(0));
    task.setPrimaryObjRef(objectReference);
    // should override old one and differ at comparison
    task.addAttachment(attachmentToUpdate);
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    doReturn(taskBefore).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)).update(((AttachmentImpl) attachmentToUpdate));
    verify(taskanaEngineMock, times(1)).returnConnection();
    assertThat(actualTask.getAttachments().size(), equalTo(1));
    assertThat(actualTask.getAttachments().get(0).getChannel(), equalTo(channelUpdate));
}
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)

Example 22 with Classification

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

the class TaskServiceImplTest method testCreateSimpleTaskWithObjectReference.

@Test
public void testCreateSimpleTaskWithObjectReference() 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.setName("workbasket");
    wb.setKey("k33");
    wb.setDomain("dummy-domain");
    Classification dummyClassification = createDummyClassification();
    TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", wb.getKey(), dummyClassification);
    expectedTask.setPrimaryObjRef(expectedObjectReference);
    ClassificationSummary classification = expectedTask.getClassificationSummary();
    doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
    doReturn(wb).when(workbasketServiceMock).getWorkbasket(expectedTask.getWorkbasketKey(), expectedTask.getDomain());
    doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(expectedObjectReference);
    doReturn(dummyClassification).when(classificationServiceImplMock).getClassification(dummyClassification.getKey(), dummyClassification.getDomain());
    doNothing().when(taskMapperMock).insert(expectedTask);
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    Task actualTask = cutSpy.createTask(expectedTask);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getKey(), wb.getDomain());
    verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketPermission.APPEND);
    verify(classificationServiceImplMock, times(1)).getClassification(classification.getKey(), classification.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, 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 23 with Classification

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

the class TaskServiceImplTest method testCreateSimpleTask.

@Test
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, TaskNotFoundException, InvalidWorkbasketException, InvalidArgumentException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "k1", dummyClassification);
    WorkbasketImpl wb = new WorkbasketImpl();
    wb.setId("1");
    wb.setKey("k1");
    wb.setName("workbasket");
    wb.setDomain(dummyClassification.getDomain());
    doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
    doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getKey(), wb.getDomain());
    doNothing().when(taskMapperMock).insert(expectedTask);
    doReturn(dummyClassification).when(classificationServiceImplMock).getClassification(dummyClassification.getKey(), dummyClassification.getDomain());
    expectedTask.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    Task actualTask = cutSpy.createTask(expectedTask);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
    verify(workbasketServiceMock, times(1)).getWorkbasket(any(), any());
    verify(classificationServiceImplMock, times(1)).getClassification(any(), any());
    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, 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));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with Classification

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

the class TaskServiceImplTest method testCompleteForcedNotClaimed.

@Test
public void testCompleteForcedNotClaimed() throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, InterruptedException, ClassificationNotFoundException, NotAuthorizedException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    final boolean isForced = true;
    final long sleepTime = 100L;
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    task.setState(TaskState.READY);
    task.setClaimed(null);
    doReturn(task).when(cutSpy).getTask(task.getId());
    TaskImpl claimedTask = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
    // created and modify should be able to be different.
    Thread.sleep(sleepTime);
    claimedTask.setState(TaskState.CLAIMED);
    claimedTask.setClaimed(Instant.now());
    doReturn(claimedTask).when(cutSpy).claim(task.getId(), isForced);
    doNothing().when(taskMapperMock).update(claimedTask);
    Task actualTask = cutSpy.completeTask(task.getId(), isForced);
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(cutSpy, times(1)).getTask(task.getId());
    verify(cutSpy, times(1)).claim(task.getId(), isForced);
    verify(taskMapperMock, times(1)).update(claimedTask);
    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(claimedTask.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 25 with Classification

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

the class ClassificationServiceImplIntAutoCommitTest method testFindWithClassificationMapperPriorityTypeAndParent.

@Test
public void testFindWithClassificationMapperPriorityTypeAndParent() throws ClassificationAlreadyExistException, NumberFormatException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification.setPriority(Integer.decode("5"));
    classificationService.createClassification(classification);
    Classification classification1 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification1.setPriority(Integer.decode("3"));
    classification1.setParentId(classification.getId());
    classificationService.createClassification(classification1);
    Classification classification2 = this.createDummyClassificationWithUniqueKey("", "DOCUMENT");
    classification2.setPriority(Integer.decode("5"));
    classification2.setParentId(classification.getId());
    classificationService.createClassification(classification2);
    Classification classification3 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification3.setPriority(Integer.decode("5"));
    classification3.setParentId(classification1.getId());
    classificationService.createClassification(classification3);
    List<ClassificationSummary> list = classificationService.createClassificationQuery().parentIdIn(classification.getId()).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().typeIn("TASK").priorityIn(Integer.decode("5")).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().priorityIn(Integer.decode("5")).typeIn("TASK").parentIdIn(classification1.getId()).list();
    Assert.assertEquals(1, list.size());
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) Classification(pro.taskana.Classification) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) 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