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();
IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
IWorkItem newWorkItem = paymentTaskWorkItem.withdraw();
return newWorkItem;
} 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;
}
});
paymentWorkItemId = newWorkItem.getId();
wi = persistenceService.findWorkItemById(paymentWorkItemId);
assertEquals(new Integer(IWorkItem.RUNNING), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
List tokensList4Payment = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
assertNotNull(tokensList4Payment);
assertEquals(1, tokensList4Payment.size());
assertEquals(Boolean.TRUE,((IToken)tokensList4Payment.get(0)).isAlive());
// assertEquals(((TaskInstance)wi.getTaskInstance()).getTokenId(),((IToken)tokensList4Payment.get(0)).getId());
List haveDoneWorkItemsList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.PrepareGoodsTask");
assertNotNull(haveDoneWorkItemsList);
assertEquals(1, haveDoneWorkItemsList.size());
IWorkItem prepareGoodsWorkItem = ((IWorkItem) haveDoneWorkItemsList.get(0));
prepareGoodsWorkItemId = prepareGoodsWorkItem.getId();
assertEquals(new Integer(IWorkItem.CANCELED),prepareGoodsWorkItem.getState());
assertEquals(new Integer(ITaskInstance.CANCELED),prepareGoodsWorkItem.getTaskInstance().getState());
assertNotNull(prepareGoodsWorkItem.getEndTime());
assertNotNull(prepareGoodsWorkItem.getTaskInstance().getEndTime());
//--------------------------------------------------------------
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);
}
}
});
wi = persistenceService.findWorkItemById(paymentWorkItemId);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
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("--------------Claim Prepare Goods WorkItem ----------------");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem prepareGoodsWorkItem = workflowSession.findWorkItemById(prepareGoodsWorkItemId);
prepareGoodsWorkItem.claim();
} 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);
}
}
});
wi = persistenceService.findWorkItemById(prepareGoodsWorkItemId);
assertEquals(new Integer(IWorkItem.RUNNING), wi.getState());
//------------------------------------------------------------
System.out.println("--------------Complete Prepare Goods WorkItem ----------------");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem prepareGoodsWorkItem = workflowSession.findWorkItemById(prepareGoodsWorkItemId);
prepareGoodsWorkItem.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);
}
}
});
wi = persistenceService.findWorkItemById(prepareGoodsWorkItemId);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(2, tokensList.size());
List tokensListOnEndNode = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.EndNode1");
assertNotNull(tokensListOnEndNode);
assertEquals(1, tokensListOnEndNode.size());
IToken tokenOnEndNode = (IToken)tokensListOnEndNode.get(0);
if (mobile==null){
assertEquals(Boolean.FALSE,tokenOnEndNode.isAlive());
}else{
assertEquals(Boolean.TRUE,tokenOnEndNode.isAlive());
}
todoWorkItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Goods_Deliver_Process", "Goods_Deliver_Process.DeliverGoodsActivity.DeliverGoodsTask");
assertNotNull(todoWorkItemsList);
assertEquals(1, todoWorkItemsList.size());
deliverGoodsWorkItemId = ((IWorkItem) todoWorkItemsList.get(0)).getId();
//--------------------------------------------------------------------------
System.out.println("--------------Withdraw Payment WorkItem ----------------");