re : Decision Hanlder
krsenthil Jul 10, 2006 11:52 AMHello,
In my junit code, I constructed a decision node and added transitions to it. But I do not know how to add the decision handlers. The purpose of this unit test is to prove all node classes can be created programmatically. Here is my junit test code. The AmountDecisionHandler is a DecisionHandler and always returns "forwardTo" value on decision method.
Please help me.
ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
StartState startState = new StartState();
startState.setName("start");
processDefinition.addNode(startState);
Decision amountcheck = new Decision();
amountcheck.setName("amountcheck");
processDefinition.addNode(amountcheck);
State reenter = new State();
reenter.setName("reenter");
processDefinition.addNode(reenter);
State increase = new State();
increase.setName("increase");
processDefinition.addNode(increase);
EndState endState = new EndState();
endState.setName("end");
processDefinition.addNode(endState);
Transition amountCheckTxns = new Transition();
amountCheckTxns.setTo(amountcheck);
Transition successTxns = new Transition();
successTxns.setName("success");
successTxns.setTo(increase);
Transition failTxns = new Transition();
failTxns.setName("fail");
failTxns.setTo(reenter);
Transition endTrans = new Transition();
endTrans.setTo(endState);
//bind transitions to node
startState.addLeavingTransition(amountCheckTxns);
amountcheck.addLeavingTransition(successTxns);
amountcheck.addLeavingTransition(failTxns);
reenter.addLeavingTransition(amountCheckTxns);
increase.addLeavingTransition(endTrans);
ProcessInstance processInstance = new ProcessInstance(processDefinition);
AmountDecisionHandler.forwardTo ="success";
// after the first signal the AmountDecisionHandler of amountcheck
// would be called. The handler forwards to increase node imediately.
processInstance.signal();
assertSame(processDefinition.getNode("increase"), processInstance.getRootToken().getNode());
processInstance.signal();
assertSame(processDefinition.getNode("end"), processInstance.getRootToken().getNode());
processInstance = new ProcessInstance(processDefinition);
//now forward to "fail" state
AmountDecisionHandler.forwardTo ="fail";
// after the first signal the AmountDecisionHandler of amountcheck
// would be called. The handler forwards to reenter node imediately.
processInstance.signal();
assertSame(processDefinition.getNode("reenter"), processInstance.getRootToken().getNode());
AmountDecisionHandler.forwardTo ="success";
processInstance.signal();
assertSame(processDefinition.getNode("increase"), processInstance.getRootToken().getNode());