* Test starting a created instance.
*
*/
public void testStart() {
// get a business process id
BusinessProcessImpl bProcess = new BusinessProcessImpl();
String graphName = "Graph" + count++;
bProcess.setName(graphName);
Node rootNode = new BaseNodeImpl() {
public Connection[] doEnd(NodeContext ctx) {
return null;
}
};
rootNode.setNodeId(new NodeID(1));
rootNode.setDisplayName("root");
bProcess.setRoot(rootNode);
BusinessProcessID bpId = bpService.addGraph(bProcess);
// then create a map of parameters
Map params = new HashMap();
params.put("foo", "foo value");
params.put("bar", "bar value");
params.put("baz", "baz value");
// create a new instance using the service
InstanceID instanceId = instanceService.newInstance(bpId, params);
// start the newly created instance
instanceService.start(instanceId);
// wait until the message has been consumed in the queue
while(engineMessage == null) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
fail();
}
}
if(engineMessage == null) {
fail("something went wrong");
}
assertEquals("Type must be 'move token'", EngineMessage.TYPE_MOVE_TOKEN, engineMessage.getMessageType());
TokenID tokenId = engineMessage.getCurrentTokenID();
Token token = tokenService.getTokenByID(tokenId);
assertEquals(1, token.getCurrentNodeID().getID());
assertTrue(token.isActive());
assertEquals(Token.PRE, token.getCurrentState());
assertNotNull(bpService.getGraphByID(instanceService.getInstanceByID(token.getInstanceID()).getBusinessProcessID()));
assertSame(bProcess.getRoot(),
bpService.getGraphByID(instanceService.getInstanceByID(token.getInstanceID()).getBusinessProcessID()).getRoot());
}