TSK-87: Improved CreateTask-Method, updated Tests

This commit is contained in:
Marcel Lengl 2017-12-19 14:56:35 +01:00 committed by Holger Hagen
parent b6a75ed5e7
commit 657cbe5e75
5 changed files with 26 additions and 36 deletions

2
lib/.gitignore vendored
View File

@ -25,4 +25,4 @@ nbdist/
.nb-gradle/
### DEV-TOOLS ###
.checkstyle
.checkstyle

View File

@ -159,27 +159,24 @@ public class TaskServiceImpl implements TaskService {
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
try {
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;
workbasketService.getWorkbasket(task.getWorkbasketId());
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
Classification classification = task.getClassification();
if (classification == null) {
throw new ClassificationNotFoundException(null);
if (task.getId() != "" && task.getId() != null) {
throw new TaskAlreadyExistException(taskToCreate.getId());
} else {
LOGGER.debug("Task {} can´t be be found, so it can be created.", taskToCreate.getId());
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;
} finally {
taskanaEngineImpl.returnConnection();

View File

@ -109,7 +109,7 @@ public class TaskServiceImplTest {
ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException,
TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "1");
WorkbasketImpl wb = new WorkbasketImpl();
wb.setId("1");
wb.setName("workbasket");
@ -120,7 +120,6 @@ public class TaskServiceImplTest {
Task actualTask = cutSpy.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskanaEngineMock, times(1)).getClassificationService();
@ -151,7 +150,7 @@ public class TaskServiceImplTest {
WorkbasketImpl wb = new WorkbasketImpl();
wb.setId("1");
wb.setName("workbasket");
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", wb.getId());
TaskImpl expectedTask = createUnitTestTask(null, "DUMMYTASK", wb.getId());
expectedTask.setPrimaryObjRef(expectedObjectReference);
Classification classification = expectedTask.getClassification();
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
@ -163,7 +162,6 @@ public class TaskServiceImplTest {
Task actualTask = cutSpy.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getId());
verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketAuthorization.APPEND);
verify(taskanaEngineMock, times(1)).getClassificationService();
@ -197,7 +195,7 @@ public class TaskServiceImplTest {
wb.setId("1");
wb.setName("workbasket");
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "1");
expectedTask.setPrimaryObjRef(expectedObjectReference);
Classification classification = expectedTask.getClassification();
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
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketId());
verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
@ -274,9 +271,8 @@ public class TaskServiceImplTest {
cutSpy.createTask(task2);
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)).checkAuthorization(any(), any());
verify(taskanaEngineMock, times(2)).getClassificationService();
verify(classificationServiceMock, times(2)).getClassification(any(), any());
verify(objectReferenceMapperMock, times(2)).findByObjectReference(expectedObjectReference);
@ -312,7 +308,6 @@ public class TaskServiceImplTest {
cutSpy.createTask(task);
} catch (TaskAlreadyExistException ex) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
@ -326,7 +321,7 @@ public class TaskServiceImplTest {
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException, TaskNotFoundException {
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(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
@ -334,7 +329,6 @@ public class TaskServiceImplTest {
cutSpy.createTask(task);
} catch (NotAuthorizedException e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
@ -351,14 +345,13 @@ public class TaskServiceImplTest {
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException, TaskNotFoundException {
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(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
try {
cutSpy.createTask(task);
} catch (WorkbasketNotFoundException e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,

View File

@ -231,7 +231,7 @@ public class TaskServiceImplIntAutocommitTest {
classificationService.createClassification(dummyClassification);
TaskImpl dummyTask = (TaskImpl) taskServiceImpl.newTask();
dummyTask.setId("1");
dummyTask.setId(null);
dummyTask.setName("Dummy-Task");
dummyTask.setClassification(dummyClassification);
dummyTask.setWorkbasketId(dummyWorkbasket.getId());
@ -397,7 +397,7 @@ public class TaskServiceImplIntAutocommitTest {
}
// Check failing with missing TRANSFER
task.setId(UUID.randomUUID().toString());
task.setId("");
task.setWorkbasketId(wbNoTransfer.getId());
task = (TaskImpl) taskServiceImpl.createTask(task);
try {

View File

@ -473,7 +473,7 @@ public class TaskServiceImplIntExplicitTest {
}
// Check failing with missing TRANSFER
task.setId(UUID.randomUUID().toString());
task.setId("");
task.setWorkbasketId(wbNoTransfer.getId());
task = (TaskImpl) taskServiceImpl.createTask(task);
try {