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