initSecurityProvider();
initRBACProvider();
}
public void testReassginTaskLifecycle() throws Exception {
ITaskManagementService tms = new RemoteTMSFactory(
"http://localhost:8080/axis2/services/TaskManagementServices", TOKEN_CURRENT).getService();
/*
* Get available users
*/
_logger.debug("Get the users from role: " + ROLE_TARGET2);
RBACQuery query = rbacProvider.getQuery();
String[] users = query.assignedUsers(ROLE_TARGET2);
_logger.debug("Get the users: " + Arrays.asList(users));
/*
* Create a new task for current user
*/
PATask task1 = new PATask(String.valueOf(new Random().nextInt(10000)), new URI("http://localhost/1"),
"processID", "urn:completeSOAPAction", Utils.createXMLDocument());
task1.getUserOwners().add(USER_CURRENT);
tms.create(task1);
/*
* Get task list of current user
*/
_logger.debug("Get the task list from token: " + TOKEN_CURRENT);
Task[] tasks = tms.getTaskList();
/*
* Select one task to re-assign
*/
PATask selectTask = null;
for (Task task : tasks) {
_logger.debug(task.getClass().getName());
if (task instanceof PATask) {
selectTask = (PATask) task;
break;
}
}
if (selectTask == null) {
throw new Exception("There is no PATask in the current user[examples\\msmith] task list");
}
String selectTaskId = selectTask.getID();
_logger.debug("Select one task: " + selectTaskId);
/*
* Select a user to be re-assigned.
*/
AuthIdentifierSet targetUserSet = new AuthIdentifierSet();
String targetUserId = users[0];
_logger.debug("Select one target user = " + targetUserId);
targetUserSet.add(targetUserId);
/*
* Re-assign task
*/
Collection<String> uOwners = selectTask.getUserOwners();
uOwners.clear();
selectTask.getRoleOwners().clear();
selectTask.getUserOwners().addAll(targetUserSet);
tms.reassign(new String[] {selectTask.getID()}, (AuthIdentifierSet)selectTask.getUserOwners(), (AuthIdentifierSet) selectTask.getRoleOwners(), selectTask.getState());
_logger.debug("Reassign task[" + selectTaskId + "] to " + targetUserId);
/*
* check that the task is not in the inbox of current user
*/
boolean task_nowuser_inbox = false;
Task[] tasks2 = tms.getTaskList();
for (int i = 0; i < tasks2.length; i++) {
if (selectTaskId.equalsIgnoreCase(tasks2[i].getID())) {
task_nowuser_inbox = true;
}
}
if (!task_nowuser_inbox) {
_logger.debug("The task " + selectTaskId + " is not in the current user[" + USER_CURRENT + "]");
}
Assert.assertEquals(false, task_nowuser_inbox);
/*
* check that the task is not in the inbox of target user
*/
ITaskManagementService tms_target = new RemoteTMSFactory(
"http://localhost:8080/axis2/services/TaskManagementServices", TOKEN_TARGET2).getService();
boolean task_targetuser_inbox = false;
Task[] tasks3 = tms_target.getTaskList();
for (int i = 0; i < tasks3.length; i++) {
if (selectTaskId.equalsIgnoreCase(tasks3[i].getID())) {