TSK-22_start_working_on_a_task

This commit is contained in:
BerndBreier 2017-12-13 15:47:23 +01:00 committed by Holger Hagen
parent 4d94684bf0
commit 600c4aa281
6 changed files with 349 additions and 249 deletions

View File

@ -32,7 +32,7 @@ public class TaskanaProducersTest {
deployment.addAllDependencies();
deployment.addDependency("org.mybatis:mybatis:3.4.2");
deployment.addDependency("org.mybatis:mybatis-cdi:1.0.0");
deployment.addDependency("pro.taskana:taskana-core:0.0.1-SNAPSHOT");
deployment.addDependency("pro.taskana:taskana-core:0.0.3-SNAPSHOT");
deployment.addAsResource("META-INF/beans.xml");
deployment.addAsResource("taskana.properties");
deployment.addAsResource("project-defaults.yml");
@ -68,7 +68,6 @@ public class TaskanaProducersTest {
Assert.assertEquals(1, resultCount);
}
@Test
public void testRollback() throws SQLException, ClassNotFoundException, NamingException {
Client client = ClientBuilder.newClient();

View File

@ -35,6 +35,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.7.1</powermock.version>
</properties>
<profiles>
@ -141,6 +142,18 @@
<version>2.8.47</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>

View File

@ -1,5 +1,7 @@
package pro.taskana;
import java.util.List;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException;
@ -12,8 +14,6 @@ import pro.taskana.model.TaskState;
import pro.taskana.model.TaskStateCounter;
import pro.taskana.model.TaskSummary;
import java.util.List;
/**
* The Task Service manages all operations on tasks.
*/
@ -21,102 +21,146 @@ public interface TaskService {
/**
* Claim an existing task for the current user.
* @param id
* task id
* @return modified claimed Task
* @throws TaskNotFoundException if the task with id was not found
* @throws InvalidStateException if the task state is not ready
* @throws InvalidOwnerException if the task is claimed by another user
*
* @param taskId
* the id of the task to be claimed
* @return claimed Task
* @throws TaskNotFoundException
* if the task with taskId was not found
* @throws InvalidStateException
* if the state of the task with taskId is not {@link TaskState#READY}
* @throws InvalidOwnerException
* if the task with taskId is claimed by some else
*/
Task claim(String id) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
Task claim(String taskId) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
/**
* Claim an existing task for the current user.
* @param id
* task id
* Claim an existing task for the current user. Enable forced claim.
*
* @param taskId
* the id of the task to be claimed
* @param forceClaim
* if true, claim is performed even if the task is already claimed by someone else
* @return modified claimed Task
* @throws TaskNotFoundException if the task with id was not found
* @throws InvalidStateException if the task state is not ready
* @throws InvalidOwnerException if the task is claimed by another user
* @return claimed Task
* @throws TaskNotFoundException
* if the task with taskId was not found
* @throws InvalidStateException
* if the state of the task with taskId is not {@link TaskState#READY}
* @throws InvalidOwnerException
* if the task with taskId is claimed by someone else
*/
Task claim(String id, boolean forceClaim) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
Task claim(String taskId, boolean forceClaim)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException;
/**
* Set task to completed.
*
* @param taskId
* the task id
* @return changed Task after update.
* @throws TaskNotFoundException TODO
* @throws TaskNotFoundException
* thrown if the task with taskId is not found.
*/
Task complete(String taskId) throws TaskNotFoundException;
/**
* Create a task by a task object.
* @param task TODO
* @return the created task
* @throws NotAuthorizedException TODO
* @throws WorkbasketNotFoundException TODO
* @throws ClassificationNotFoundException TODO
* Create and persist a task.
*
* @param task
* the transient task object to be persisted
* @return the created and persisted task
* @throws NotAuthorizedException
* thrown if the current user is not authorized to create that task
* @throws WorkbasketNotFoundException
* thrown if the work basket referenced by the task is not found
* @throws ClassificationNotFoundException
* thrown if the {@link Classification} referenced by the task is not found
*/
Task createTask(Task task) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException;
Task createTask(Task task)
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException;
/**
* Get the details of a task.
* Get the details of a task by Id.
*
* @param taskId
* the id of the task
* @return the Task
* @throws TaskNotFoundException TODO
* @throws TaskNotFoundException
* thrown of the {@link Task} with taskId is not found
*/
Task getTaskById(String taskId) throws TaskNotFoundException;
/**
* This method counts all tasks with a given state.
*
* @param states
* the countable states
* @return a List of {@link TaskStateCounter}
* @return a List of {@link TaskStateCounter} objects that specifies how many tasks in the specified states exist in
* the available work baskets
*/
List<TaskStateCounter> getTaskCountForState(List<TaskState> states);
/**
* Count all Tasks in a given workbasket with daysInPast as Days from today in
* the past and a specific state.
* @param workbasketId TODO
* @param daysInPast TODO
* @param states TODO
* @return TODO
* Count all Tasks in a given work basket where the due date is after "daysInPast" days from today in the past and
* the tasks are in specified states.
*
* @param workbasketId
* the id of the work basket
* @param daysInPast
* identifies the days in the past from today
* @param states
* {@link List} of {@link TaskState} that identifies the states of the tasks to be searched for
* @return the number of {@link Task} objects in the given work basket that match the query parameters
*/
long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states);
/**
* Count all Tasks for all work basket objects where the due date is after "daysInPast" days from today in the past
* and the tasks are in specified states.
*
* @param daysInPast
* identifies the days in the past from today
* @param states
* {@link List} of {@link TaskState} objects that identifies the states of the tasks searched
* @return a list of of {@link DueWorkbasketCounter} objects that specifies how many tasks in the requested states
* with appropriate due date exist in the various work baskets
*/
List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast, List<TaskState> states);
/**
* Transfer task to another workbasket. The transfer set the transferred flag
* and resets the read flag.
* @param taskId TODO
* @param workbasketId TODO
* @return the updated task
* @throws TaskNotFoundException TODO
* @throws WorkbasketNotFoundException TODO
* @throws NotAuthorizedException TODO
* Transfer a task to another work basket. The transfer sets the transferred flag and resets the read flag.
*
* @param taskId
* The id of the {@link Task} to be transferred
* @param workbasketId
* The id of the target work basket
* @return the transferred task
* @throws TaskNotFoundException
* Thrown if the {@link Task} with taskId was not found.
* @throws WorkbasketNotFoundException
* Thrown if the target work basket was not found.
* @throws NotAuthorizedException
* Thrown if the current user is not authorized to transfer this {@link Task} to the target work basket
*/
Task transfer(String taskId, String workbasketId)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException;
/**
* Marks a task as read.
*
* @param taskId
* the id of the task to be updated
* @param isRead
* the new status of the read flag.
* @return Task the updated Task
* @throws TaskNotFoundException TODO
* @return the updated Task
* @throws TaskNotFoundException
* Thrown if the {@link Task} with taskId was not found
*/
Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException;
/**
* This method provides a query builder for quering the database.
*
* @return a {@link TaskQuery}
*/
TaskQuery createTaskQuery();
@ -124,21 +168,27 @@ public interface TaskService {
/**
* Getting a list of all Tasks which got matching workbasketIds and states.
*
* @param workbasketId where the tasks need to be in.
* @param taskState which is required for the request,
* @param workbasketId
* where the tasks need to be in.
* @param taskState
* which is required for the request,
* @return a filled/empty list of tasks with attributes which are matching given params.
*
* @throws WorkbasketNotFoundException if the workbasketId can´t be resolved to a existing workbasket.
* @throws NotAuthorizedException if the current user got no rights for reading on this workbasket.
* @throws Exception if no result can be found by @{link TaskMapper}.
* @throws WorkbasketNotFoundException
* if the workbasketId can´t be resolved to a existing work basket.
* @throws NotAuthorizedException
* if the current user got no rights for reading on this work basket.
*/
List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception;
List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState)
throws WorkbasketNotFoundException, NotAuthorizedException;
/**
* Getting a short summary of all tasks in a specific workbasket.
* @param workbasketId ID of workbasket where tasks are located.
* @return TaskSummaryList with all TaskSummaries of a workbasket
* @throws WorkbasketNotFoundException if a Workbasket can´t be located.
* Getting a short summary of all tasks in a specific work basket.
*
* @param workbasketId
* ID of work basket where tasks are located.
* @return TaskSummaryList with all TaskSummaries of a work basket
* @throws WorkbasketNotFoundException
* if a Work basket can´t be located.
*/
List<TaskSummary> getTaskSummariesByWorkbasketId(String workbasketId) throws WorkbasketNotFoundException;
}

View File

@ -42,14 +42,20 @@ public class TaskServiceImpl implements TaskService {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class);
private static final String ID_PREFIX_OBJECTR_EFERENCE = "ORI";
private static final String ID_PREFIX_OBJECT_REFERENCE = "ORI";
private static final String ID_PREFIX_TASK = "TKI";
private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI";
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketService workbasketService;
private TaskMapper taskMapper;
private ObjectReferenceMapper objectReferenceMapper;
public TaskServiceImpl(TaskanaEngine taskanaEngine, TaskMapper taskMapper,
@ -63,43 +69,39 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public Task claim(String id) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
return claim(id, false);
public Task claim(String taskId) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
return claim(taskId, false);
}
@Override
public Task claim(String id, boolean forceClaim) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
String userName = CurrentUserContext.getUserid();
return claim(id, userName, forceClaim);
}
public Task claim(String id, String userName, boolean forceClaim) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
LOGGER.debug("entry to claim(id = {}, userName = {})", id, userName);
public Task claim(String taskId, boolean forceClaim)
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException {
String userId = CurrentUserContext.getUserid();
LOGGER.debug("entry to claim(id = {}, forceClaim = {}, userId = {})", taskId, forceClaim, userId);
Task task = null;
try {
taskanaEngineImpl.openConnection();
task = taskMapper.findById(id);
if (task == null) {
LOGGER.warn("Method claim() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id);
}
task = getTaskById(taskId);
TaskState state = task.getState();
if (state == TaskState.COMPLETED) {
LOGGER.warn("Method claim() found that task {} is already completed. Throwing InvalidStateException", id);
LOGGER.warn("Method claim() found that task {} is already completed. Throwing InvalidStateException",
taskId);
throw new InvalidStateException("Task is already completed");
}
if (state == TaskState.CLAIMED && !forceClaim) {
LOGGER.warn("Method claim() found that task {} is claimed by {} and forceClaim is false. Throwing InvalidOwnerException", id, task.getOwner());
LOGGER.warn(
"Method claim() found that task {} is claimed by {} and forceClaim is false. Throwing InvalidOwnerException",
taskId, task.getOwner());
throw new InvalidOwnerException("Task is already claimed by user " + task.getOwner());
}
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setOwner(userName);
task.setOwner(userId);
task.setModified(now);
task.setClaimed(now);
task.setRead(true);
task.setState(TaskState.CLAIMED);
taskMapper.update(task);
LOGGER.debug("Method claim() claimed task '{}' for user '{}'.", id, userName);
LOGGER.debug("Method claim() claimed task '{}' for user '{}'.", taskId, userId);
} finally {
taskanaEngineImpl.returnConnection();
@ -134,12 +136,13 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public Task createTask(Task task) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
public Task createTask(Task task)
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
LOGGER.debug("entry to createTask(task = {})", task);
try {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
workbasketService.getWorkbasket(task.getWorkbasketId());
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
Classification classification = task.getClassification();
if (classification == null) {
throw new ClassificationNotFoundException(null);
@ -191,15 +194,18 @@ public class TaskServiceImpl implements TaskService {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountForState(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
LOGGER.debug("exit from getTaskCountForState(). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
@Override
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
List<TaskState> states) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
LOGGER.debug(
"entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
workbasketId, daysInPast, LoggerUtils.listToString(states));
}
long result = -1;
@ -226,13 +232,13 @@ public class TaskServiceImpl implements TaskService {
Task task = getTaskById(taskId);
// transfer requires TRANSFER in source and APPEND on destination workbasket
taskanaEngine.getWorkbasketService().checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
workbasketService.checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
// if security is disabled, the implicit existance check on the
// destination workbasket has been skipped and needs to be performed
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
taskanaEngine.getWorkbasketService().getWorkbasket(destinationWorkbasketId);
workbasketService.getWorkbasket(destinationWorkbasketId);
}
// reset read flag and set transferred flag
@ -245,7 +251,8 @@ public class TaskServiceImpl implements TaskService {
taskMapper.update(task);
result = getTaskById(taskId);
LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId,
destinationWorkbasketId);
return result;
} finally {
taskanaEngineImpl.returnConnection();
@ -257,7 +264,8 @@ public class TaskServiceImpl implements TaskService {
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
List<TaskState> states) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})", daysInPast, LoggerUtils.listToString(states));
LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})",
daysInPast, LoggerUtils.listToString(states));
}
List<DueWorkbasketCounter> result = null;
try {
@ -271,7 +279,8 @@ public class TaskServiceImpl implements TaskService {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
LOGGER.debug(
"exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@ -302,18 +311,21 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception {
LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState);
public List<Task> getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState)
throws WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId,
taskState);
List<Task> result = null;
try {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
workbasketService.checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
result = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ",
LOGGER.debug(
"exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
}
@ -365,7 +377,7 @@ public class TaskServiceImpl implements TaskService {
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
if (objectReference == null) {
objectReference = task.getPrimaryObjRef();
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECT_REFERENCE));
this.objectReferenceMapper.insert(objectReference);
}
task.setPrimaryObjRef(objectReference);
@ -376,7 +388,7 @@ public class TaskServiceImpl implements TaskService {
public List<TaskSummary> getTaskSummariesByWorkbasketId(String workbasketId) throws WorkbasketNotFoundException {
LOGGER.debug("entry to getTaskSummariesByWorkbasketId(workbasketId = {}", workbasketId);
List<TaskSummary> taskSummaries = new ArrayList<>();
taskanaEngineImpl.getWorkbasketService().getWorkbasket(workbasketId);
workbasketService.getWorkbasket(workbasketId);
try {
taskanaEngineImpl.openConnection();
taskSummaries = taskMapper.findTaskSummariesByWorkbasketId(workbasketId);
@ -389,12 +401,12 @@ public class TaskServiceImpl implements TaskService {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = taskSummaries.size();
LOGGER.debug("exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
LOGGER.debug(
"exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(taskSummaries));
}
}
return taskSummaries;
}
}

View File

@ -27,7 +27,10 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
@ -49,12 +52,17 @@ import pro.taskana.model.Workbasket;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.mappings.ObjectReferenceMapper;
import pro.taskana.model.mappings.TaskMapper;
import pro.taskana.security.CurrentUserContext;
/**
* Unit Test for TaskServiceImpl.
*
* @author EH
*/
@RunWith(MockitoJUnitRunner.class)
// @RunWith(MockitoJUnitRunner.class)
@RunWith(PowerMockRunner.class)
@PrepareForTest(CurrentUserContext.class)
@PowerMockIgnore("javax.management.*")
public class TaskServiceImplTest {
private static final int SLEEP_TIME = 100;
@ -98,7 +106,8 @@ public class TaskServiceImplTest {
}
@Test
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException {
Mockito.doNothing().when(taskMapperMock).insert(any());
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
Workbasket wb = new Workbasket();
@ -109,7 +118,6 @@ public class TaskServiceImplTest {
Task actualTask = cut.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
@ -131,7 +139,8 @@ public class TaskServiceImplTest {
}
@Test
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException {
ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY");
@ -149,7 +158,6 @@ public class TaskServiceImplTest {
Task actualTask = cut.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
@ -174,7 +182,8 @@ public class TaskServiceImplTest {
}
@Test
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY");
@ -193,7 +202,6 @@ public class TaskServiceImplTest {
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
@ -218,7 +226,8 @@ public class TaskServiceImplTest {
}
@Test
public void testCreateTaskWithPlanned() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
public void testCreateTaskWithPlanned()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY");
@ -252,7 +261,6 @@ public class TaskServiceImplTest {
cut.createTask(test2);
verify(taskanaEngineImpl, times(2)).openConnection();
verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService();
verify(taskanaEngineMock, times(2)).getClassificationService();
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(2)).getWorkbasket(any());
@ -282,7 +290,8 @@ public class TaskServiceImplTest {
}
@Test(expected = NotAuthorizedException.class)
public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
public void testCreateThrowingAuthorizedOnWorkbasket()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
try {
Mockito.doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
Task task = new Task();
@ -293,7 +302,6 @@ public class TaskServiceImplTest {
cut.createTask(task);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(taskanaEngineImpl, times(1)).returnConnection();
@ -305,7 +313,8 @@ public class TaskServiceImplTest {
}
@Test(expected = WorkbasketNotFoundException.class)
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
public void testCreateThrowsWorkbasketNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
try {
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
Task task = new Task();
@ -314,7 +323,6 @@ public class TaskServiceImplTest {
cut.createTask(task);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
@ -328,15 +336,20 @@ public class TaskServiceImplTest {
public void testClaimSuccessfulToOwner() throws Exception {
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
Thread.sleep(SLEEP_TIME); // to have different timestamps
String expectedOwner = "John Does";
Task acturalTask = cut.claim(expectedTask.getId(), expectedOwner, true);
PowerMockito.mockStatic(CurrentUserContext.class);
Mockito.when(CurrentUserContext.getUserid()).thenReturn(expectedOwner);
verify(taskanaEngineImpl, times(1)).openConnection();
// Mockito.doReturn(expectedOwner).when(currentUserContext).getUserid();
Task acturalTask = cut.claim(expectedTask.getId(), true);
verify(taskanaEngineImpl, times(2)).openConnection();
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
verify(taskMapperMock, times(1)).update(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verify(taskanaEngineImpl, times(2)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
@ -351,12 +364,13 @@ public class TaskServiceImplTest {
try {
Task expectedTask = null;
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(any());
// Mockito.doReturn("OWNER").when(currentUserContext).getUserid();
cut.claim("1", "OWNER", true);
cut.claim("1", true);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineImpl, times(2)).openConnection();
verify(taskMapperMock, times(1)).findById(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verify(taskanaEngineImpl, times(2)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
@ -364,7 +378,8 @@ public class TaskServiceImplTest {
}
@Test
public void testCompleteTask() throws TaskNotFoundException, InterruptedException, ClassificationAlreadyExistException {
public void testCompleteTask()
throws TaskNotFoundException, InterruptedException, ClassificationAlreadyExistException {
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
Thread.sleep(SLEEP_TIME); // to have different timestamps
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
@ -400,7 +415,8 @@ public class TaskServiceImplTest {
@Test
public void testTransferTaskToDestinationWorkbasketWithoutSecurity()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
Workbasket destinationWorkbasket = createWorkbasket("2");
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
@ -411,14 +427,15 @@ public class TaskServiceImplTest {
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
doReturn(task).when(cutSpy).getTaskById(task.getId());
doNothing().when(taskMapperMock).update(any());
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(),
WorkbasketAuthorization.APPEND);
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(workServiceMockCalls)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(),
WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
verify(taskanaEngineMock, times(1)).getConfiguration();
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
@ -435,7 +452,8 @@ public class TaskServiceImplTest {
@Test
public void testTransferTaskToDestinationWorkbasketUsingSecurityTrue()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
Workbasket destinationWorkbasket = createWorkbasket("2");
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
@ -444,14 +462,15 @@ public class TaskServiceImplTest {
doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
doReturn(task).when(cutSpy).getTaskById(task.getId());
doNothing().when(taskMapperMock).update(any());
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(),
WorkbasketAuthorization.APPEND);
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(),
WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
verify(taskanaEngineMock, times(1)).getConfiguration();
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
@ -467,20 +486,22 @@ public class TaskServiceImplTest {
@Test(expected = WorkbasketNotFoundException.class)
public void testTransferDestinationWorkbasketDoesNotExist()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
String destinationWorkbasketId = "2";
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
TaskServiceImpl cutSpy = Mockito.spy(cut);
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock)
.checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
doReturn(task).when(cutSpy).getTaskById(task.getId());
try {
cutSpy.transfer(task.getId(), destinationWorkbasketId);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
@ -490,7 +511,8 @@ public class TaskServiceImplTest {
@Test(expected = TaskNotFoundException.class)
public void testTransferTaskDoesNotExist()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
TaskServiceImpl cutSpy = Mockito.spy(cut);
@ -509,19 +531,21 @@ public class TaskServiceImplTest {
@Test(expected = NotAuthorizedException.class)
public void testTransferNotAuthorizationOnWorkbasketAppend()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
String destinationWorkbasketId = "2";
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
TaskServiceImpl cutSpy = Mockito.spy(cut);
doReturn(task).when(cutSpy).getTaskById(task.getId());
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
try {
cutSpy.transfer(task.getId(), destinationWorkbasketId);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
@ -531,20 +555,23 @@ public class TaskServiceImplTest {
@Test(expected = NotAuthorizedException.class)
public void testTransferNotAuthorizationOnWorkbasketTransfer()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException {
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException {
String destinationWorkbasketId = "2";
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
TaskServiceImpl cutSpy = Mockito.spy(cut);
doReturn(task).when(cutSpy).getTaskById(task.getId());
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.TRANSFER);
try {
cutSpy.transfer(task.getId(), destinationWorkbasketId);
} catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
@ -575,7 +602,8 @@ public class TaskServiceImplTest {
final long daysInPast = 10L;
final long expectedResult = 5L;
String workbasketId = "1";
doReturn(expectedResult).when(taskMapperMock).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
doReturn(expectedResult).when(taskMapperMock).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(),
any());
long actualResult = cut.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, daysInPast, taskStates);
@ -592,9 +620,11 @@ public class TaskServiceImplTest {
final long daysInPast = 10L;
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
List<DueWorkbasketCounter> expectedResult = new ArrayList<>();
doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class),
any());
List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast, taskStates);
List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,
taskStates);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
@ -679,9 +709,9 @@ public class TaskServiceImplTest {
String workbasketId = "1";
List<TaskSummary> expectedResultList = new ArrayList<>();
doNothing().when(taskanaEngineImpl).openConnection();
doThrow(new IllegalArgumentException("Invalid ID: " + workbasketId)).when(taskMapperMock).findTaskSummariesByWorkbasketId(workbasketId);
doThrow(new IllegalArgumentException("Invalid ID: " + workbasketId)).when(taskMapperMock)
.findTaskSummariesByWorkbasketId(workbasketId);
doNothing().when(taskanaEngineImpl).returnConnection();
doReturn(workbasketServiceMock).when(taskanaEngineImpl).getWorkbasketService();
doReturn(new Workbasket()).when(workbasketServiceMock).getWorkbasket(any());
// when - make the call
@ -691,7 +721,6 @@ public class TaskServiceImplTest {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskMapperMock, times(1)).findTaskSummariesByWorkbasketId(workbasketId);
verify(taskanaEngineImpl, times(1)).returnConnection();
verify(taskanaEngineImpl, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verifyNoMoreInteractions(taskMapperMock, taskanaEngineImpl, workbasketServiceMock);
@ -704,13 +733,11 @@ public class TaskServiceImplTest {
List<TaskSummary> expectedResultList = Arrays.asList(new TaskSummary(), new TaskSummary());
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
doReturn(workbasketServiceMock).when(taskanaEngineImpl).getWorkbasketService();
doReturn(new Workbasket()).when(workbasketServiceMock).getWorkbasket(any());
doReturn(expectedResultList).when(taskMapperMock).findTaskSummariesByWorkbasketId(workbasketId);
List<TaskSummary> actualResultList = cut.getTaskSummariesByWorkbasketId(workbasketId);
verify(taskanaEngineImpl, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskMapperMock, times(1)).findTaskSummariesByWorkbasketId(workbasketId);
@ -727,7 +754,6 @@ public class TaskServiceImplTest {
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
doReturn(null).when(taskMapperMock).findTaskSummariesByWorkbasketId(workbasketId);
doReturn(workbasketServiceMock).when(taskanaEngineImpl).getWorkbasketService();
doReturn(new Workbasket()).when(workbasketServiceMock).getWorkbasket(any());
List<TaskSummary> actualResultList = cut.getTaskSummariesByWorkbasketId(workbasketId);
@ -735,7 +761,6 @@ public class TaskServiceImplTest {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskMapperMock, times(1)).findTaskSummariesByWorkbasketId(workbasketId);
verify(taskanaEngineImpl, times(1)).returnConnection();
verify(taskanaEngineImpl, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verifyNoMoreInteractions(taskMapperMock, taskanaEngineImpl, workbasketServiceMock);
@ -743,7 +768,8 @@ public class TaskServiceImplTest {
assertThat(actualResultList.size(), equalTo(expectedResultList.size()));
}
private Task createUnitTestTask(String id, String name, String workbasketId) throws ClassificationAlreadyExistException {
private Task createUnitTestTask(String id, String name, String workbasketId)
throws ClassificationAlreadyExistException {
Task task = new Task();
task.setId(id);
task.setName(name);

View File

@ -5,7 +5,7 @@
<groupId>pro.taskana</groupId>
<artifactId>rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rest</name>
@ -37,7 +37,7 @@
<dependency>
<groupId>pro.taskana</groupId>
<artifactId>taskana-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</dependency>
<dependency>