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()));
}
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;
}
}
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));
}
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;
}
}
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));
}
Aggregations