TSK-87: Improved CreateTask-Method, updated Tests
This commit is contained in:
parent
b6a75ed5e7
commit
657cbe5e75
|
|
@ -25,4 +25,4 @@ nbdist/
|
||||||
.nb-gradle/
|
.nb-gradle/
|
||||||
|
|
||||||
### DEV-TOOLS ###
|
### DEV-TOOLS ###
|
||||||
.checkstyle
|
.checkstyle
|
||||||
|
|
|
||||||
|
|
@ -159,27 +159,24 @@ public class TaskServiceImpl implements TaskService {
|
||||||
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
|
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
|
||||||
try {
|
try {
|
||||||
taskanaEngineImpl.openConnection();
|
taskanaEngineImpl.openConnection();
|
||||||
try {
|
|
||||||
this.getTaskById(taskToCreate.getId());
|
|
||||||
throw new TaskAlreadyExistException(taskToCreate.getId());
|
|
||||||
} catch (TaskNotFoundException ex) {
|
|
||||||
LOGGER.debug("Task {} can´t be be found, so it can be created.", taskToCreate.getId());
|
|
||||||
}
|
|
||||||
TaskImpl task = (TaskImpl) taskToCreate;
|
TaskImpl task = (TaskImpl) taskToCreate;
|
||||||
workbasketService.getWorkbasket(task.getWorkbasketId());
|
if (task.getId() != "" && task.getId() != null) {
|
||||||
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
throw new TaskAlreadyExistException(taskToCreate.getId());
|
||||||
Classification classification = task.getClassification();
|
} else {
|
||||||
if (classification == null) {
|
LOGGER.debug("Task {} can´t be be found, so it can be created.", taskToCreate.getId());
|
||||||
throw new ClassificationNotFoundException(null);
|
workbasketService.getWorkbasket(task.getWorkbasketId());
|
||||||
|
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||||
|
Classification classification = task.getClassification();
|
||||||
|
if (classification == null) {
|
||||||
|
throw new ClassificationNotFoundException(null);
|
||||||
|
}
|
||||||
|
taskanaEngine.getClassificationService().getClassification(classification.getKey(),
|
||||||
|
classification.getDomain());
|
||||||
|
|
||||||
|
standardSettings(task);
|
||||||
|
this.taskMapper.insert(task);
|
||||||
|
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
|
||||||
}
|
}
|
||||||
taskanaEngine.getClassificationService().getClassification(classification.getKey(),
|
|
||||||
classification.getDomain());
|
|
||||||
|
|
||||||
standardSettings(task);
|
|
||||||
|
|
||||||
this.taskMapper.insert(task);
|
|
||||||
|
|
||||||
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
|
|
||||||
return task;
|
return task;
|
||||||
} finally {
|
} finally {
|
||||||
taskanaEngineImpl.returnConnection();
|
taskanaEngineImpl.returnConnection();
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public class TaskServiceImplTest {
|
||||||
ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException,
|
ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException,
|
||||||
TaskNotFoundException {
|
TaskNotFoundException {
|
||||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "1");
|
||||||
WorkbasketImpl wb = new WorkbasketImpl();
|
WorkbasketImpl wb = new WorkbasketImpl();
|
||||||
wb.setId("1");
|
wb.setId("1");
|
||||||
wb.setName("workbasket");
|
wb.setName("workbasket");
|
||||||
|
|
@ -120,7 +120,6 @@ public class TaskServiceImplTest {
|
||||||
Task actualTask = cutSpy.createTask(expectedTask);
|
Task actualTask = cutSpy.createTask(expectedTask);
|
||||||
|
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(any());
|
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
|
||||||
verify(taskanaEngineMock, times(1)).getClassificationService();
|
verify(taskanaEngineMock, times(1)).getClassificationService();
|
||||||
|
|
@ -151,7 +150,7 @@ public class TaskServiceImplTest {
|
||||||
WorkbasketImpl wb = new WorkbasketImpl();
|
WorkbasketImpl wb = new WorkbasketImpl();
|
||||||
wb.setId("1");
|
wb.setId("1");
|
||||||
wb.setName("workbasket");
|
wb.setName("workbasket");
|
||||||
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", wb.getId());
|
TaskImpl expectedTask = createUnitTestTask(null, "DUMMYTASK", wb.getId());
|
||||||
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
||||||
Classification classification = expectedTask.getClassification();
|
Classification classification = expectedTask.getClassification();
|
||||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
|
||||||
|
|
@ -163,7 +162,6 @@ public class TaskServiceImplTest {
|
||||||
Task actualTask = cutSpy.createTask(expectedTask);
|
Task actualTask = cutSpy.createTask(expectedTask);
|
||||||
|
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(any());
|
|
||||||
verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getId());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getId());
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketAuthorization.APPEND);
|
verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketAuthorization.APPEND);
|
||||||
verify(taskanaEngineMock, times(1)).getClassificationService();
|
verify(taskanaEngineMock, times(1)).getClassificationService();
|
||||||
|
|
@ -197,7 +195,7 @@ public class TaskServiceImplTest {
|
||||||
wb.setId("1");
|
wb.setId("1");
|
||||||
wb.setName("workbasket");
|
wb.setName("workbasket");
|
||||||
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
|
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
|
||||||
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "1");
|
||||||
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
||||||
Classification classification = expectedTask.getClassification();
|
Classification classification = expectedTask.getClassification();
|
||||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
|
||||||
|
|
@ -211,7 +209,6 @@ public class TaskServiceImplTest {
|
||||||
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
|
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
|
||||||
|
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(any());
|
|
||||||
verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketId());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketId());
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketId(),
|
verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketId(),
|
||||||
WorkbasketAuthorization.APPEND);
|
WorkbasketAuthorization.APPEND);
|
||||||
|
|
@ -274,9 +271,8 @@ public class TaskServiceImplTest {
|
||||||
cutSpy.createTask(task2);
|
cutSpy.createTask(task2);
|
||||||
|
|
||||||
verify(taskanaEngineImpl, times(2)).openConnection();
|
verify(taskanaEngineImpl, times(2)).openConnection();
|
||||||
verify(cutSpy, times(2)).getTaskById(any());
|
|
||||||
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
|
|
||||||
verify(workbasketServiceMock, times(2)).getWorkbasket(any());
|
verify(workbasketServiceMock, times(2)).getWorkbasket(any());
|
||||||
|
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
|
||||||
verify(taskanaEngineMock, times(2)).getClassificationService();
|
verify(taskanaEngineMock, times(2)).getClassificationService();
|
||||||
verify(classificationServiceMock, times(2)).getClassification(any(), any());
|
verify(classificationServiceMock, times(2)).getClassification(any(), any());
|
||||||
verify(objectReferenceMapperMock, times(2)).findByObjectReference(expectedObjectReference);
|
verify(objectReferenceMapperMock, times(2)).findByObjectReference(expectedObjectReference);
|
||||||
|
|
@ -312,7 +308,6 @@ public class TaskServiceImplTest {
|
||||||
cutSpy.createTask(task);
|
cutSpy.createTask(task);
|
||||||
} catch (TaskAlreadyExistException ex) {
|
} catch (TaskAlreadyExistException ex) {
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(task.getId());
|
|
||||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
|
||||||
|
|
@ -326,7 +321,7 @@ public class TaskServiceImplTest {
|
||||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||||
TaskAlreadyExistException, TaskNotFoundException {
|
TaskAlreadyExistException, TaskNotFoundException {
|
||||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
TaskImpl task = createUnitTestTask("1", "dummyTask", "1");
|
TaskImpl task = createUnitTestTask("", "dummyTask", "1");
|
||||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||||
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(),
|
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(),
|
||||||
WorkbasketAuthorization.APPEND);
|
WorkbasketAuthorization.APPEND);
|
||||||
|
|
@ -334,7 +329,6 @@ public class TaskServiceImplTest {
|
||||||
cutSpy.createTask(task);
|
cutSpy.createTask(task);
|
||||||
} catch (NotAuthorizedException e) {
|
} catch (NotAuthorizedException e) {
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(task.getId());
|
|
||||||
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketId(),
|
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketId(),
|
||||||
WorkbasketAuthorization.APPEND);
|
WorkbasketAuthorization.APPEND);
|
||||||
|
|
@ -351,14 +345,13 @@ public class TaskServiceImplTest {
|
||||||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||||
TaskAlreadyExistException, TaskNotFoundException {
|
TaskAlreadyExistException, TaskNotFoundException {
|
||||||
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
TaskImpl task = createUnitTestTask("1", "dumma-task", "1");
|
TaskImpl task = createUnitTestTask("", "dumma-task", "1");
|
||||||
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||||
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
|
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
|
||||||
try {
|
try {
|
||||||
cutSpy.createTask(task);
|
cutSpy.createTask(task);
|
||||||
} catch (WorkbasketNotFoundException e) {
|
} catch (WorkbasketNotFoundException e) {
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(cutSpy, times(1)).getTaskById(task.getId());
|
|
||||||
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
|
||||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ public class TaskServiceImplIntAutocommitTest {
|
||||||
classificationService.createClassification(dummyClassification);
|
classificationService.createClassification(dummyClassification);
|
||||||
|
|
||||||
TaskImpl dummyTask = (TaskImpl) taskServiceImpl.newTask();
|
TaskImpl dummyTask = (TaskImpl) taskServiceImpl.newTask();
|
||||||
dummyTask.setId("1");
|
dummyTask.setId(null);
|
||||||
dummyTask.setName("Dummy-Task");
|
dummyTask.setName("Dummy-Task");
|
||||||
dummyTask.setClassification(dummyClassification);
|
dummyTask.setClassification(dummyClassification);
|
||||||
dummyTask.setWorkbasketId(dummyWorkbasket.getId());
|
dummyTask.setWorkbasketId(dummyWorkbasket.getId());
|
||||||
|
|
@ -397,7 +397,7 @@ public class TaskServiceImplIntAutocommitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check failing with missing TRANSFER
|
// Check failing with missing TRANSFER
|
||||||
task.setId(UUID.randomUUID().toString());
|
task.setId("");
|
||||||
task.setWorkbasketId(wbNoTransfer.getId());
|
task.setWorkbasketId(wbNoTransfer.getId());
|
||||||
task = (TaskImpl) taskServiceImpl.createTask(task);
|
task = (TaskImpl) taskServiceImpl.createTask(task);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check failing with missing TRANSFER
|
// Check failing with missing TRANSFER
|
||||||
task.setId(UUID.randomUUID().toString());
|
task.setId("");
|
||||||
task.setWorkbasketId(wbNoTransfer.getId());
|
task.setWorkbasketId(wbNoTransfer.getId());
|
||||||
task = (TaskImpl) taskServiceImpl.createTask(task);
|
task = (TaskImpl) taskServiceImpl.createTask(task);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue