String[] emptyRoles = {};
Situation situation = new CMSSituation(emptyRoles, "test", "127.0.0.1");
WorkflowInstance instance = resolver.getWorkflowInstance(document);
instance.getHistory().initialize(situation);
for (int situationIndex = 0; situationIndex < situations.length; situationIndex++) {
assertNotNull(instance);
System.out.println("Current state: " + instance.getCurrentState());
Identity identity = new Identity();
User user = getAccreditableManager().getUserManager().getUser(
situations[situationIndex].getUser());
identity.addIdentifiable(user);
Role[] roles = policy.getRoles(identity);
System.out.print("Roles:");
for (int roleIndex = 0; roleIndex < roles.length; roleIndex++) {
System.out.print(" " + roles[roleIndex]);
}
System.out.println();
String[] roleIds = new String[roles.length];
for (int i = 0; i < roles.length; i++) {
roleIds[i] = roles[i].getId();
}
situation = new CMSSituation(roleIds, identity.getUser().getId(), "");
String[] events = instance.getExecutableEvents(situation);
String event = null;
System.out.print("Events:");
for (int eventIndex = 0; eventIndex < events.length; eventIndex++) {
System.out.print(" " + events[eventIndex]);
if (events[eventIndex].equals(situations[situationIndex].getEvent())) {
event = events[eventIndex];
}
}
assertNotNull(event);
System.out.println();
System.out.println("Executing event: " + event);
instance.invoke(situation, event);
assertTrue(instance.getValue(variableName) == situations[situationIndex].getValue());
System.out.println("Variable: " + variableName + " = "
+ instance.getValue(variableName));
System.out.println("------------------------------------------------------");
}
}
finally {
// this.manager.release(resolver);