TSK-126: Query workbaskets by task, adding Authentification, expanding REST getAllWorkbaskets, updated Tests

This commit is contained in:
Marcel Lengl 2018-01-09 14:20:40 +01:00 committed by Holger Hagen
parent 588c30887c
commit 2b8ab6b16d
34 changed files with 938 additions and 848 deletions

View File

@ -6,6 +6,7 @@ import pro.taskana.exceptions.NotAuthorizedException;
/**
* Main query interface.
*
* @author EH
* @param <T>
* specifies the return type of the follwing methods
@ -14,25 +15,32 @@ public interface BaseQuery<T> {
/**
* This method will return a list of defined {@link T} objects.
* @return TODO
* @throws NotAuthorizedException TODO
*
* @return List containing elements of type T
* @throws NotAuthorizedException
* if the permissions are not granted for this specific interaction with query.
*/
List<T> list() throws NotAuthorizedException;
/**
* This method will return a list of defined {@link T} objects with specified
* offset and an limit.
* @param offset TODO
* @param limit TODO
* @return TODO
* @throws NotAuthorizedException TODO
* This method will return a list of defined {@link T} objects with specified offset and an limit.
*
* @param offset
* index of the first element which should be returned.
* @param limit
* amount of elements which should be returned beginning on offset.
* @return List containing elements of type T
* @throws NotAuthorizedException
* if the permissions are not granted for this specific interaction with query.
*/
List<T> list(int offset, int limit) throws NotAuthorizedException;
/**
* This method will return a single object of {@link T}.
* @return TODO
* @throws NotAuthorizedException TODO
*
* @return T a single object of given Type.
* @throws NotAuthorizedException
* if the permissions for interactions are not granted.
*/
T single() throws NotAuthorizedException;

View File

@ -4,6 +4,7 @@ import java.util.List;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
/**
@ -16,9 +17,11 @@ public interface ClassificationService {
*
* @return The List of all Classifications
* @throws NotAuthorizedException
* TODO
* if the permissions are not granted for this specific interaction.
* @throws InvalidArgumentException
* if the given permissions/UserContext or Base-Object is NULL.
*/
List<Classification> getClassificationTree() throws NotAuthorizedException;
List<Classification> getClassificationTree() throws NotAuthorizedException, InvalidArgumentException;
/**
* Get all Classifications with the given key. Returns also older and domain-specific versions of the

View File

@ -110,7 +110,7 @@ public interface TaskService {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException;
/**
* Get the details of a task by Id.
* Get the details of a task by Id without checking permissions.
*
* @param taskId
* the id of the task
@ -186,9 +186,11 @@ public interface TaskService {
* if a Work basket can´t be located.
* @throws InvalidWorkbasketException
* thrown if the Workbasket specified with workbasketId has a missing required property
* @throws NotAuthorizedException
* if the current user got no rights for reading on this work basket.
*/
List<TaskSummary> getTaskSummariesByWorkbasketKey(String workbasketKey)
throws WorkbasketNotFoundException, InvalidWorkbasketException;
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException;
/**
* Returns a not persisted instance of {@link Task}.

View File

@ -103,16 +103,31 @@ public interface WorkbasketQuery extends BaseQuery<Workbasket> {
WorkbasketQuery ownerIn(String... owners);
/**
* Add the access requested.
* Setting up the permission which should be granted on the result workbaskets and the users which should be
* checked. READ permission will always be checked by default.<br>
* The AccessIds and the given permission will throw a Exception if they would be NULL.
*
* @param permission
* the permissions requested
* which should be used for results.
* @param accessIds
* the accessIds as String
* @return the query
* Users which sould be checked for given permissions on workbaskets.
* @return the current query object.
* @throws InvalidArgumentException
* if any argument is not specified
* when permission OR the accessIds are NULL.
*/
WorkbasketQuery access(WorkbasketAuthorization permission, String... accessIds) throws InvalidArgumentException;
WorkbasketQuery accessIdsHavePersmission(WorkbasketAuthorization permission, String... accessIds)
throws InvalidArgumentException;
/**
* Setting up the permissions for the accessIds of the CurrentUserContext. READ permissions need to be granted,too
* by default.<br>
* The UserContext-AccessIds and the given permission will throw a Exception if they would be NULL.
*
* @param permission
* which should be used for results.
* @return the current query object.
* @throws InvalidArgumentException
* when permission OR accessIds of the userContext are NULL.
*/
WorkbasketQuery callerHasPermission(WorkbasketAuthorization permission) throws InvalidArgumentException;
}

View File

@ -21,10 +21,11 @@ public interface WorkbasketService {
* @return the requested Workbasket
* @throws WorkbasketNotFoundException
* If the Workbasket with workbasketId is not found
* @throws InvalidWorkbasketException
* If required properties are missing in the found Workbasket
* @throws NotAuthorizedException
* If the current user or group does not have the permissions for interactions.
*/
Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException, InvalidWorkbasketException;
Workbasket getWorkbasket(String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException;
/**
* Get Workbasket for a given key.
@ -34,13 +35,14 @@ public interface WorkbasketService {
* @return the requested Workbasket
* @throws WorkbasketNotFoundException
* If the Workbasket with workbasketId is not found
* @throws InvalidWorkbasketException
* If required properties are missing in the found Workbasket
* @throws NotAuthorizedException
* If the current user or group does not have the permissions for interactions.
*/
Workbasket getWorkbasketByKey(String workbasketKey) throws WorkbasketNotFoundException, InvalidWorkbasketException;
Workbasket getWorkbasketByKey(String workbasketKey)
throws WorkbasketNotFoundException, NotAuthorizedException;
/**
* Get all available Workbaskets.
* Get all available Workbaskets without checking any permission.
*
* @return a list containing all Workbaskets
*/
@ -55,9 +57,12 @@ public interface WorkbasketService {
* @throws InvalidWorkbasketException
* If a required property of the Workbasket is not set.
* @throws WorkbasketNotFoundException
* If the to be created work basket references a distribution target that does not exist
* If the to be created work basket references a distribution target that does not exist.
* @throws NotAuthorizedException
* If the current user or group does not have the permissions for interactions.
*/
Workbasket createWorkbasket(Workbasket workbasket) throws InvalidWorkbasketException, WorkbasketNotFoundException;
Workbasket createWorkbasket(Workbasket workbasket)
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException;
/**
* Update a Workbasket.
@ -138,16 +143,6 @@ public interface WorkbasketService {
*/
List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketKey);
/**
* This method returns the workbaskets for which the current user has all permissions specified in the permissions
* list.
*
* @param permission
* a List of WorkbasketAuthorization enums
* @return all Workbaskets for which the current user has the specified authorizations
*/
List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permission);
/**
* This method provides a query builder for querying the database.
*
@ -161,4 +156,14 @@ public interface WorkbasketService {
* @return newWorkbasket
*/
Workbasket newWorkbasket();
/**
* This method returns the workbaskets for which the current user has all permissions specified in the permissions
* list.
*
* @param permissions
* a List of WorkbasketAuthorization enums
* @return all Workbaskets for which the current user has the specified authorizations
*/
List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions);
}

View File

@ -15,6 +15,7 @@ import pro.taskana.ClassificationService;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils;
@ -38,7 +39,7 @@ public class ClassificationServiceImpl implements ClassificationService {
}
@Override
public List<Classification> getClassificationTree() throws NotAuthorizedException {
public List<Classification> getClassificationTree() throws NotAuthorizedException, InvalidArgumentException {
LOGGER.debug("entry to getClassificationTree()");
List<Classification> result = null;
try {
@ -61,7 +62,7 @@ public class ClassificationServiceImpl implements ClassificationService {
}
private List<Classification> populateChildClassifications(List<Classification> classifications)
throws NotAuthorizedException {
throws NotAuthorizedException, InvalidArgumentException {
try {
taskanaEngineImpl.openConnection();
List<Classification> children = new ArrayList<>();

View File

@ -25,9 +25,7 @@ public class TaskQueryImpl implements TaskQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
private static final Logger LOGGER = LoggerFactory.getLogger(TaskQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl;
private String[] name;
private String description;
private int[] priority;
@ -250,8 +248,8 @@ public class TaskQueryImpl implements TaskQuery {
private void checkAuthorization() throws NotAuthorizedException {
if (this.workbasketKey != null && this.workbasketKey.length > 0) {
for (String workbasket : this.workbasketKey) {
taskanaEngineImpl.getWorkbasketService().checkAuthorization(workbasket, WorkbasketAuthorization.OPEN);
for (String wbKey : this.workbasketKey) {
taskanaEngineImpl.getWorkbasketService().checkAuthorization(wbKey, WorkbasketAuthorization.OPEN);
}
}
}

View File

@ -392,7 +392,7 @@ public class TaskServiceImpl implements TaskService {
@Override
public List<TaskSummary> getTaskSummariesByWorkbasketKey(String workbasketKey)
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
LOGGER.debug("entry to getTaskSummariesByWorkbasketId(workbasketId = {}", workbasketKey);
List<TaskSummary> taskSummaries = new ArrayList<>();
workbasketService.getWorkbasketByKey(workbasketKey);

View File

@ -13,10 +13,11 @@ import pro.taskana.Workbasket;
import pro.taskana.WorkbasketQuery;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.WorkbasketType;
import pro.taskana.model.mappings.WorkbasketAccessMapper;
import pro.taskana.security.CurrentUserContext;
/**
* WorkbasketQuery for generating dynamic SQL.
@ -26,9 +27,7 @@ import pro.taskana.model.WorkbasketType;
public class WorkbasketQueryImpl implements WorkbasketQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryWorkbasket";
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketQueryImpl.class);
private String[] accessId;
private WorkbasketAuthorization authorization;
private String[] name;
@ -43,7 +42,7 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
private String[] owner;
private TaskanaEngineImpl taskanaEngineImpl;
public WorkbasketQueryImpl(TaskanaEngine taskanaEngine) {
public WorkbasketQueryImpl(TaskanaEngine taskanaEngine, WorkbasketAccessMapper workbasketAccessMapper) {
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
}
@ -108,75 +107,96 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
}
@Override
public WorkbasketQuery access(WorkbasketAuthorization permission, String... accessIds)
public WorkbasketQuery accessIdsHavePersmission(WorkbasketAuthorization permission, String... accessIds)
throws InvalidArgumentException {
// Checking pre-conditions
if (permission == null) {
throw new InvalidArgumentException("permission must not be null");
throw new InvalidArgumentException("Permission can´t be null.");
}
if (accessIds == null || accessIds.length == 0) {
throw new InvalidArgumentException("accessIds must not be empty");
throw new InvalidArgumentException("accessIds can´t be NULL or empty.");
}
// set up permissions and ids
this.authorization = permission;
this.accessId = accessIds;
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
for (int i = 0; i < accessIds.length; i++) {
String id = accessIds[i];
if (id != null) {
accessIds[i] = id.toLowerCase();
}
}
}
lowercaseAccessIds();
return this;
}
@Override
public List<Workbasket> list() throws NotAuthorizedException {
public WorkbasketQuery callerHasPermission(WorkbasketAuthorization permission) throws InvalidArgumentException {
String[] accessIds;
// Check pre-conditions
if (permission == null) {
throw new InvalidArgumentException("Permission can´t be null.");
}
if (CurrentUserContext.getAccessIds() != null && CurrentUserContext.getAccessIds().size() > 0) {
accessIds = new String[CurrentUserContext.getAccessIds().size()];
accessIds = CurrentUserContext.getAccessIds().toArray(accessIds);
} else {
throw new InvalidArgumentException("CurrentUserContext need to have at least one accessId.");
}
// set up permissions and ids
accessIds = new String[CurrentUserContext.getAccessIds().size()];
accessIds = CurrentUserContext.getAccessIds().toArray(accessIds);
this.authorization = permission;
this.accessId = accessIds;
lowercaseAccessIds();
return this;
}
@Override
public List<Workbasket> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<Workbasket> result = null;
List<Workbasket> workbaskets = null;
try {
taskanaEngineImpl.openConnection();
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
workbaskets = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return workbaskets;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
LoggerUtils.listToString(workbaskets));
}
}
}
@Override
public List<Workbasket> list(int offset, int limit) throws NotAuthorizedException {
public List<Workbasket> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<Workbasket> result = null;
List<Workbasket> workbaskets = null;
try {
taskanaEngineImpl.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
workbaskets = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return workbaskets;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
LoggerUtils.listToString(workbaskets));
}
}
}
@Override
public Workbasket single() throws NotAuthorizedException {
public Workbasket single() {
LOGGER.debug("entry to single(), this = {}", this);
WorkbasketImpl result = null;
WorkbasketImpl workbasket = null;
try {
taskanaEngineImpl.openConnection();
result = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return result;
workbasket = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return workbasket;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
LOGGER.debug("exit from single(). Returning result {} ", workbasket);
}
}
@ -307,4 +327,14 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
return builder.toString();
}
private void lowercaseAccessIds() {
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
for (int i = 0; i < this.accessId.length; i++) {
String id = this.accessId[i];
if (id != null) {
this.accessId[i] = id.toLowerCase();
}
}
}
}
}

View File

@ -33,7 +33,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketServiceImpl.class);
private static final String ID_PREFIX_WORKBASKET = "WBI";
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketMapper workbasketMapper;
@ -54,21 +53,19 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasket(String workbasketId)
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
Workbasket result = null;
try {
taskanaEngineImpl.openConnection();
result = workbasketMapper.findById(workbasketId);
if (result == null) {
LOGGER.warn(
"Method getWorkbasket() didn't find workbasket with id {}. Throwing WorkbasketNotFoundException",
LOGGER.error(
"Method getWorkbasket() didn't find workbasket with ID {}. Throwing WorkbasketNotFoundException",
workbasketId);
throw new WorkbasketNotFoundException(workbasketId);
} else {
validateWorkbasket(result);
}
this.checkAuthorization(result.getKey(), WorkbasketAuthorization.READ);
return result;
} finally {
taskanaEngineImpl.returnConnection();
@ -78,21 +75,19 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasketByKey(String workbasketKey)
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getWorkbasketByKey(workbasketKey = {})", workbasketKey);
Workbasket result = null;
try {
taskanaEngineImpl.openConnection();
result = workbasketMapper.findByKey(workbasketKey);
if (result == null) {
LOGGER.warn(
"Method getWorkbasket() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException",
LOGGER.error(
"Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException",
workbasketKey);
throw new WorkbasketNotFoundException(workbasketKey);
} else {
validateWorkbasket(result);
}
this.checkAuthorization(workbasketKey, WorkbasketAuthorization.READ);
return result;
} finally {
taskanaEngineImpl.returnConnection();
@ -146,9 +141,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
}
@Override
public Workbasket createWorkbasket(Workbasket newWorkbasket)
throws InvalidWorkbasketException, WorkbasketNotFoundException {
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to createtWorkbasket(workbasket)", newWorkbasket);
Workbasket result = null;
WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket;
@ -167,7 +161,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
if (workbasket.getDistributionTargets() != null) {
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
// validate that all distribution targets exist
getWorkbasket(distributionTarget.getId());
this.getWorkbasket(distributionTarget.getId());
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
LOGGER.debug("Method createWorkbasket() created distributiontarget for source '{}' and target {}",
workbasket.getId(), distributionTarget.getId());
@ -353,7 +347,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public WorkbasketQuery createWorkbasketQuery() {
return new WorkbasketQueryImpl(taskanaEngine);
return new WorkbasketQueryImpl(taskanaEngine, workbasketAccessMapper);
}
private void validateWorkbasket(Workbasket workbasket) throws InvalidWorkbasketException {

View File

@ -11,12 +11,16 @@ public final class IdGenerator {
/**
* This method create an id with an specific prefix.
*
* @param prefix
* only 3 characters!
* @return a String with a length of 40 characters
*/
public static String generateWithPrefix(String prefix) {
return new StringBuilder().append(prefix).append(SEPERATOR).append(UUID.randomUUID().toString()).toString();
return new StringBuilder().append(prefix)
.append(SEPERATOR)
.append(UUID.randomUUID().toString())
.toString();
}
private IdGenerator() {

View File

@ -71,7 +71,7 @@ public interface QueryMapper {
+ "</if>"
+ "</where>"
+ "</script>")
@Results(value = {@Result(property = "id", column = "ID"),
@Results(value = { @Result(property = "id", column = "ID"),
@Result(property = "created", column = "CREATED"),
@Result(property = "claimed", column = "CLAIMED"),
@Result(property = "completed", column = "COMPLETED"),
@ -102,7 +102,7 @@ public interface QueryMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
List<TaskImpl> queryTasks(TaskQueryImpl taskQuery);
@Select("<script>SELECT ID, KEY, PARENT_CLASSIFICATION_KEY, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, APPLICATION_ENTRY_POINT, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8, VALID_FROM, VALID_UNTIL "
@ -125,7 +125,7 @@ public interface QueryMapper {
+ "<if test='validUntil != null'>AND VALID_UNTIL IN(<foreach item='item' collection='validUntil' separator=',' >#{item}</foreach>)</if> "
+ "</where>"
+ "</script>")
@Results({@Result(property = "id", column = "ID"),
@Results({ @Result(property = "id", column = "ID"),
@Result(property = "parentClassificationId", column = "PARENT_CLASSIFICATION_ID"),
@Result(property = "category", column = "CATEGORY"),
@Result(property = "type", column = "TYPE"),
@ -145,7 +145,7 @@ public interface QueryMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "validFrom", column = "VALID_FROM"),
@Result(property = "validUntil", column = "VALID_UNTIL")})
@Result(property = "validUntil", column = "VALID_UNTIL") })
List<ClassificationImpl> queryClassification(ClassificationQueryImpl classificationQuery);
@Select("<script>SELECT ID, COMPANY, SYSTEM, SYSTEM_INSTANCE, TYPE, VALUE "
@ -164,7 +164,7 @@ public interface QueryMapper {
@Result(property = "system", column = "SYSTEM"),
@Result(property = "systemInstance", column = "SYSTEM_INSTANCE"),
@Result(property = "type", column = "TYPE"),
@Result(property = "value", column = "VALUE")})
@Result(property = "value", column = "VALUE") })
List<ObjectReference> queryObjectReference(ObjectReferenceQueryImpl objectReference);
@Select("<script>SELECT w.ID, w.KEY, w.CREATED, w.MODIFIED, w.NAME, w.DOMAIN, W.TYPE, w.DESCRIPTION, w.OWNER, w.CUSTOM_1, w.CUSTOM_2, w.CUSTOM_3, w.CUSTOM_4, w.ORG_LEVEL_1, w.ORG_LEVEL_2, w.ORG_LEVEL_3, w.ORG_LEVEL_4 from WORKBASKET w "
@ -180,7 +180,7 @@ public interface QueryMapper {
+ "<if test='modifiedAfter != null'>AND w.MODIFIED &gt; #{modifiedAfter}</if> "
+ "<if test='modifiedBefore != null'>AND w.MODIFIED &lt; #{modifiedBefore}</if> "
+ "<if test='description != null'>AND w.DESCRIPTION like #{description}</if> "
+ "<if test='accessId != null'>AND a.ACCESS_ID IN(<foreach item='item' collection='accessId' separator=',' >#{item}</foreach>)</if> "
+ "<if test='accessId != null'>AND a.ACCESS_ID IN(<foreach item='item' collection='accessId' separator=',' >#{item}</foreach>) AND PERM_READ = 1 </if> "
+ "<if test='authorization != null'>AND "
+ "<if test=\"authorization.name().equals('OPEN')\">PERM_OPEN</if> "
+ "<if test=\"authorization.name().equals('READ')\">PERM_READ</if>"
@ -217,7 +217,7 @@ public interface QueryMapper {
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
List<WorkbasketImpl> queryWorkbasket(WorkbasketQueryImpl workbasketQuery);
@Select("<script>SELECT TARGET_ID from DISTRIBUTION_TARGETS "
@ -226,7 +226,7 @@ public interface QueryMapper {
+ "</where>"
+ "</script>")
@Results(value = {
@Result(property = "distributionTarget", column = "TARGET_ID")})
@Result(property = "distributionTarget", column = "TARGET_ID") })
List<String> findDistributionTargets(String sourceId);
}

View File

@ -22,7 +22,7 @@ import pro.taskana.model.WorkbasketAuthorization;
public interface WorkbasketMapper {
@Select("SELECT ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1 ,CUSTOM_2 ,CUSTOM_3 ,CUSTOM_4 ,ORG_LEVEL_1 ,ORG_LEVEL_2 ,ORG_LEVEL_3 ,ORG_LEVEL_4 FROM WORKBASKET WHERE ID = #{id}")
@Results(value = {@Result(property = "id", column = "ID"),
@Results(value = { @Result(property = "id", column = "ID"),
@Result(property = "key", column = "KEY"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
@ -42,11 +42,11 @@ public interface WorkbasketMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
WorkbasketImpl findById(@Param("id") String id);
@Select("SELECT ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1 ,CUSTOM_2 ,CUSTOM_3 ,CUSTOM_4 ,ORG_LEVEL_1 ,ORG_LEVEL_2 ,ORG_LEVEL_3 ,ORG_LEVEL_4 FROM WORKBASKET WHERE KEY = #{key}")
@Results(value = {@Result(property = "id", column = "ID"),
@Results(value = { @Result(property = "id", column = "ID"),
@Result(property = "key", column = "KEY"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
@ -66,7 +66,7 @@ public interface WorkbasketMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
WorkbasketImpl findByKey(@Param("key") String key);
@Select("SELECT * FROM WORKBASKET WHERE id IN (SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{id})")
@ -91,7 +91,7 @@ public interface WorkbasketMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
List<WorkbasketImpl> findByDistributionTargets(@Param("id") String id);
@Select("SELECT * FROM WORKBASKET ORDER BY id")
@ -116,7 +116,7 @@ public interface WorkbasketMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
List<WorkbasketImpl> findAll();
@Select("<script>SELECT W.ID, W.KEY, W.CREATED, W.MODIFIED, W.NAME, W.DESCRIPTION, W.OWNER FROM WORKBASKET AS W "
@ -158,7 +158,7 @@ public interface WorkbasketMapper {
@Result(property = "custom7", column = "CUSTOM_7"),
@Result(property = "custom8", column = "CUSTOM_8"),
@Result(property = "custom9", column = "CUSTOM_9"),
@Result(property = "custom10", column = "CUSTOM_10")})
@Result(property = "custom10", column = "CUSTOM_10") })
List<WorkbasketImpl> findByPermission(@Param("authorizations") List<WorkbasketAuthorization> authorizations,
@Param("accessId") String accessId);

View File

@ -12,6 +12,7 @@ import acceptance.AbstractAccTest;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
/**
@ -25,7 +26,7 @@ public class GetClassificationAccTest extends AbstractAccTest {
@Test
public void testFindAllClassifications()
throws SQLException, ClassificationNotFoundException, NotAuthorizedException {
throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<Classification> classificationList = classificationService.getClassificationTree();
Assert.assertNotNull(classificationList);

View File

@ -15,6 +15,7 @@ import acceptance.AbstractAccTest;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
/**
@ -28,7 +29,7 @@ public class QueryClassificationAccTest extends AbstractAccTest {
@Test
public void testFindClassificationsByCategoryAndDomain()
throws SQLException, ClassificationNotFoundException, NotAuthorizedException {
throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<Classification> classificationList = classificationService.createClassificationQuery()
.category("MANUAL")
@ -42,7 +43,7 @@ public class QueryClassificationAccTest extends AbstractAccTest {
@Ignore
@Test
public void testGetOneClassificationForMultipleDomains()
throws SQLException, ClassificationNotFoundException, NotAuthorizedException {
throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<Classification> classifications = classificationService.createClassificationQuery()
.type("L10000")

View File

@ -32,7 +32,7 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
@WithAccessId(
userName = "user_1_1",
groupNames = { "group_1" })
groupNames = { "teamlead_1" })
@Test
public void testGetWorkbasket()
throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,

View File

@ -6,7 +6,6 @@ import java.util.List;
import org.h2.store.fs.FileUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -34,7 +33,7 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<Workbasket> results = workbasketService.createWorkbasketQuery()
.access(WorkbasketAuthorization.APPEND, "user_1_1")
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1")
.list();
Assert.assertEquals(1L, results.size());
Assert.assertEquals("USER_1_1", results.get(0).getKey());
@ -45,12 +44,11 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<Workbasket> results = workbasketService.createWorkbasketQuery()
.access(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
.list();
Assert.assertEquals(8L, results.size());
}
@Ignore
@WithAccessId(
userName = "user_1_1",
groupNames = { "group_1" })
@ -59,23 +57,21 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<Workbasket> results = workbasketService.createWorkbasketQuery()
.access(WorkbasketAuthorization.APPEND)
.callerHasPermission(WorkbasketAuthorization.APPEND)
.list();
Assert.assertEquals(7L, results.size());
Assert.assertEquals(8L, results.size());
}
@Ignore
@WithAccessId(
userName = "user_1_1",
groupNames = { "group_1" })
userName = "user_1_1")
@Test
public void testQueryAllAvailableWorkbasketForOpeningForUserAndGroupFromSubject()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
// WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
// List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
// .access(WorkbasketAuthorization.OPEN)
// .list();
// Assert.assertEquals(7L, results.size());
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<Workbasket> results = workbasketService.createWorkbasketQuery()
.callerHasPermission(WorkbasketAuthorization.READ)
.list();
Assert.assertEquals(1L, results.size());
}
@AfterClass

View File

@ -15,22 +15,24 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Classification;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
/**
* Test for ClassificationQueryImpl.
*
* @author EH
*/
@RunWith(MockitoJUnitRunner.class)
public class ClassificationQueryImplTest {
ClassificationQueryImpl classificationQueryImpl;
private ClassificationQueryImpl classificationQueryImpl;
@Mock
TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngine;
@Mock
SqlSession sqlSession;
private SqlSession sqlSession;
@Before
public void setup() {
@ -38,32 +40,42 @@ public class ClassificationQueryImplTest {
}
@Test
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
.parentClassificationKey("superId").list();
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber")
.type("cool", "bla")
.priority(1, 2)
.parentClassificationKey("superId")
.list();
Assert.assertNotNull(result);
}
@Test
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnListWithOffset_when_BuilderIsUsed()
throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
.parentClassificationKey("superId").list(1, 1);
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber")
.type("cool", "bla")
.priority(1, 2)
.parentClassificationKey("superId")
.list(1, 1);
Assert.assertNotNull(result);
}
@Test
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectOne(any(), any())).thenReturn(new ClassificationImpl());
Classification result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
.parentClassificationKey("superId").single();
Classification result = classificationQueryImpl.name("test", "asd", "blubber")
.type("cool", "bla")
.priority(1, 2)
.parentClassificationKey("superId")
.single();
Assert.assertNotNull(result);
}
}

View File

@ -26,6 +26,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Classification;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.model.mappings.ClassificationMapper;
@ -59,7 +60,7 @@ public class ClassificationServiceImplTest {
}
@Test
public void testGetClassificationTree() throws NotAuthorizedException {
public void testGetClassificationTree() throws NotAuthorizedException, InvalidArgumentException {
List<Classification> classifications = new ArrayList<>();
doReturn(classificationQueryImplMock).when(cutSpy).createClassificationQuery();

View File

@ -14,11 +14,13 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.model.ObjectReference;
/**
* Test for ObjectReferenceQueryImpl.
*
* @author EH
*/
@RunWith(MockitoJUnitRunner.class)
@ -38,32 +40,42 @@ public class ObjectReferenceQueryImplTest {
}
@Test
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
.systemInstance("1", "2").system("superId").list();
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber")
.type("cool", "bla")
.systemInstance("1", "2")
.system("superId")
.list();
Assert.assertNotNull(result);
}
@Test
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnListWithOffset_when_BuilderIsUsed()
throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
.systemInstance("1", "2").system("superId").list(1, 1);
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber")
.type("cool", "bla")
.systemInstance("1", "2")
.system("superId")
.list(1, 1);
Assert.assertNotNull(result);
}
@Test
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectOne(any(), any())).thenReturn(new ObjectReference());
ObjectReference result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
.systemInstance("1", "2").system("superId").single();
ObjectReference result = objectReferenceQueryImpl.value("test", "asd", "blubber")
.type("cool", "bla")
.systemInstance("1", "2")
.system("superId")
.single();
Assert.assertNotNull(result);
}
}

View File

@ -15,23 +15,25 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Task;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.model.TaskState;
/**
* Test for TaskQueryImpl.
*
* @author EH
*/
@RunWith(MockitoJUnitRunner.class)
public class TaskQueryImplTest {
TaskQueryImpl taskQueryImpl;
private TaskQueryImpl taskQueryImpl;
@Mock
TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngine;
@Mock
SqlSession sqlSession;
private SqlSession sqlSession;
@Before
public void setup() {
@ -39,32 +41,42 @@ public class TaskQueryImplTest {
}
@Test
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED).list();
List<Task> result = taskQueryImpl.name("test", "asd", "blubber")
.customFields("cool", "bla")
.priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED)
.list();
Assert.assertNotNull(result);
}
@Test
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnListWithOffset_when_BuilderIsUsed()
throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED).list(1, 1);
List<Task> result = taskQueryImpl.name("test", "asd", "blubber")
.customFields("cool", "bla")
.priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED)
.list(1, 1);
Assert.assertNotNull(result);
}
@Test
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException, InvalidArgumentException {
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
when(sqlSession.selectOne(any(), any())).thenReturn(new TaskImpl());
Task result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED).single();
Task result = taskQueryImpl.name("test", "asd", "blubber")
.customFields("cool", "bla")
.priority(1, 2)
.state(TaskState.CLAIMED, TaskState.COMPLETED)
.single();
Assert.assertNotNull(result);
}
}

View File

@ -839,7 +839,7 @@ doNothing().when(taskMapperMock).update(any());
@Test
public void testGetTaskSummariesByWorkbasketIdWithInternalException()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
// given - set behaviour and expected result
String workbasketKey = "1";
List<TaskSummary> expectedResultList = new ArrayList<>();
@ -864,7 +864,7 @@ doNothing().when(taskMapperMock).update(any());
@Test
public void testGetTaskSummariesByWorkbasketIdGettingResults()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
String workbasketKey = "1";
List<TaskSummary> expectedResultList = Arrays.asList(new TaskSummary(), new TaskSummary());
doNothing().when(taskanaEngineImpl).openConnection();
@ -886,7 +886,7 @@ doNothing().when(taskMapperMock).update(any());
@Test
public void testGetTaskSummariesByWorkbasketIdGettingNull()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
String workbasketKey = "1";
List<TaskSummary> expectedResultList = new ArrayList<>();
doNothing().when(taskanaEngineImpl).openConnection();

View File

@ -1,21 +1,28 @@
package pro.taskana.impl;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Workbasket;
@ -23,7 +30,6 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.WorkbasketType;
import pro.taskana.model.mappings.DistributionTargetMapper;
@ -38,343 +44,359 @@ import pro.taskana.model.mappings.WorkbasketMapper;
@RunWith(MockitoJUnitRunner.class)
public class WorkbasketServiceImplTest {
private static final int THREE = 3;
private static final int SLEEP_TIME = 100;
@Spy
@InjectMocks
WorkbasketServiceImpl workbasketServiceImpl;
private WorkbasketServiceImpl cutSpy;
@Mock
WorkbasketMapper workbasketMapper;
private WorkbasketMapper workbasketMapperMock;
@Mock
DistributionTargetMapper distributionTargetMapper;
private DistributionTargetMapper distributionTargetMapperMock;
@Mock
WorkbasketAccessMapper workbasketAccessMapper;
private WorkbasketAccessMapper workbasketAccessMapperMock;
@Mock
TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngineImplMock;
@Mock
TaskanaEngineImpl taskanaEngineImpl;
@Mock
TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngineConfiguration taskanaEngineConfigurationMock;
@Before
public void setup() {
public void setup() throws NotAuthorizedException {
MockitoAnnotations.initMocks(this);
}
@Test(expected = InvalidWorkbasketException.class)
public void should_throw_InvalidWorkbasketException_when_empty_Workbasket_is_found()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
when(workbasketMapper.findById(any())).thenReturn(new WorkbasketImpl());
@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketById_NonAuthorizedUser()
throws WorkbasketNotFoundException, NotAuthorizedException {
String wbId = "ID-1";
Workbasket wb = createTestWorkbasket(wbId, "Key-1");
WorkbasketAuthorization authorization = WorkbasketAuthorization.READ;
doReturn(wb).when(workbasketMapperMock).findById(wbId);
doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wb.getKey(), authorization);
Workbasket workbasket = workbasketServiceImpl.getWorkbasket("fail");
Assert.assertNull(workbasket);
}
@Test(expected = WorkbasketNotFoundException.class)
public void should_ThrowWorkbasketNotFoundException_when_WorkbasketIdDoesNotExist()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
workbasketServiceImpl.getWorkbasket("fail");
}
@Test
public void should_ReturnListOfWorkbaskets_when_PermissionAndUserExists() {
when(workbasketMapper.findByPermission(any(), any())).thenReturn(new ArrayList<WorkbasketImpl>());
List<WorkbasketAuthorization> authorizations = new ArrayList<>();
authorizations.add(WorkbasketAuthorization.OPEN);
authorizations.add(WorkbasketAuthorization.APPEND);
List<Workbasket> workbaskets = workbasketServiceImpl.getWorkbaskets(authorizations);
verify(workbasketMapper).findByPermission(any(), any());
Assert.assertNotNull(workbaskets);
}
@Test
public void should_ReturnAllWorkbaskets_when_AllWorkbaskets() {
when(workbasketMapper.findAll()).thenReturn(new ArrayList<WorkbasketImpl>());
List<Workbasket> workbaskets = workbasketServiceImpl.getWorkbaskets();
verify(workbasketMapper).findAll();
Assert.assertNotNull(workbaskets);
}
@Test
public void should_InitializeAndStoreWorkbasket_when_WorkbasketIsCreated()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
doNothing().when(workbasketMapper).insert(any());
WorkbasketImpl workbasket = new WorkbasketImpl();
workbasket.setId("1");
workbasket.setKey("myKey");
workbasket.setName("workbasket");
workbasket.setType(WorkbasketType.PERSONAL);
workbasket.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket);
Assert.assertEquals("1", workbasket.getId());
Assert.assertEquals(workbasket.getModified(), workbasket.getCreated());
verify(workbasketMapper).insert(any());
}
@SuppressWarnings("serial")
@Test
public void should_InitializeAndStoreWorkbasket_when_WorkbasketWithDistributionTargetsIsCreated()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
doNothing().when(workbasketMapper).insert(any());
doNothing().when(distributionTargetMapper).insert(any(), any());
WorkbasketImpl workbasket = new WorkbasketImpl();
workbasket.setId("1");
workbasket.setKey("myKey1");
WorkbasketImpl workbasket1 = new WorkbasketImpl();
workbasket1.setId("2");
WorkbasketImpl workbasket2 = new WorkbasketImpl();
workbasket1.setKey("myKey2");
workbasket1.setName("workbasket2");
workbasket1.setType(WorkbasketType.PERSONAL);
workbasket1.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket1);
when(workbasketMapper.findById("2")).thenReturn(workbasket1);
workbasket2.setId("3");
workbasket2.setKey("myKey3");
workbasket2.setName("workbasket3");
workbasket2.setType(WorkbasketType.PERSONAL);
workbasket2.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket2);
when(workbasketMapper.findById("3")).thenReturn(workbasket2);
workbasket.setDistributionTargets(new ArrayList<Workbasket>() {
{
add(workbasket1);
add(workbasket2);
}
});
workbasket.setKey("myKey");
workbasket.setName("workbasket");
workbasket.setType(WorkbasketType.PERSONAL);
workbasket.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket);
Assert.assertEquals("1", workbasket.getId());
Assert.assertEquals(workbasket.getModified(), workbasket.getCreated());
verify(workbasketMapper, times(THREE)).insert(any());
verify(distributionTargetMapper, times(2)).insert(any(), any());
}
@Test
public void should_ReturnUpdatedWorkbasket_when_ExistingWorkbasketDescriptionIsChanged()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
doNothing().when(workbasketMapper).insert(any());
WorkbasketImpl workbasket = new WorkbasketImpl();
workbasket.setId("0");
workbasket.setDescription("TestDescription");
workbasket.setName("Cool New WorkintheBasket");
workbasket.setOwner("Arthur Dent");
workbasket.setKey("myKey");
workbasket.setType(WorkbasketType.PERSONAL);
workbasket.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket);
doNothing().when(workbasketMapper).update(any());
workbasket.setDescription("42");
workbasketServiceImpl.updateWorkbasket(workbasket);
verify(workbasketMapper).update(any());
}
@SuppressWarnings("serial")
@Test
public void should_ReturnUpdatedWorkbasket_when_ExistingWorkbasketDistributionTargetIsChanged()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
doNothing().when(workbasketMapper).insert(any());
WorkbasketImpl workbasket = new WorkbasketImpl();
workbasket.setId("0");
WorkbasketImpl workbasket1 = new WorkbasketImpl();
workbasket1.setId("1");
workbasket1.setKey("myKey1");
workbasket1.setName("workbasket1");
workbasket1.setType(WorkbasketType.PERSONAL);
workbasket1.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket1);
when(workbasketMapper.findById("1")).thenReturn(workbasket1);
workbasket.setDistributionTargets(new ArrayList<Workbasket>() {
{
add(workbasket1);
}
});
workbasket.setKey("myKey0");
workbasket.setName("workbasket0");
workbasket.setType(WorkbasketType.PERSONAL);
workbasket.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket);
doNothing().when(workbasketMapper).update(any());
when(workbasketMapper.findById(any())).thenReturn(workbasket);
workbasket.getDistributionTargets().get(0).setDescription("Test123");
Workbasket result = workbasketServiceImpl.updateWorkbasket(workbasket);
verify(workbasketMapper).update(any());
Assert.assertEquals("Test123", result.getDistributionTargets().get(0).getDescription());
}
@Test
public void should_UpdateModifiedTimestamp_when_ExistingWorkbasketDistributionTargetIsChanged() throws Exception {
doNothing().when(workbasketMapper).insert(any());
WorkbasketImpl workbasket0 = new WorkbasketImpl();
workbasket0.setId("0");
workbasket0.setKey("myKey0");
workbasket0.setName("workbasket0");
workbasket0.setType(WorkbasketType.PERSONAL);
workbasket0.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket0);
when(workbasketMapper.findById("0")).thenReturn(workbasket0);
WorkbasketImpl workbasket1 = new WorkbasketImpl();
workbasket1.setKey("myKey1");
workbasket1.setName("workbasket1");
workbasket1.setType(WorkbasketType.PERSONAL);
workbasket1.setDomain("generali");
workbasket1.setId("1");
workbasketServiceImpl.createWorkbasket(workbasket1);
when(workbasketMapper.findById("1")).thenReturn(workbasket1);
WorkbasketImpl workbasket2 = new WorkbasketImpl();
workbasket2.setId("2");
workbasket2.setKey("myKey2");
workbasket2.setName("workbasket2");
workbasket2.setType(WorkbasketType.PERSONAL);
workbasket2.setDomain("generali");
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workbasketServiceImpl.createWorkbasket(workbasket2);
WorkbasketImpl workbasket3 = new WorkbasketImpl();
workbasket3.setId("3");
workbasket3.setKey("myKey3");
workbasket3.setName("workbasket3");
workbasket3.setType(WorkbasketType.PERSONAL);
workbasket3.setDomain("generali");
workbasketServiceImpl.createWorkbasket(workbasket3);
when(workbasketMapper.findById("3")).thenReturn(workbasket3);
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(SLEEP_TIME);
doNothing().when(workbasketMapper).update(any());
workbasketServiceImpl.updateWorkbasket(workbasket2);
when(workbasketMapper.findById("2")).thenReturn(workbasket2);
Workbasket foundBasket = workbasketServiceImpl.getWorkbasket(workbasket2.getId());
when(workbasketMapper.findById("1")).thenReturn(workbasket1);
when(workbasketMapper.findById("3")).thenReturn(workbasket1);
List<Workbasket> distributionTargets = foundBasket.getDistributionTargets();
Assert.assertEquals(1, distributionTargets.size());
Assert.assertEquals("3", distributionTargets.get(0).getId());
Assert.assertNotEquals(workbasketServiceImpl.getWorkbasket("2").getCreated(),
workbasketServiceImpl.getWorkbasket("2").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("1").getCreated(),
workbasketServiceImpl.getWorkbasket("1").getModified());
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("3").getCreated(),
workbasketServiceImpl.getWorkbasket("3").getModified());
}
@Test
public void should_ReturnWorkbasketAuthorization_when_NewWorkbasketAccessItemIsCreated()
throws NotAuthorizedException {
doNothing().when(workbasketAccessMapper).insert(any());
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketKey("1");
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertNotNull(accessItem.getId());
}
@Test
public void should_ReturnWorkbasketAuthorization_when_WorkbasketAccessItemIsUpdated()
throws NotAuthorizedException {
doNothing().when(workbasketAccessMapper).insert(any());
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketKey("1");
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertNotNull(accessItem.getId());
doNothing().when(workbasketAccessMapper).update(any());
accessItem.setAccessId("Zaphod Beeblebrox");
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
Assert.assertEquals("zaphod beeblebrox", accessItem.getAccessId());
} else {
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getAccessId());
try {
cutSpy.getWorkbasket(wbId);
} catch (NotAuthorizedException ex) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).findById(wbId);
verify(cutSpy, times(1)).checkAuthorization(wb.getKey(), authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw ex;
}
}
@Test(expected = WorkbasketNotFoundException.class)
public void testGetWorkbasketById_AuthenticatedWithoutResult()
throws NotAuthorizedException, WorkbasketNotFoundException {
String wbId = "ID-1";
doReturn(null).when(workbasketMapperMock).findById(wbId);
try {
cutSpy.getWorkbasket(wbId);
} catch (WorkbasketNotFoundException ex) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).findById(wbId);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw ex;
}
}
@Test
public void testGetWorkbasketById() throws NotAuthorizedException, WorkbasketNotFoundException {
String wbId = "ID-1";
Workbasket wb = createTestWorkbasket(wbId, "key-1");
WorkbasketAuthorization authorization = WorkbasketAuthorization.READ;
doReturn(wb).when(workbasketMapperMock).findById(wbId);
doNothing().when(cutSpy).checkAuthorization(wb.getKey(), authorization);
Workbasket actualWb = cutSpy.getWorkbasket(wbId);
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).findById(wbId);
verify(cutSpy, times(1)).checkAuthorization(wb.getKey(), authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb, equalTo(wb));
}
@Test(expected = NotAuthorizedException.class)
public void should_ThrowNotAuthorizedException_when_OperationIsNotAuthorized() throws NotAuthorizedException {
when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngine.getConfiguration().isSecurityEnabled()).thenReturn(true);
public void testGetWorkbasketByKey_NonAuthorizedUser()
throws WorkbasketNotFoundException, NotAuthorizedException {
String wbKey = "Key-1";
Workbasket wb = createTestWorkbasket("ID", wbKey);
WorkbasketAuthorization authorization = WorkbasketAuthorization.READ;
doReturn(wb).when(workbasketMapperMock).findByKey(wbKey);
doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wbKey, authorization);
workbasketServiceImpl.checkAuthorization("1", WorkbasketAuthorization.READ);
try {
cutSpy.getWorkbasketByKey(wbKey);
} catch (NotAuthorizedException ex) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).findByKey(wbKey);
verify(cutSpy, times(1)).checkAuthorization(wbKey, authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw ex;
}
}
@SuppressWarnings("serial")
@Test
public void should_Pass_when_OperationIsAuthorized() throws NotAuthorizedException {
when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngine.getConfiguration().isSecurityEnabled()).thenReturn(true);
@Test(expected = WorkbasketNotFoundException.class)
public void testGetWorkbasketByKey_AuthenticatedWithoutResult()
throws NotAuthorizedException, WorkbasketNotFoundException {
String wbKey = "Key-1";
doReturn(null).when(workbasketMapperMock).findByKey(wbKey);
when(workbasketAccessMapper.findByWorkbasketAndAccessIdAndAuthorizations(any(), any(), any()))
.thenReturn(new ArrayList<WorkbasketAccessItem>() {
{
add(new WorkbasketAccessItem());
}
});
workbasketServiceImpl.checkAuthorization("1", WorkbasketAuthorization.READ);
verify(workbasketAccessMapper, times(1)).findByWorkbasketAndAccessIdAndAuthorizations(any(), any(), any());
try {
cutSpy.getWorkbasketByKey(wbKey);
} catch (WorkbasketNotFoundException ex) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).findByKey(wbKey);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw ex;
}
}
@Test
public void should_Pass_when_SecurityIsDisabled() throws NotAuthorizedException {
when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngine.getConfiguration().isSecurityEnabled()).thenReturn(false);
public void testGetWorkbasketByKey() throws NotAuthorizedException, WorkbasketNotFoundException {
String wbKey = "Key-1";
Workbasket wb = createTestWorkbasket("ID-1", wbKey);
WorkbasketAuthorization authorization = WorkbasketAuthorization.READ;
doNothing().when(cutSpy).checkAuthorization(wbKey, authorization);
doReturn(wb).when(workbasketMapperMock).findByKey(wbKey);
workbasketServiceImpl.checkAuthorization("1", WorkbasketAuthorization.READ);
Workbasket actualWb = cutSpy.getWorkbasketByKey(wbKey);
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(cutSpy, times(1)).checkAuthorization(wbKey, authorization);
verify(workbasketMapperMock, times(1)).findByKey(wbKey);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb, equalTo(wb));
}
@Test
public void testCreateWorkbasket_InvalidWorkbasketCases()
throws WorkbasketNotFoundException, NotAuthorizedException {
WorkbasketImpl wb = new WorkbasketImpl();
int serviceCalls = 1;
// KEY NULL
try {
wb.setId(null);
wb.setKey(null);
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
// KEY EMPTY
serviceCalls++;
try {
wb.setKey("");
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
// NAME NULL
serviceCalls++;
try {
wb.setKey("KEY");
wb.setName(null);
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
// NAME EMPTY
serviceCalls++;
try {
wb.setName("");
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
// DOMAIN NULL
serviceCalls++;
try {
wb.setName("Name");
wb.setDomain(null);
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
// TYPE NULL
serviceCalls++;
try {
wb.setDomain("Domain");
wb.setType(null);
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(wb.getId(), not(equalTo(null)));
assertThat(wb.getCreated(), not(equalTo(null)));
assertThat(wb.getModified(), not(equalTo(null)));
}
}
@Test
public void testCreateWorkbasket_WithoutDistibutionTargets()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(null);
doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(workbasketMapperMock).findById(any());
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId());
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb.getId(), not(equalTo(null)));
assertThat(actualWb.getId(), startsWith("WBI"));
assertThat(actualWb.getCreated(), not(equalTo(null)));
assertThat(actualWb.getModified(), not(equalTo(null)));
}
@Test
public void testCreateWorkbasket_WithDistibutionTargets()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
final int distTargetAmount = 2;
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(cutSpy).getWorkbasket(any());
doReturn(expectedWb).when(workbasketMapperMock).findById(any());
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(cutSpy, times(distTargetAmount)).getWorkbasket(any());
verify(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any());
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId());
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb.getId(), not(equalTo(null)));
assertThat(actualWb.getId(), startsWith("WBI"));
assertThat(actualWb.getCreated(), not(equalTo(null)));
assertThat(actualWb.getModified(), not(equalTo(null)));
}
@Test(expected = WorkbasketNotFoundException.class)
public void testCreateWorkbasket_DistibutionTargetNotExisting()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
final int distTargetAmount = 5;
WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1");
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(cutSpy)
.getWorkbasket(expectedWb.getDistributionTargets().get(0).getId());
try {
cutSpy.createWorkbasket(expectedWb);
} catch (WorkbasketNotFoundException e) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(cutSpy, times(1)).getWorkbasket(any());
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw e;
}
}
// TODO Add stored-check. Not getWorkbasket() because permissions are not set with this action here.
@Ignore
@Test(expected = WorkbasketNotFoundException.class)
public void testCreateWorkbasket_NotCreated()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(null);
doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any());
try {
cutSpy.createWorkbasket(expectedWb);
} catch (Exception e) {
verify(taskanaEngineImplMock, times(1)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId());
verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw e;
}
}
private WorkbasketImpl createTestWorkbasket(String id, String key) {
WorkbasketImpl workbasket = new WorkbasketImpl();
workbasket.setId(id);
workbasket.setKey(key);
workbasket.setName("Workbasket " + id);
workbasket.setDescription("Description WB with Key " + key);
workbasket.setType(WorkbasketType.PERSONAL);
workbasket.setDomain("");
return workbasket;
}
private List<Workbasket> createTestDistributionTargets(int amount) {
List<Workbasket> distributionsTargets = new ArrayList<>();
amount = (amount < 0) ? 0 : amount;
for (int i = 0; i < amount; i++) {
distributionsTargets.add(createTestWorkbasket("WB-ID-" + i, "WB-KEY-" + i));
}
return distributionsTargets;
}
}

View File

@ -30,6 +30,7 @@ import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.ClassificationImpl;
import pro.taskana.impl.TaskanaEngineImpl;
@ -152,7 +153,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testFindAllClassifications()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification0 = this.createDummyClassificationWithUniqueKey();
classificationService.createClassification(classification0);
Classification classification1 = this.createDummyClassificationWithUniqueKey();
@ -178,7 +180,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testInsertAndClassificationMapper()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification = this.createDummyClassificationWithUniqueKey();
Classification actualClassification = classificationService.createClassification(classification);
Date today = Date.valueOf(LocalDate.now());
@ -194,7 +197,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testUpdateAndClassificationMapper()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification = this.createDummyClassificationWithUniqueKey();
classificationService.createClassification(classification);
System.out.println(classification.getId());
@ -224,7 +228,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testFindWithClassificationMapperDomainAndCategory()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification1 = this.createDummyClassificationWithUniqueKey();
classification1.setDomain("domain1");
classification1.setCategory("category1");
@ -249,7 +254,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testFindWithClassificationMapperCustomAndCategory()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification1 = this.createDummyClassificationWithUniqueKey();
classification1.setDescription("DESC1");
classification1.setCategory("category1");
@ -283,7 +289,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testFindWithClassificationMapperPriorityTypeAndParent()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
NumberFormatException, InvalidArgumentException {
Classification classification = this.createDummyClassificationWithUniqueKey();
classification.setPriority(Integer.decode("5"));
classification.setType("type1");
@ -320,7 +327,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testFindWithClassificationMapperServiceLevelNameAndDescription()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
int all = 0;
Classification classification = this.createDummyClassificationWithUniqueKey();
classification.setServiceLevel("P1D");
@ -358,7 +366,8 @@ public class ClassificationServiceImplIntAutoCommitTest {
@Test
public void testDefaultSettingsWithClassificationMapper()
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException,
InvalidArgumentException {
Classification classification = this.createDummyClassificationWithUniqueKey();
Classification classification1 = this.createDummyClassificationWithUniqueKey();
classificationService.createClassification(classification);

View File

@ -31,6 +31,7 @@ import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.ClassificationImpl;
import pro.taskana.impl.TaskanaEngineImpl;
@ -86,9 +87,11 @@ public class ClassificationServiceImplIntExplicitTest {
// empty classification (root)
expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey();
expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
expectedClassification = (ClassificationImpl) classificationService
.createClassification(expectedClassification);
connection.commit();
actualClassification = classificationService.getClassification(expectedClassification.getKey(), expectedClassification.getDomain());
actualClassification = classificationService.getClassification(expectedClassification.getKey(),
expectedClassification.getDomain());
assertThat(actualClassification, not(equalTo(null)));
assertThat(actualClassification.getCreated(), not(equalTo(null)));
assertThat(actualClassification.getId(), not(equalTo(null)));
@ -98,9 +101,11 @@ public class ClassificationServiceImplIntExplicitTest {
expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey();
expectedClassification.setDomain(domain);
expectedClassification.setKey(key);
expectedClassification = (ClassificationImpl) classificationService.createClassification(expectedClassification);
expectedClassification = (ClassificationImpl) classificationService
.createClassification(expectedClassification);
connection.commit();
actualClassification = classificationService.getClassification(expectedClassification.getKey(), expectedClassification.getDomain());
actualClassification = classificationService.getClassification(expectedClassification.getKey(),
expectedClassification.getDomain());
actualClassification2 = classificationService.getClassification(expectedClassification.getKey(), "");
assertThat(actualClassification, not(equalTo(null)));
assertThat(actualClassification.getCreated(), not(equalTo(null)));
@ -124,7 +129,8 @@ public class ClassificationServiceImplIntExplicitTest {
classificationService.createClassification(expectedClassification);
connection.commit();
fail("Should have thrown 'ClassificationAlreadyExistException' here.");
} catch (ClassificationAlreadyExistException e) { }
} catch (ClassificationAlreadyExistException e) {
}
// new classification but root existing
expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey();
@ -151,12 +157,14 @@ public class ClassificationServiceImplIntExplicitTest {
classificationService.createClassification(expectedClassification);
connection.commit();
fail("Should have thrown IllegalArgumentException, because ServiceLevel is invalid.");
} catch (IllegalArgumentException e) { }
} catch (IllegalArgumentException e) {
}
}
@Test
public void testFindAllClassifications()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification0 = this.createNewClassificationWithUniqueKey();
@ -188,7 +196,8 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testInsertAndClassificationMapper()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey();
@ -205,7 +214,7 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testUpdateAndClassificationMapper() throws NotAuthorizedException, SQLException,
ClassificationAlreadyExistException, ClassificationNotFoundException {
ClassificationAlreadyExistException, ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey();
@ -236,7 +245,8 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testFindWithClassificationMapperDomainAndCategory()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification1 = this.createNewClassificationWithUniqueKey();
@ -264,7 +274,8 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testFindWithClassificationMapperCustomAndCategory()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification1 = this.createNewClassificationWithUniqueKey();
@ -301,7 +312,8 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testFindWithClassificationMapperPriorityTypeAndParent()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey();
@ -341,7 +353,8 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testFindWithClassificationMapperServiceLevelNameAndDescription()
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException {
throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException,
ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
int all = 0;
@ -382,7 +395,7 @@ public class ClassificationServiceImplIntExplicitTest {
@Test
public void testDefaultSettingsWithClassificationMapper() throws NotAuthorizedException, SQLException,
ClassificationAlreadyExistException, ClassificationNotFoundException {
ClassificationAlreadyExistException, ClassificationNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey();
@ -392,7 +405,9 @@ public class ClassificationServiceImplIntExplicitTest {
classification1.setParentClassificationKey(classification.getKey());
classificationService.updateClassification(classification1);
List<Classification> list = classificationService.createClassificationQuery().parentClassificationKey("").list();
List<Classification> list = classificationService.createClassificationQuery()
.parentClassificationKey("")
.list();
Assert.assertEquals(2, list.size());
list = classificationService.createClassificationQuery().validUntil(Date.valueOf("9999-12-31")).list();
Assert.assertEquals(2, list.size());

View File

@ -286,13 +286,13 @@ public class TaskServiceImplIntAutocommitTest {
@Test(expected = WorkbasketNotFoundException.class)
public void shouldThrowWorkbasketNotFoundExceptionByNullParameter()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
taskServiceImpl.getTaskSummariesByWorkbasketKey(null);
}
@Test(expected = WorkbasketNotFoundException.class)
public void shouldThrowWorkbasketNotFoundExceptionByInvalidWorkbasketParameter()
throws WorkbasketNotFoundException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setKey("key");
wb.setName("wb");

View File

@ -73,17 +73,11 @@ import pro.taskana.security.WithAccessId;
public class TaskServiceImplIntExplicitTest {
private DataSource dataSource;
private TaskServiceImpl taskServiceImpl;
private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private ClassificationService classificationService;
private WorkbasketService workbasketService;
@BeforeClass
@ -163,6 +157,7 @@ public class TaskServiceImplIntExplicitTest {
accessItem.setWorkbasketKey("wb");
accessItem.setAccessId("Elena");
accessItem.setPermAppend(true);
accessItem.setPermRead(true);
accessItem.setPermOpen(true);
workbasketService.createWorkbasketAuthorization(accessItem);
@ -245,6 +240,7 @@ public class TaskServiceImplIntExplicitTest {
accessItem.setWorkbasketKey("wb");
accessItem.setAccessId("Elena");
accessItem.setPermAppend(true);
accessItem.setPermRead(true);
accessItem.setPermOpen(true);
workbasketService.createWorkbasketAuthorization(accessItem);
@ -334,7 +330,7 @@ public class TaskServiceImplIntExplicitTest {
taskServiceImpl.createTask(task);
}
@WithAccessId(userName = "Elena", groupNames = {"DummyGroup"})
@WithAccessId(userName = "Elena", groupNames = { "DummyGroup" })
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
@ -353,11 +349,11 @@ public class TaskServiceImplIntExplicitTest {
workbasket.setKey("k1");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setDomain("novatec");
workbasketService.createWorkbasket(workbasket);
workbasket = (WorkbasketImpl) workbasketService.createWorkbasket(workbasket);
Task task = taskServiceImpl.newTask();
task.setName("Unit Test Task");
task.setWorkbasketKey(workbasket.getKey());
task.setWorkbasketKey("k1");
task.setClassification(classification);
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = taskServiceImpl.createTask(task);
@ -384,7 +380,7 @@ public class TaskServiceImplIntExplicitTest {
.descriptionLike("test")
.priority(1, 2, 2)
.state(TaskState.CLAIMED)
.workbasketKeyIn("k1", "k2")
.workbasketKeyIn("k1")
.owner("test", "test2", "bla")
.customFields("test")
.classification(classificationQuery)
@ -427,7 +423,7 @@ public class TaskServiceImplIntExplicitTest {
sourceWB = workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), false, false, false, false);
createWorkbasketWithSecurity(sourceWB, sourceWB.getOwner(), false, false, true, true);
createWorkbasketWithSecurity(sourceWB, sourceWB.getOwner(), true, true, true, true);
// Destination Workbasket
wb = (WorkbasketImpl) workbasketService.newWorkbasket();
@ -438,7 +434,7 @@ public class TaskServiceImplIntExplicitTest {
wb.setType(WorkbasketType.TOPIC);
wb.setKey("wb2Key");
destinationWB = workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(destinationWB, destinationWB.getOwner(), false, false, true, true);
createWorkbasketWithSecurity(destinationWB, destinationWB.getOwner(), false, true, true, true);
// Classification required for Task
classification = (ClassificationImpl) classificationService.newClassification();
@ -576,7 +572,7 @@ public class TaskServiceImplIntExplicitTest {
}
private Task generateDummyTask() throws ClassificationAlreadyExistException, ClassificationNotFoundException,
WorkbasketNotFoundException, InvalidWorkbasketException {
WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket();
workbasket.setKey("wb");
workbasket.setName("wb");
@ -601,6 +597,7 @@ public class TaskServiceImplIntExplicitTest {
accessItem.setWorkbasketKey("k1");
accessItem.setAccessId("Elena");
accessItem.setPermAppend(true);
accessItem.setPermRead(true);
accessItem.setPermOpen(true);
workbasketService.createWorkbasketAuthorization(accessItem);
@ -608,6 +605,7 @@ public class TaskServiceImplIntExplicitTest {
accessItem2.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem2.setWorkbasketKey("k2");
accessItem2.setAccessId("DummyGroup");
accessItem.setPermRead(true);
accessItem2.setPermOpen(true);
workbasketService.createWorkbasketAuthorization(accessItem2);
}

View File

@ -3,16 +3,12 @@ package pro.taskana.impl.integration;
import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException;
import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
@ -23,6 +19,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
@ -30,11 +27,9 @@ import pro.taskana.Workbasket;
import pro.taskana.WorkbasketQuery;
import pro.taskana.WorkbasketService;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.TaskanaEngineProxyForTest;
@ -46,40 +41,30 @@ import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.WorkbasketType;
import pro.taskana.model.mappings.WorkbasketMapper;
import pro.taskana.security.GroupPrincipal;
import pro.taskana.security.UserPrincipal;
import pro.taskana.security.CurrentUserContext;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
/**
* Integration Test for workbasketServiceImpl with connection management mode AUTOCOMMIT.
*
* @author EH
*/
@RunWith(JAASRunner.class)
public class WorkbasketServiceImplIntAutocommitTest {
private static final int SLEEP_TIME = 100;
private static final int THREE = 3;
private static final long ONE_DAY = 24 * 3600 * 1000;
private static final long TEN_DAYS = 10 * ONE_DAY;
private static final long FIFTEEN_DAYS = 15 * ONE_DAY;
private static final long TWENTY_DAYS = 2 * TEN_DAYS;
static int counter = 0;
private DataSource dataSource;
private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketService workBasketService;
private Date workBasketsCreated;
@BeforeClass
@ -147,118 +132,82 @@ public class WorkbasketServiceImplIntAutocommitTest {
Assert.assertEquals(before + THREE, workBasketService.getWorkbaskets().size());
}
@WithAccessId(userName = "Elena")
@Test
public void testSelectWorkbasket()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workBasketService.createWorkbasket(workbasket0);
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
workBasketService.createWorkbasket(workbasket2);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId());
String id = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket = createTestWorkbasket(id, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
workbasket = workBasketService.createWorkbasket(workbasket);
createWorkbasketWithSecurity(workbasket, CurrentUserContext.getUserid(), true, true, false, false);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id);
Assert.assertEquals(id, foundWorkbasket.getId());
}
@Test(expected = WorkbasketNotFoundException.class)
public void testGetWorkbasketFail() throws WorkbasketNotFoundException, InvalidWorkbasketException {
public void testGetWorkbasketFail()
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
workBasketService.getWorkbasket("fail");
}
@WithAccessId(userName = "Elena")
@Test
public void testSelectWorkbasketWithDistribution()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workBasketService.createWorkbasket(workbasket0);
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
workbasket2.setDistributionTargets(new ArrayList<>());
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workBasketService.createWorkbasket(workbasket2);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId());
String id = IdGenerator.generateWithPrefix("TWB");
Workbasket wbDist1 = createTestWorkbasket(id, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
wbDist1 = workBasketService.createWorkbasket(wbDist1);
createWorkbasketWithSecurity(wbDist1, CurrentUserContext.getUserid(), true, true, false, false);
id = IdGenerator.generateWithPrefix("TWB");
Workbasket wbDist2 = createTestWorkbasket(id, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
wbDist2 = workBasketService.createWorkbasket(wbDist2);
createWorkbasketWithSecurity(wbDist2, "Elena", true, true, false, false);
id = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket = createTestWorkbasket(id, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
workbasket.setDistributionTargets(new ArrayList<>());
workbasket.getDistributionTargets().add(wbDist1);
workbasket.getDistributionTargets().add(wbDist2);
workbasket = workBasketService.createWorkbasket(workbasket);
createWorkbasketWithSecurity(workbasket, "Elena", true, true, false, false);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(workbasket.getId());
Assert.assertEquals(id, foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
}
@WithAccessId(userName = "Elena")
@Test
public void testUpdateWorkbasket() throws Exception {
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workBasketService.createWorkbasket(workbasket0);
Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
workbasket0 = workBasketService.createWorkbasket(workbasket0);
createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
workbasket1 = workBasketService.createWorkbasket(workbasket1);
createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
workbasket2.setDistributionTargets(new ArrayList<>());
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workBasketService.createWorkbasket(workbasket2);
workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
WorkbasketImpl workbasket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id3 = IdGenerator.generateWithPrefix("TWB");
workbasket3.setId(id3);
workbasket3.setKey("key3");
workbasket3.setName("hm ... irgend ein basket");
workbasket3.setType(WorkbasketType.GROUP);
workbasket3.setDomain("novatec");
workBasketService.createWorkbasket(workbasket3);
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
WorkbasketType.GROUP);
workbasket3 = workBasketService.createWorkbasket(workbasket3);
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(SLEEP_TIME);
workBasketService.updateWorkbasket(workbasket2);
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
@ -308,6 +257,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
}
}
@WithAccessId(userName = "Bernd", groupNames = { "group1", "group2", "group3", "group4" })
@Test
public void testWorkbasketQuery()
throws NotAuthorizedException, InvalidArgumentException, InvalidWorkbasketException,
@ -323,27 +273,30 @@ public class WorkbasketServiceImplIntAutocommitTest {
Date thirtyDaysAgo = new Date(workBasketsCreated.getTime() - THREE * TEN_DAYS);
WorkbasketQuery query1 = workBasketService.createWorkbasketQuery()
.access(WorkbasketAuthorization.OPEN, "Bernd")
.nameIn("Basket1");
.accessIdsHavePersmission(WorkbasketAuthorization.OPEN, "Bernd")
.nameIn("Basket4");
List<Workbasket> result1 = query1.list();
Assert.assertEquals(1, result1.size());
Assert.assertEquals(THREE, result1.get(0).getDistributionTargets().size());
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().access(WorkbasketAuthorization.OPEN, "Bernd",
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
WorkbasketAuthorization.OPEN, "Bernd",
"Konstantin");
List<Workbasket> result2 = query2.list();
Assert.assertEquals(1, result2.size());
Assert.assertEquals(2, result2.size());
WorkbasketQuery query3 = workBasketService.createWorkbasketQuery().access(WorkbasketAuthorization.CUSTOM_5,
WorkbasketQuery query3 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
WorkbasketAuthorization.CUSTOM_5,
"Bernd", "Konstantin");
List<Workbasket> result3 = query3.list();
Assert.assertEquals(0, result3.size());
WorkbasketQuery query4 = workBasketService.createWorkbasketQuery().access(WorkbasketAuthorization.CUSTOM_1,
WorkbasketQuery query4 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
WorkbasketAuthorization.CUSTOM_1,
"Bernd");
List<Workbasket> result4 = query4.list();
Assert.assertEquals(0, result4.size());
Assert.assertEquals(1, result4.size());
WorkbasketQuery query0 = workBasketService.createWorkbasketQuery()
.createdBefore(tomorrow)
@ -363,7 +316,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
assertTrue(result5.size() == 2);
for (Workbasket workbasket : result5) {
String name = workbasket.getName();
assertTrue("Basket2".equals(name) || "Basket3".equals(name));
assertTrue("Basket1".equals(name) || "Basket2".equals(name));
}
WorkbasketQuery query6 = workBasketService.createWorkbasketQuery()
@ -371,7 +324,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
.domainIn("novatec", "consulting");
List<Workbasket> result6 = query6.list();
assertTrue(result6.size() == 1);
assertTrue("Basket2".equals(result6.get(0).getName()));
assertTrue("Basket1".equals(result6.get(0).getName()));
WorkbasketQuery query7 = workBasketService.createWorkbasketQuery()
.typeIn(WorkbasketType.GROUP, WorkbasketType.CLEARANCE);
@ -379,143 +332,91 @@ public class WorkbasketServiceImplIntAutocommitTest {
assertTrue(result7.size() == 2);
for (Workbasket workbasket : result7) {
String name = workbasket.getName();
assertTrue("Basket2".equals(name) || "Basket3".equals(name));
assertTrue("Basket1".equals(name) || "Basket2".equals(name));
}
}
@Test
public void testGetWorkbasketsForCurrentUserAndPermission()
throws NotAuthorizedException, InvalidWorkbasketException, WorkbasketNotFoundException {
generateSampleDataForQuery();
String userName = "Bernd";
String[] groupNames = {"group2", "group3"};
List<WorkbasketAuthorization> authorizations = new ArrayList<WorkbasketAuthorization>();
authorizations.add(WorkbasketAuthorization.OPEN);
Assert.assertTrue(2 == getWorkbasketsForPrincipalesAndPermissions(userName, groupNames, authorizations));
authorizations.add(WorkbasketAuthorization.CUSTOM_4);
Assert.assertTrue(0 == getWorkbasketsForPrincipalesAndPermissions(userName, groupNames, authorizations));
userName = "Holger";
authorizations = new ArrayList<WorkbasketAuthorization>();
authorizations.add(WorkbasketAuthorization.APPEND);
Assert.assertTrue(1 == getWorkbasketsForPrincipalesAndPermissions(userName, groupNames, authorizations));
}
private int getWorkbasketsForPrincipalesAndPermissions(String userName, String[] groupNames,
List<WorkbasketAuthorization> authorizations) throws NotAuthorizedException {
Subject subject = new Subject();
List<Principal> principalList = new ArrayList<>();
principalList.add(new UserPrincipal(userName));
for (int i = 0; i < groupNames.length; i++) {
principalList.add(new GroupPrincipal(groupNames[i]));
}
subject.getPrincipals().addAll(principalList);
int result = -1;
try {
result = Subject.doAs(subject, new PrivilegedExceptionAction<Integer>() {
@Override
public Integer run() throws TaskNotFoundException, FileNotFoundException, NotAuthorizedException,
SQLException, WorkbasketNotFoundException, ClassificationNotFoundException {
List<Workbasket> wbsResult = workBasketService.getWorkbaskets(authorizations);
return wbsResult.size();
}
});
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause != null) {
Assert.assertTrue(cause instanceof NotAuthorizedException);
throw (NotAuthorizedException) cause;
}
}
return result;
}
public void generateSampleDataForQuery() throws InvalidWorkbasketException, WorkbasketNotFoundException {
private void generateSampleDataForQuery()
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException {
workBasketsCreated = new Date();
WorkbasketImpl basket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
basket1.setId("1");
basket1.setKey("k1");
basket1.setName("Basket1");
basket1.setOwner("Eberhardt");
basket1.setType(WorkbasketType.GROUP);
basket1.setDomain("novatec");
basket1 = (WorkbasketImpl) workBasketService.createWorkbasket(basket1);
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketKey(basket1.getKey());
accessItem.setAccessId("Bernd");
accessItem.setPermTransfer(true);
accessItem.setPermCustom1(true);
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
workBasketService.createWorkbasketAuthorization(accessItem);
WorkbasketImpl basket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
basket2.setId("2");
basket2.setKey("k2");
basket2.setName("Basket2");
basket2.setOwner("Eberhardt");
basket2.setType(WorkbasketType.GROUP);
basket2.setDomain("novatec");
basket2.setOwner("Konstantin");
basket2.setType(WorkbasketType.CLEARANCE);
basket2.setDomain("consulting");
basket2 = (WorkbasketImpl) workBasketService.createWorkbasket(basket2);
WorkbasketAccessItem accessItem2 = new WorkbasketAccessItem();
accessItem2.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem2.setWorkbasketKey(basket2.getKey());
accessItem2.setAccessId("group2");
accessItem2.setPermTransfer(true);
accessItem2.setPermRead(true);
accessItem2.setPermCustom4(true);
accessItem2.setPermCustom1(true);
accessItem2.setPermOpen(true);
workBasketService.createWorkbasketAuthorization(accessItem2);
WorkbasketImpl basket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
basket3.setId("3");
basket3.setKey("k3");
basket3.setName("Basket3");
basket3.setOwner("Konstantin");
basket3.setType(WorkbasketType.CLEARANCE);
basket3.setDomain("consulting");
basket3.setOwner("Holger");
basket3.setType(WorkbasketType.TOPIC);
basket3.setDomain("develop");
basket3 = (WorkbasketImpl) workBasketService.createWorkbasket(basket3);
WorkbasketAccessItem accessItem3 = new WorkbasketAccessItem();
accessItem3.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem3.setWorkbasketKey(basket3.getKey());
accessItem3.setAccessId("group3");
accessItem3.setPermOpen(true);
accessItem3.setPermRead(true);
accessItem3.setPermAppend(true);
workBasketService.createWorkbasketAuthorization(accessItem3);
WorkbasketImpl basket4 = (WorkbasketImpl) workBasketService.newWorkbasket();
basket4.setId("4");
basket4.setKey("k4");
basket4.setName("Basket4");
basket4.setOwner("Holger");
basket4.setType(WorkbasketType.TOPIC);
basket4.setDomain("develop");
basket4 = (WorkbasketImpl) workBasketService.createWorkbasket(basket4);
WorkbasketImpl basket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
basket1.setId("1");
basket1.setKey("k1");
basket1.setName("Basket1");
basket1.setOwner("Holger");
basket1.setType(WorkbasketType.PERSONAL);
basket1.setDomain("");
basket4.setType(WorkbasketType.PERSONAL);
basket4.setDomain("");
List<Workbasket> distTargets = new ArrayList<Workbasket>();
distTargets.add(basket1);
distTargets.add(basket2);
distTargets.add(basket3);
distTargets.add(basket4);
basket1.setDistributionTargets(distTargets);
basket1 = (WorkbasketImpl) workBasketService.createWorkbasket(basket1);
updateModifiedTimestamps(basket2, basket3, basket4, basket1);
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketKey("k1");
accessItem.setAccessId("Bernd");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
workBasketService.createWorkbasketAuthorization(accessItem);
WorkbasketAccessItem accessItem2 = new WorkbasketAccessItem();
accessItem2.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem2.setWorkbasketKey("k2");
accessItem2.setAccessId("Eberhardt");
accessItem2.setPermTransfer(true);
accessItem2.setPermCustom1(true);
workBasketService.createWorkbasketAuthorization(accessItem2);
WorkbasketAccessItem accessItem3 = new WorkbasketAccessItem();
accessItem3.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem3.setWorkbasketKey("k3");
accessItem3.setAccessId("group2");
accessItem3.setPermCustom4(true);
accessItem3.setPermCustom1(true);
workBasketService.createWorkbasketAuthorization(accessItem3);
basket4.setDistributionTargets(distTargets);
basket4 = (WorkbasketImpl) workBasketService.createWorkbasket(basket4);
WorkbasketAccessItem accessItem4 = new WorkbasketAccessItem();
accessItem4.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem4.setWorkbasketKey("k4");
accessItem4.setAccessId("group3");
accessItem4.setWorkbasketKey(basket4.getKey());
accessItem4.setAccessId("Bernd");
accessItem4.setPermOpen(true);
accessItem4.setPermRead(true);
accessItem4.setPermAppend(true);
workBasketService.createWorkbasketAuthorization(accessItem4);
updateModifiedTimestamps(basket1, basket2, basket3, basket4);
}
private void updateModifiedTimestamps(Workbasket basket2, Workbasket basket3, Workbasket basket4,
@ -543,6 +444,30 @@ public class WorkbasketServiceImplIntAutocommitTest {
engineProxy.returnConnection();
}
private void createWorkbasketWithSecurity(Workbasket wb, String accessId, boolean permOpen,
boolean permRead, boolean permAppend, boolean permTransfer) {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketKey(wb.getKey());
accessItem.setAccessId(accessId);
accessItem.setPermOpen(permOpen);
accessItem.setPermRead(permRead);
accessItem.setPermAppend(permAppend);
accessItem.setPermTransfer(permTransfer);
workBasketService.createWorkbasketAuthorization(accessItem);
}
private Workbasket createTestWorkbasket(String id, String key, String domain, String name, WorkbasketType type) {
WorkbasketImpl wb = (WorkbasketImpl) workBasketService.newWorkbasket();
wb.setId(id);
wb.setKey(key);
wb.setDomain(domain);
wb.setName(name);
wb.setDescription("Description of a Workbasket...");
wb.setType(type);
return wb;
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);

View File

@ -16,6 +16,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
@ -32,28 +33,24 @@ import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketType;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
/**
* Integration Test for workbasketServiceImpl with connection mode EXPLICIT.
*
* @author bbr
*/
@RunWith(JAASRunner.class)
public class WorkbasketServiceImplIntExplicitTest {
private static final int SLEEP_TIME = 100;
private static final int THREE = 3;
static int counter = 0;
private DataSource dataSource;
private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketService workBasketService;
@BeforeClass
@ -129,141 +126,113 @@ public class WorkbasketServiceImplIntExplicitTest {
taskanaEngineImpl.closeConnection();
}
@WithAccessId(userName = "Elena")
@Test
public void testSelectWorkbasket()
throws WorkbasketNotFoundException, NotAuthorizedException, SQLException, InvalidWorkbasketException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
WorkbasketImpl workbasket = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workbasket0 = (WorkbasketImpl) workBasketService.createWorkbasket(workbasket0);
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workbasket1 = (WorkbasketImpl) workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
workbasket2 = (WorkbasketImpl) workBasketService.createWorkbasket(workbasket2);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId());
workbasket.setId(id0);
workbasket.setKey("key0");
workbasket.setName("Superbasket");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setDomain("novatec");
workbasket = (WorkbasketImpl) workBasketService.createWorkbasket(workbasket);
createWorkbasketWithSecurity(workbasket, "Elena", true, true, true, true);
connection.commit();
workbasket = (WorkbasketImpl) workBasketService.getWorkbasket(workbasket.getId());
connection.commit();
taskanaEngineImpl.closeConnection();
}
@Test(expected = WorkbasketNotFoundException.class)
public void testGetWorkbasketFail() throws WorkbasketNotFoundException, SQLException, InvalidWorkbasketException {
@WithAccessId(userName = "Elena")
@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketFail()
throws WorkbasketNotFoundException, SQLException, InvalidWorkbasketException, NotAuthorizedException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
workBasketService.getWorkbasket("fail");
Workbasket wb = createTestWorkbasket("ID-1", "KEY-1", "DOMAIN", "Name-1", WorkbasketType.PERSONAL);
wb = workBasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, "Elena", false, false, false, false);
workBasketService.getWorkbasket(wb.getId());
connection.commit();
taskanaEngineImpl.closeConnection();
}
@WithAccessId(userName = "Elena")
@Test
public void testSelectWorkbasketWithDistribution()
throws WorkbasketNotFoundException, NotAuthorizedException, SQLException, InvalidWorkbasketException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workbasket0 = (WorkbasketImpl) workBasketService.createWorkbasket(workbasket0);
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
workbasket0 = workBasketService.createWorkbasket(workbasket0);
createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
workbasket1.setDomain("D2");
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
workbasket1 = workBasketService.createWorkbasket(workbasket1);
createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
workbasket2.setDistributionTargets(new ArrayList<>());
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workBasketService.createWorkbasket(workbasket2);
workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
connection.commit();
}
@WithAccessId(userName = "Elena")
@Test
public void testUpdateWorkbasket() throws Exception {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
WorkbasketImpl workbasket0 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id0 = IdGenerator.generateWithPrefix("TWB");
workbasket0.setId(id0);
workbasket0.setKey("key0");
workbasket0.setName("Superbasket");
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
workBasketService.createWorkbasket(workbasket0);
Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
workbasket0 = workBasketService.createWorkbasket(workbasket0);
createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
WorkbasketImpl workbasket1 = (WorkbasketImpl) workBasketService.newWorkbasket();
workbasket0.setType(WorkbasketType.GROUP);
workbasket0.setDomain("novatec");
String id1 = IdGenerator.generateWithPrefix("TWB");
workbasket1.setId(id1);
workbasket1.setKey("key1");
workbasket1.setName("Megabasket");
workbasket1.setType(WorkbasketType.GROUP);
workbasket1.setDomain("novatec");
workBasketService.createWorkbasket(workbasket1);
WorkbasketImpl workbasket2 = (WorkbasketImpl) workBasketService.newWorkbasket();
Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
workbasket1 = workBasketService.createWorkbasket(workbasket1);
createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
String id2 = IdGenerator.generateWithPrefix("TWB");
workbasket2.setId(id2);
workbasket2.setKey("key2");
workbasket2.setName("Hyperbasket");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
workbasket2.setDistributionTargets(new ArrayList<>());
workbasket2.setType(WorkbasketType.GROUP);
workbasket2.setDomain("novatec");
workbasket2.getDistributionTargets().add(workbasket0);
workbasket2.getDistributionTargets().add(workbasket1);
workBasketService.createWorkbasket(workbasket2);
workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
WorkbasketImpl workbasket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
String id3 = IdGenerator.generateWithPrefix("TWB");
workbasket3.setId(id3);
workbasket3.setKey("key3");
workbasket3.setName("hm ... irgend ein basket");
workbasket3.setType(WorkbasketType.GROUP);
workbasket3.setDomain("novatec");
workBasketService.createWorkbasket(workbasket3);
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
WorkbasketType.GROUP);
workbasket3.setDistributionTargets(new ArrayList<>());
workbasket3.getDistributionTargets().add(workbasket0);
workbasket3.getDistributionTargets().add(workbasket1);
workbasket3 = workBasketService.createWorkbasket(workbasket3);
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
workbasket2.getDistributionTargets().clear();
workbasket2.getDistributionTargets().add(workbasket3);
Thread.sleep(SLEEP_TIME);
workBasketService.updateWorkbasket(workbasket2);
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
@ -317,6 +286,30 @@ public class WorkbasketServiceImplIntExplicitTest {
connection.commit();
}
private void createWorkbasketWithSecurity(Workbasket wb, String accessId, boolean permOpen,
boolean permRead, boolean permAppend, boolean permTransfer) {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketKey(wb.getKey());
accessItem.setAccessId(accessId);
accessItem.setPermOpen(permOpen);
accessItem.setPermRead(permRead);
accessItem.setPermAppend(permAppend);
accessItem.setPermTransfer(permTransfer);
workBasketService.createWorkbasketAuthorization(accessItem);
}
private Workbasket createTestWorkbasket(String id, String key, String domain, String name, WorkbasketType type) {
WorkbasketImpl wb = (WorkbasketImpl) workBasketService.newWorkbasket();
wb.setId(id);
wb.setKey(key);
wb.setDomain(domain);
wb.setName(name);
wb.setDescription("Description of a Workbasket...");
wb.setType(type);
return wb;
}
@After
public void cleanUp() {
taskanaEngineImpl.setConnection(null);

View File

@ -1,9 +1,9 @@
DROP TABLE TASKANA_SCHEMA_VERSION;
DROP TABLE TASK;
DROP TABLE WORKBASKET;
DROP TABLE DISTRIBUTION_TARGETS;
DROP TABLE CLASSIFICATION;
DROP TABLE WORKBASKET_ACCESS_LIST;
DROP TABLE OBJECT_REFERENCE;
DROP TABLE ATTACHMENT;
DROP TABLE IF EXISTS TASKANA_SCHEMA_VERSION;
DROP TABLE IF EXISTS TASK;
DROP TABLE IF EXISTS WORKBASKET;
DROP TABLE IF EXISTS DISTRIBUTION_TARGETS;
DROP TABLE IF EXISTS CLASSIFICATION;
DROP TABLE IF EXISTS WORKBASKET_ACCESS_LIST;
DROP TABLE IF EXISTS OBJECT_REFERENCE;
DROP TABLE IF EXISTS ATTACHMENT;
COMMIT;

View File

@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
import pro.taskana.Task;
import pro.taskana.TaskService;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException;
@ -31,7 +32,7 @@ import pro.taskana.model.TaskSummary;
import pro.taskana.rest.query.TaskFilter;
@RestController
@RequestMapping(path = "/v1/tasks", produces = {MediaType.APPLICATION_JSON_VALUE})
@RequestMapping(path = "/v1/tasks", produces = { MediaType.APPLICATION_JSON_VALUE })
public class TaskController {
private static final Logger logger = LoggerFactory.getLogger(TaskController.class);
@ -44,7 +45,7 @@ public class TaskController {
@RequestMapping
public ResponseEntity<List<Task>> getTasks(@RequestParam MultiValueMap<String, String> params)
throws LoginException {
throws LoginException, InvalidArgumentException {
try {
if (params.keySet().size() == 0) {
// get all

View File

@ -26,19 +26,20 @@ import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization;
@RestController
@RequestMapping(path = "/v1/workbaskets", produces = {MediaType.APPLICATION_JSON_VALUE})
@RequestMapping(path = "/v1/workbaskets", produces = { MediaType.APPLICATION_JSON_VALUE })
public class WorkbasketController {
@Autowired
private WorkbasketService workbasketService;
@GetMapping
public List<Workbasket> getWorkbaskets(@RequestParam MultiValueMap<String, String> params) {
public ResponseEntity<List<Workbasket>> getWorkbaskets(@RequestParam MultiValueMap<String, String> params) {
List<Workbasket> workbaskets = new ArrayList<>();
if (params.containsKey("requiredPermission")) {
List<WorkbasketAuthorization> authorizations = new ArrayList<>();
params.get("requiredPermission").stream().forEach(item -> {
for (String authorization : Arrays.asList(item.split(","))) {
switch (authorization) {
switch (authorization.trim()) {
case "READ":
authorizations.add(WorkbasketAuthorization.READ);
break;
@ -54,13 +55,38 @@ public class WorkbasketController {
case "DISTRIBUTE":
authorizations.add(WorkbasketAuthorization.DISTRIBUTE);
break;
case "CUSTOM_1":
authorizations.add(WorkbasketAuthorization.CUSTOM_1);
break;
case "CUSTOM_2":
authorizations.add(WorkbasketAuthorization.CUSTOM_2);
break;
case "CUSTOM_3":
authorizations.add(WorkbasketAuthorization.CUSTOM_3);
break;
case "CUSTOM_4":
authorizations.add(WorkbasketAuthorization.CUSTOM_4);
break;
case "CUSTOM_5":
authorizations.add(WorkbasketAuthorization.CUSTOM_5);
break;
case "CUSTOM_6":
authorizations.add(WorkbasketAuthorization.CUSTOM_6);
break;
case "CUSTOM_7":
authorizations.add(WorkbasketAuthorization.CUSTOM_7);
break;
case "CUSTOM_8":
authorizations.add(WorkbasketAuthorization.CUSTOM_8);
break;
}
}
});
return workbasketService.getWorkbaskets(authorizations);
workbaskets = workbasketService.getWorkbaskets(authorizations);
} else {
return workbasketService.getWorkbaskets();
workbaskets = workbasketService.getWorkbaskets();
}
return new ResponseEntity<>(workbaskets, HttpStatus.OK);
}
@RequestMapping(value = "/{workbasketid}")
@ -70,8 +96,8 @@ public class WorkbasketController {
return new ResponseEntity<>(workbasket, HttpStatus.OK);
} catch (WorkbasketNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (InvalidWorkbasketException e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotAuthorizedException e) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}
@ -80,12 +106,14 @@ public class WorkbasketController {
Workbasket createdWorkbasket;
try {
createdWorkbasket = workbasketService.createWorkbasket(workbasket);
return new ResponseEntity<>(createdWorkbasket, HttpStatus.CREATED);
} catch (InvalidWorkbasketException e) {
return new ResponseEntity<>(HttpStatus.CONFLICT);
} catch (WorkbasketNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NotAuthorizedException e) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return new ResponseEntity<>(createdWorkbasket, HttpStatus.CREATED);
}
@RequestMapping(value = "/{workbasketkey}", method = RequestMethod.PUT)

View File

@ -13,6 +13,7 @@ import pro.taskana.ClassificationService;
import pro.taskana.Task;
import pro.taskana.TaskQuery;
import pro.taskana.TaskService;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.model.TaskState;
@ -58,11 +59,12 @@ public class TaskFilter {
@Autowired
private ClassificationService classificationService;
public List<Task> getAll() throws NotAuthorizedException {
public List<Task> getAll() throws NotAuthorizedException, InvalidArgumentException {
return taskService.createTaskQuery().list();
}
public List<Task> inspectPrams(MultiValueMap<String, String> params) throws NotAuthorizedException {
public List<Task> inspectPrams(MultiValueMap<String, String> params)
throws NotAuthorizedException, InvalidArgumentException {
TaskQuery taskQuery = taskService.createTaskQuery();
// apply filters

View File

@ -17,7 +17,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import pro.taskana.Workbasket;
import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
/**
@ -51,8 +51,10 @@ public class DistributionTargetDeserializer extends StdDeserializer<List<Workbas
distributionTargets.add(workbasketService.getWorkbasket(id));
} catch (WorkbasketNotFoundException e) {
logger.error("The workbasket with the id '" + id + "' is not found in database.");
} catch (InvalidWorkbasketException e) {
logger.error("The workbasket with the id '" + id + "' misses some required properties. Exception = {}.",
} catch (NotAuthorizedException e) {
logger.error(
"The user misses some required permissions for the workbasket with ID '" + id
+ "'. Exception = {}.",
e);
}
}