}
public void testPATaskLifecycle() throws Exception {
ITMSServer server = Utils.createTMSServer();
PATask paTask = new PATask("taskID", new URI("http://localhost/1"), "processID", "urn:completeSOAPAction", Utils.createXMLDocument());
paTask.getUserOwners().add("test/user1");
paTask.getRoleOwners().add("test/role3");
paTask.getUserOwners().add("test/user1");
paTask.getRoleOwners().add("test/role3");
ITaskDAOConnectionFactory daoFactory=new SimpleTaskDAOConnectionFactory();
ITaskDAOConnection dao=daoFactory.openConnection();
server.create(dao,paTask, "token1");
TaskEquality.areTasksEquals(paTask, server.getTask(dao,"taskID", "token1"));
TaskEquality.areTasksEquals(paTask, server.getTask(dao,"taskID", "token2"));
TaskEquality.areTasksEquals(paTask, server.getTaskList(dao,"token1")[0]);
TaskEquality.areTasksEquals(paTask, server.getTaskList(dao,"token2")[0]);
try {
server.getTask(dao,"taskID", "token3");
Assert.fail("AccessDeniedException expected");
} catch (AccessDeniedException e) {
}
Assert.assertEquals(0, server.getTaskList(dao,"token3").length);
Document newOutput1 = Utils.createXMLDocument();
server.setOutput(dao,"taskID", newOutput1, "token1");
PATask taskWithSetOutput = (PATask) server.getTask(dao,"taskID", "token2");
Assert.assertTrue(XmlTooling.equals(newOutput1, taskWithSetOutput.getOutput()));
Assert.assertEquals(TaskState.READY, taskWithSetOutput.getState());
// test reassign
org.intalio.tempo.workflow.auth.AuthIdentifierSet newUsers = new org.intalio.tempo.workflow.auth.AuthIdentifierSet(new String[]{"test/user1", "test/user2"});
org.intalio.tempo.workflow.auth.AuthIdentifierSet newRoles = new org.intalio.tempo.workflow.auth.AuthIdentifierSet(new String[]{"test/role2", "test/role3"});
server.reassign(dao,"taskID", newUsers, newRoles, TaskState.READY, "token1");
Document newOutput2 = Utils.createXMLDocument();
server.setOutputAndComplete(dao,"taskID", newOutput2, "token2");
PATask completedTask = (PATask) server.getTask(dao,"taskID", "token1");
Assert.assertTrue(XmlTooling.equals(newOutput2, completedTask.getOutput()));
Assert.assertEquals(TaskState.COMPLETED, completedTask.getState());
String failureCode = "failure-code";
String failureReason = "failure reason";
server.fail(dao,"taskID", failureCode, failureReason, "token1");
PATask failedTask = (PATask) server.getTask(dao,"taskID", "token2");
Assert.assertEquals(TaskState.FAILED, failedTask.getState());
Assert.assertEquals(failureCode, failedTask.getFailureCode());
Assert.assertEquals(failureReason, failedTask.getFailureReason());
try {
server.delete(dao,new String[] { "taskID" }, "token1");
Assert.fail("AuthException expected");
} catch (UnavailableTaskException e) {