deliverGoodsWorkItemId = ((IWorkItem) todoWorkItemsList.get(0)).getId();
}
@Test(expected=RuntimeException.class)
public void testWithdrawPrepareGoodsWorkItem(){
currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
//启动"/workflowdefinition/example_workflow.xml"中的“送货流程”
IProcessInstance processInstance = workflowSession.createProcessInstance("Goods_Deliver_Process","fireflowTester");
processInstance.setProcessInstanceVariable("mobile", mobile);
processInstance.run();
return processInstance;
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
});
assertNotNull(currentProcessInstance);
IPersistenceService persistenceService = runtimeContext.getPersistenceService();
List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
assertNotNull(taskInstanceList);
assertEquals(1, taskInstanceList.size());
assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.PaymentActivity.Payment_Task");
assertNotNull(workItemList);
assertEquals(1, workItemList.size());
assertEquals(new Integer(ITaskInstance.RUNNING), ((IWorkItem) workItemList.get(0)).getState());
paymentWorkItemId = ((IWorkItem) workItemList.get(0)).getId();
//---------------------------------------------------------
System.out.println("--------------Withdraw Payment WorkItem ----------------");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
paymentTaskWorkItem.withdraw();
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex.getMessage());
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//----------------------------------------------------------
System.out.println("--------------Complete Payment WorkItem ----------------");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
paymentTaskWorkItem.complete();
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
IWorkItem wi = persistenceService.findWorkItemById(paymentWorkItemId);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
List tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
List todoWorkItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.PrepareGoodsTask");
assertNotNull(todoWorkItemsList);
assertEquals(1, todoWorkItemsList.size());
prepareGoodsWorkItemId = ((IWorkItem) todoWorkItemsList.get(0)).getId();
//--------------------------------------------------------
System.out.println("--------------Withdraw Payment WorkItem After It Has Bean Completed----------------");
IWorkItem newWorkItem = (IWorkItem)transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();