public void testNextToken() {
// retrieve a token from the service given the ff. instance and node id's
InstanceID instanceId = new InstanceID(instanceCounter++);
Node parentNode = new FullBaseNode();
parentNode.setDisplayName("parent_node");
parentNode.setNodeId(new NodeID(nodeCounter++));
Token parentToken = tokenService.newToken(instanceId, parentNode.getNodeId(), Token.PRE);
TokenID tokenId = parentToken.getTokenID();
// create n child nodes
Node[] childrenNode = new Node[5];
for(int i = 0; i < childrenNode.length; i++) {
Node childNode = new FullBaseNode();
childNode.setDisplayName("child_node_"+ i);
childNode.setNodeId(new NodeID(nodeCounter++));
childrenNode[i] = childNode;
}
// create childrenNode.length connections
Connection[] connections = new Connection[childrenNode.length];
for(int i = 0; i < connections.length; i++) {
Connection connection = new ConnectionImpl("connection_"+ i);
connection.setParentNode(parentNode);
connection.setChildNode(childrenNode[i]);
parentNode.addOutboundConnection(connection);
childrenNode[i].addInboundConnection(connection);
connections[i] = connection;
}
// tokens are created in the order of connections -- this test will be using that fact.
// question: would it be proper to do so? Is that a property of the engine?
Token[] tokens = tokenService.nextToken(connections, parentToken);
for(int i = 0; i < tokens.length; i++) {
Token token = tokens[i];
InstanceID instance_id = token.getInstanceID();
NodeID currentNodeId = token.getCurrentNodeID();
int currentState = token.getCurrentState();
Node currentNode = childrenNode[i];
Connection[] inbound = currentNode.getInboundConnections();
assertNotNull(instance_id);
assertEquals(instanceId, instance_id);
// here is where we use the ordering
assertEquals(currentNode.getNodeId(), currentNodeId);
assertEquals(Token.PRE, currentState);
assertNotNull(inbound);
assertEquals(1, inbound.length);
assertNotNull(inbound[0].getParentNode());
assertSame(parentNode, inbound[0].getParentNode());