diff --git a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java
index c98a39b8b..4fe302ed8 100644
--- a/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java
+++ b/lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java
@@ -24,66 +24,65 @@ import org.wildfly.swarm.undertow.WARArchive;
@RunWith(Arquillian.class)
public class TaskanaProducersTest {
- @Deployment(testable = false)
- public static Archive> createDeployment() throws Exception {
- WARArchive deployment = ShrinkWrap.create(WARArchive.class);
- deployment.addPackage("pro.taskana");
- deployment.addClass(TaskanaProducers.class);
- 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.addAsResource("META-INF/beans.xml");
- deployment.addAsResource("taskana.properties");
- deployment.addAsResource("project-defaults.yml");
- return deployment;
- }
+ @Deployment(testable = false)
+ public static Archive> createDeployment() throws Exception {
+ WARArchive deployment = ShrinkWrap.create(WARArchive.class);
+ deployment.addPackage("pro.taskana");
+ deployment.addClass(TaskanaProducers.class);
+ 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.3-SNAPSHOT");
+ deployment.addAsResource("META-INF/beans.xml");
+ deployment.addAsResource("taskana.properties");
+ deployment.addAsResource("project-defaults.yml");
+ return deployment;
+ }
- @CreateSwarm
- public static Swarm newContainer() throws Exception {
- Swarm swarm = new Swarm();
- return swarm;
- }
+ @CreateSwarm
+ public static Swarm newContainer() throws Exception {
+ Swarm swarm = new Swarm();
+ return swarm;
+ }
- @Before
- public void init() throws SQLException, ClassNotFoundException {
- }
+ @Before
+ public void init() throws SQLException, ClassNotFoundException {
+ }
- @Test
- public void testCommit() throws SQLException, ClassNotFoundException, NamingException {
-
- Client client = ClientBuilder.newClient();
- client.target("http://127.0.0.1:8090/rest/test").request().get();
+ @Test
+ public void testCommit() throws SQLException, ClassNotFoundException, NamingException {
- Class.forName("org.h2.Driver");
- int resultCount = 0;
- try (Connection conn = DriverManager.getConnection("jdbc:h2:~/data/testdb;AUTO_SERVER=TRUE", "SA", "SA")) {
- ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASK");
+ Client client = ClientBuilder.newClient();
+ client.target("http://127.0.0.1:8090/rest/test").request().get();
- while (rs.next()) {
- resultCount++;
- }
- }
+ Class.forName("org.h2.Driver");
+ int resultCount = 0;
+ try (Connection conn = DriverManager.getConnection("jdbc:h2:~/data/testdb;AUTO_SERVER=TRUE", "SA", "SA")) {
+ ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASK");
- Assert.assertEquals(1, resultCount);
- }
-
-
- @Test
- public void testRollback() throws SQLException, ClassNotFoundException, NamingException {
- Client client = ClientBuilder.newClient();
- client.target("http://127.0.0.1:8090/rest/test").request().post(null);
+ while (rs.next()) {
+ resultCount++;
+ }
+ }
- Class.forName("org.h2.Driver");
- int resultCount = 0;
- try (Connection conn = DriverManager.getConnection("jdbc:h2:~/data/testdb;AUTO_SERVER=TRUE", "SA", "SA")) {
- ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASK");
+ Assert.assertEquals(1, resultCount);
+ }
- while (rs.next()) {
- resultCount++;
- }
- }
+ @Test
+ public void testRollback() throws SQLException, ClassNotFoundException, NamingException {
+ Client client = ClientBuilder.newClient();
+ client.target("http://127.0.0.1:8090/rest/test").request().post(null);
- Assert.assertEquals(0, resultCount);
- }
+ Class.forName("org.h2.Driver");
+ int resultCount = 0;
+ try (Connection conn = DriverManager.getConnection("jdbc:h2:~/data/testdb;AUTO_SERVER=TRUE", "SA", "SA")) {
+ ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASK");
+
+ while (rs.next()) {
+ resultCount++;
+ }
+ }
+
+ Assert.assertEquals(0, resultCount);
+ }
}
diff --git a/lib/taskana-core/pom.xml b/lib/taskana-core/pom.xml
index 961d72ae3..2fda1aa91 100644
--- a/lib/taskana-core/pom.xml
+++ b/lib/taskana-core/pom.xml
@@ -35,6 +35,7 @@
1.8
1.8
UTF-8
+ 1.7.1
@@ -141,6 +142,18 @@
2.8.47
test
+
+ org.powermock
+ powermock-module-junit4
+ ${powermock.version}
+ test
+
+
+ org.powermock
+ powermock-api-mockito2
+ ${powermock.version}
+ test
+
com.h2database
h2
diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskService.java b/lib/taskana-core/src/main/java/pro/taskana/TaskService.java
index 56039142f..e3960f828 100644
--- a/lib/taskana-core/src/main/java/pro/taskana/TaskService.java
+++ b/lib/taskana-core/src/main/java/pro/taskana/TaskService.java
@@ -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 getTaskCountForState(List 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 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 getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast, List 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;
+ 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 getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception;
+ List 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 getTaskSummariesByWorkbasketId(String workbasketId) throws WorkbasketNotFoundException;
}
diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java
index 04fc727bb..6da9bf98a 100644
--- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java
+++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java
@@ -42,64 +42,66 @@ 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,
- ObjectReferenceMapper objectReferenceMapper) {
+ ObjectReferenceMapper objectReferenceMapper) {
super();
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.taskMapper = taskMapper;
this.objectReferenceMapper = objectReferenceMapper;
- this.workbasketService = taskanaEngineImpl.getWorkbasketService();
+ this.workbasketService = taskanaEngineImpl.getWorkbasketService();
}
@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);
@@ -155,7 +158,7 @@ public class TaskServiceImpl implements TaskService {
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from createTask(task = {})");
- }
+ }
}
@Override
@@ -191,16 +194,19 @@ 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 states) {
+ public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
+ List states) {
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
- workbasketId, daysInPast, LoggerUtils.listToString(states));
+ LOGGER.debug(
+ "entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
+ workbasketId, daysInPast, LoggerUtils.listToString(states));
}
long result = -1;
try {
@@ -213,12 +219,12 @@ public class TaskServiceImpl implements TaskService {
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from getTaskCountForWorkbasketByDaysInPastAndState(). Returning result {} ", result);
- }
+ }
}
@Override
public Task transfer(String taskId, String destinationWorkbasketId)
- throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
+ throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
Task result = null;
try {
@@ -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();
@@ -255,9 +262,10 @@ public class TaskServiceImpl implements TaskService {
@Override
public List getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
- List states) {
+ List 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 result = null;
try {
@@ -271,8 +279,9 @@ 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: {} ",
- numberOfResultObjects, LoggerUtils.listToString(result));
+ LOGGER.debug(
+ "exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
+ numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
@@ -302,19 +311,22 @@ public class TaskServiceImpl implements TaskService {
}
@Override
- public List getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState) throws WorkbasketNotFoundException, NotAuthorizedException, Exception {
- LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId, taskState);
+ public List getTasksByWorkbasketIdAndState(String workbasketId, TaskState taskState)
+ throws WorkbasketNotFoundException, NotAuthorizedException {
+ LOGGER.debug("entry to getTasksByWorkbasketIdAndState(workbasketId = {}, taskState = {})", workbasketId,
+ taskState);
List 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: {} ",
- numberOfResultObjects, LoggerUtils.listToString(result));
+ LOGGER.debug(
+ "exit from getTasksByWorkbasketIdAndState(workbasketId, taskState). Returning {} resulting Objects: {} ",
+ numberOfResultObjects, LoggerUtils.listToString(result));
}
}
return (result == null) ? new ArrayList<>() : 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,25 +388,25 @@ public class TaskServiceImpl implements TaskService {
public List getTaskSummariesByWorkbasketId(String workbasketId) throws WorkbasketNotFoundException {
LOGGER.debug("entry to getTaskSummariesByWorkbasketId(workbasketId = {}", workbasketId);
List taskSummaries = new ArrayList<>();
- taskanaEngineImpl.getWorkbasketService().getWorkbasket(workbasketId);
+ workbasketService.getWorkbasket(workbasketId);
try {
taskanaEngineImpl.openConnection();
taskSummaries = taskMapper.findTaskSummariesByWorkbasketId(workbasketId);
} catch (Exception ex) {
LOGGER.error("Getting TASKSUMMARY failed internally.", ex);
- } finally {
+ } finally {
if (taskSummaries == null) {
taskSummaries = new ArrayList<>();
}
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = taskSummaries.size();
- LOGGER.debug("exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
- numberOfResultObjects, LoggerUtils.listToString(taskSummaries));
+ LOGGER.debug(
+ "exit from getTaskSummariesByWorkbasketId(workbasketId). Returning {} resulting Objects: {} ",
+ numberOfResultObjects, LoggerUtils.listToString(taskSummaries));
}
}
return taskSummaries;
}
-
}
diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java
index 65209a61c..b02af5224 100644
--- a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java
+++ b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java
@@ -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;
@@ -91,14 +99,15 @@ public class TaskServiceImplTest {
try {
Mockito.doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
} catch (NotAuthorizedException e) {
- e.printStackTrace();
+ e.printStackTrace();
}
Mockito.doNothing().when(taskanaEngineImpl).openConnection();
Mockito.doNothing().when(taskanaEngineImpl).returnConnection();
}
@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());
@@ -118,8 +126,8 @@ public class TaskServiceImplTest {
verify(classificationServiceMock, times(1)).createClassification(any());
verify(classificationServiceMock, times(1)).getClassification(any(), any());
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated());
@@ -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());
@@ -158,10 +166,10 @@ public class TaskServiceImplTest {
verify(taskanaEngineImpl, times(1)).returnConnection();
verify(classificationServiceMock, times(1)).createClassification(any());
verify(classificationServiceMock, times(1)).getClassification(any(),
- any());
+ any());
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated());
@@ -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());
@@ -204,8 +212,8 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated());
@@ -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());
@@ -263,8 +271,8 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).insert(test2);
verify(taskanaEngineImpl, times(2)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
assertNull(test.getOwner());
assertNotNull(test.getCreated());
@@ -282,30 +290,31 @@ 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();
task.setWorkbasketId("1");
- task.setBusinessProcessId("BPI1");
- task.setParentBusinessProcessId("PBPI1");
+ task.setBusinessProcessId("BPI1");
+ task.setParentBusinessProcessId("PBPI1");
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();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
throw e;
}
}
@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,12 +323,11 @@ 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,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
- classificationServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
+ classificationServiceMock);
throw e;
}
}
@@ -328,17 +336,22 @@ 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);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(acturalTask.getState(), equalTo(TaskState.CLAIMED));
assertThat(acturalTask.getCreated(), not(equalTo(expectedTask.getModified())));
@@ -351,20 +364,22 @@ 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);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@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());
@@ -376,7 +391,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).update(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualTask.getState(), equalTo(TaskState.COMPLETED));
assertThat(actualTask.getCreated(), not(equalTo(expectedTask.getModified())));
@@ -393,14 +408,15 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).findById(invalidTaskId);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@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();
@@ -426,7 +443,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).update(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualTask.isRead(), equalTo(false));
assertThat(actualTask.isTransferred(), equalTo(true));
@@ -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,21 +462,22 @@ 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();
verify(taskMapperMock, times(1)).update(any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualTask.isRead(), equalTo(false));
assertThat(actualTask.isTransferred(), equalTo(true));
@@ -467,30 +486,33 @@ 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);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@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);
@@ -502,53 +524,58 @@ public class TaskServiceImplTest {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@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);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@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,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@@ -565,7 +592,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).getTaskCountForState(taskStates);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualResult, equalTo(expectedResult));
}
@@ -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);
@@ -583,7 +611,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualResult, equalTo(expectedResult));
}
@@ -592,15 +620,17 @@ public class TaskServiceImplTest {
final long daysInPast = 10L;
List taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
List expectedResult = new ArrayList<>();
- doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
+ doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class),
+ any());
- List actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast, taskStates);
+ List actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,
+ taskStates);
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualResult, equalTo(expectedResult));
}
@@ -618,7 +648,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).update(task);
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualTask.getModified(), not(equalTo(null)));
assertThat(actualTask.isRead(), equalTo(true));
}
@@ -636,7 +666,7 @@ public class TaskServiceImplTest {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@@ -652,7 +682,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
assertThat(actualTask, equalTo(expectedTask));
}
@@ -668,7 +698,7 @@ public class TaskServiceImplTest {
verify(taskMapperMock, times(1)).findById(task.getId());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
- taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
+ taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
throw e;
}
}
@@ -679,9 +709,9 @@ public class TaskServiceImplTest {
String workbasketId = "1";
List 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,18 +733,16 @@ public class TaskServiceImplTest {
List 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 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);
verify(taskanaEngineImpl, times(1)).returnConnection();
- verifyNoMoreInteractions(taskMapperMock, taskanaEngineImpl, workbasketServiceMock);
+ verifyNoMoreInteractions(taskMapperMock, taskanaEngineImpl, workbasketServiceMock);
assertThat(actualResultList, equalTo(expectedResultList));
assertThat(actualResultList.size(), equalTo(expectedResultList.size()));
}
@@ -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 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);
diff --git a/rest/pom.xml b/rest/pom.xml
index 22dbe9e79..2273b407e 100644
--- a/rest/pom.xml
+++ b/rest/pom.xml
@@ -5,7 +5,7 @@
pro.taskana
rest
- 0.0.1-SNAPSHOT
+ 0.0.2-SNAPSHOT
jar
rest
@@ -37,7 +37,7 @@
pro.taskana
taskana-core
- 0.0.1-SNAPSHOT
+ 0.0.3-SNAPSHOT