Package org.fireflow.engine.persistence

Examples of org.fireflow.engine.persistence.IPersistenceService


                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());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        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();

        //abort processInstance
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.suspend();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });

        assertEquals(IProcessInstance.RUNNING, currentProcessInstance.getState().intValue());
        assertEquals(Boolean.TRUE, currentProcessInstance.isSuspended());
       
        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(Boolean.TRUE, ((ITaskInstance) taskInstanceList.get(0)).isSuspended());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        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());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
      //-------------------------------------------------------------------------------
        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) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }
            }
        });

        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());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
    }
View Full Code Here


                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());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        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();

        //abort processInstance
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.suspend();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });

        assertEquals(IProcessInstance.RUNNING, currentProcessInstance.getState().intValue());
        assertEquals(Boolean.TRUE, currentProcessInstance.isSuspended());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(Boolean.TRUE, ((ITaskInstance) taskInstanceList.get(0)).isSuspended());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        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());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
      //-------------------------------------------------------------------------------
        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) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }
            }
        });

        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());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.restore();

                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
                    paymentTaskWorkItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });
        wi = persistenceService.findWorkItemById(paymentWorkItemId);
        assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());

        tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokensList);
        assertEquals(1, tokensList.size());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();

    }
View Full Code Here

                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());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        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();

        //abort processInstance
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.suspend();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });

        assertEquals(IProcessInstance.RUNNING, currentProcessInstance.getState().intValue());
        assertEquals(Boolean.TRUE, currentProcessInstance.isSuspended());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PaymentActivity");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(Boolean.TRUE, ((ITaskInstance) taskInstanceList.get(0)).isSuspended());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        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());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
      //-------------------------------------------------------------------------------
        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) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }
            }
        });

        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());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.restore();

                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
                    paymentTaskWorkItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });
        wi = persistenceService.findWorkItemById(paymentWorkItemId);
        assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());

        tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokensList);
        assertEquals(1, tokensList.size());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession session = runtimeContext.getWorkflowSession();
                    ITaskInstance taskInstance = (ITaskInstance) session.execute(new IWorkflowSessionCallback() {

                        public Object doInWorkflowSession(RuntimeContext ctx) throws EngineException, KernelException {
                            IPersistenceService persistenceService = runtimeContext.getPersistenceService();
                            List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PrepareGoodsActivity");
                            ITaskInstance taskInstance = (ITaskInstance) taskInstanceList.get(0);
                            return taskInstance;
                        }
                    });
                    taskInstance.suspend();

                } catch (EngineException ex) {

                    ex.printStackTrace();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PrepareGoodsActivity");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        ITaskInstance taskInstance = (ITaskInstance) taskInstanceList.get(0);
        assertEquals(Boolean.TRUE, taskInstance.isSuspended());
View Full Code Here

                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());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        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();

        //abort processInstance
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.suspend();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });
       
        this.refresh(currentProcessInstance);
       
        assertEquals(IProcessInstance.RUNNING, currentProcessInstance.getState().intValue());
        assertEquals(Boolean.TRUE, currentProcessInstance.isSuspended());

        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());
        assertEquals(Boolean.TRUE, ((ITaskInstance) taskInstanceList.get(0)).isSuspended());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        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());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
      //-------------------------------------------------------------------------------
        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) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }
            }
        });

        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());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    currentProcessInstance.restore();

                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem paymentTaskWorkItem = workflowSession.findWorkItemById(paymentWorkItemId);
                    paymentTaskWorkItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });
        wi = persistenceService.findWorkItemById(paymentWorkItemId);
        assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());

        tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokensList);
        assertEquals(1, tokensList.size());
        token = (IToken) tokensList.get(0);
        assertEquals(2, token.getStepNumber().intValue());

        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();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession session = runtimeContext.getWorkflowSession();
                    ITaskInstance taskInstance = (ITaskInstance) session.execute(new IWorkflowSessionCallback() {

                        public Object doInWorkflowSession(RuntimeContext ctx) throws EngineException, KernelException {
                            IPersistenceService persistenceService = runtimeContext.getPersistenceService();
                            List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PrepareGoodsActivity");
                            ITaskInstance taskInstance = (ITaskInstance) taskInstanceList.get(0);
                            return taskInstance;
                        }
                    });
                    taskInstance.suspend();

                } catch (EngineException ex) {

                    ex.printStackTrace();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                }
                return null;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Goods_Deliver_Process.PrepareGoodsActivity");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        ITaskInstance taskInstance = (ITaskInstance) taskInstanceList.get(0);
        assertEquals(Boolean.TRUE, taskInstance.isSuspended());
View Full Code Here

                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } 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;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.CANCELED), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(2, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
       
        this.refresh(workItemList.get(0));
       
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.CANCELED), ((IWorkItem) workItemList.get(0)).getState());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(3, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(4, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.reject();
                } 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;
            }
        });


        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(2, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(5, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(3, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(6, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(7, token.getStepNumber().intValue());
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(4, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(3, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(8, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(9, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.claim();
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(10, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());
      //---------------------------------------------------------------------------------------------
        System.out.println("------------------withdraw from work item 3--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //------------------------------------------------------------------------------
        System.out.println("------------------reject from work item 5--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());//重点研究。。。
        token = (IToken) tokenList.get(0);
        assertEquals(11, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(12, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(13, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemList.get(0)).getId();
View Full Code Here

                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } 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;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.CANCELED), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(2, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
       
        this.refresh(workItemList.get(0));
       
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.CANCELED), ((IWorkItem) workItemList.get(0)).getState());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(3, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(4, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.reject();
                } 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;
            }
        });


        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(2, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(5, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(3, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(6, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(7, token.getStepNumber().intValue());
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(4, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(3, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(8, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(9, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.claim();
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(10, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());
      //---------------------------------------------------------------------------------------------
        System.out.println("------------------withdraw from work item 3--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //------------------------------------------------------------------------------
        System.out.println("------------------reject from work item 5--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());//重点研究。。。
        token = (IToken) tokenList.get(0);
        assertEquals(11, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(12, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(13, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemList.get(0)).getId();

      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    IWorkItem newWorkItem = workItem.withdraw();
                    workItem5Id = newWorkItem.getId();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(14, token.getStepNumber().intValue());

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(15, token.getStepNumber().intValue());

        List workItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemsList);
        assertEquals(1, workItemsList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemsList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemsList.get(0)).getId();
View Full Code Here

                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());

        List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        IToken token = (IToken) tokenList.get(0);
        assertEquals(1, token.getStepNumber().intValue());

        List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } 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;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
       
        this.refresh((ITaskInstance) taskInstanceList.get(0));
       
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        assertEquals(new Integer(ITaskInstance.CANCELED), ((ITaskInstance) taskInstanceList.get(0)).getState());
        assertEquals(2, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
       
        this.refresh(workItemList.get(0));
       
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.CANCELED), ((IWorkItem) workItemList.get(0)).getState());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(3, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(4, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
      //------------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.reject();
                } 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;
            }
        });


        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(2, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(2, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(5, token.getStepNumber().intValue());

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(3, taskInstanceList.size());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem1Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.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);
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(6, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.claim();
                    workItem.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);
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(7, token.getStepNumber().intValue());
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //--------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity2");
        assertNotNull(taskInstanceList);
        assertEquals(4, taskInstanceList.size());


        workItemList = persistenceService.findHaveDoneWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(3, workItemList.size());


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(8, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem2Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem2Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(9, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.claim();
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(10, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());
      //---------------------------------------------------------------------------------------------
        System.out.println("------------------withdraw from work item 3--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.withdraw();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
      //------------------------------------------------------------------------------
        System.out.println("------------------reject from work item 5--------------------------------");
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());//重点研究。。。
        token = (IToken) tokenList.get(0);
        assertEquals(11, token.getStepNumber().intValue());

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity3.Task3");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem3Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity4.Task4");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());

        workItem4Id = ((IWorkItem) workItemList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem3Id);
                    workItem.complete();

                    workItem = workflowSession.findWorkItemById(workItem4Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(3, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(12, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemList.get(0)).getId();

        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity6.Task6");
        assertNotNull(workItemList);
        assertEquals(0, workItemList.size());

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.claim();
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(13, token.getStepNumber().intValue());



        workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemList.get(0)).getId();

      //-------------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    IWorkItem newWorkItem = workItem.withdraw();
                    workItem5Id = newWorkItem.getId();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });


        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(14, token.getStepNumber().intValue());

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });
        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(15, token.getStepNumber().intValue());

        List workItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemsList);
        assertEquals(1, workItemsList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemsList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemsList.get(0)).getId();
      //--------------------------------------------------
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem7Id);
                    workItem.reject();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(2, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(16, token.getStepNumber().intValue());

        workItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity5.Task5");
        assertNotNull(workItemsList);
        assertEquals(1, workItemsList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemsList.get(0)).getState());

        workItem5Id = ((IWorkItem) workItemsList.get(0)).getId();

        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem workItem = workflowSession.findWorkItemById(workItem5Id);
                    workItem.complete();
                } catch (EngineException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                } catch (KernelException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException();
                }

                return null;
            }
        });

        tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokenList);
        assertEquals(1, tokenList.size());
        token = (IToken) tokenList.get(0);
        assertEquals(17, token.getStepNumber().intValue());

        workItemsList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity7.Task7");
        assertNotNull(workItemsList);
        assertEquals(1, workItemsList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemsList.get(0)).getState());

        workItem7Id = ((IWorkItem) workItemsList.get(0)).getId();
View Full Code Here

                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List<ITaskInstance> taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.A");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
       

        List<IWorkItem> workItemList = persistenceService.findTodoWorkItems(AssignToCurrentUserAndCompleteWorkItemHandler.ACTOR_ID, "AbortTaskInstance2", "AbortTaskInstance2.A.TaskA");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
        final String workItemAId = ((IWorkItem) workItemList.get(0)).getId();
       
        //结束Activity A的工作项,使流程流转到B环节
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem wi = workflowSession.findWorkItemById(workItemAId);
                    wi.claim();
                    wi.complete();
                    return null;
                } 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;
            }
        });
       
        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.B");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());   
        //String taskInstanceBId = ((ITaskInstance)taskInstanceList.get(0)).getId();
       
        workItemList = persistenceService.findTodoWorkItems(AssignToCurrentUserAndCompleteWorkItemHandler.ACTOR_ID, "AbortTaskInstance2", "AbortTaskInstance2.B.TaskB");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
        //String workItemBId = ((IWorkItem) workItemList.get(0)).getId();       
    }   
View Full Code Here

                return null;
            }
        });
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List<ITaskInstance> taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.A");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
       

        List<IWorkItem> workItemList = persistenceService.findTodoWorkItems(AssignToCurrentUserAndCompleteWorkItemHandler.ACTOR_ID, "AbortTaskInstance2", "AbortTaskInstance2.A.TaskA");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
        final String workItemAId = ((IWorkItem) workItemList.get(0)).getId();
       
        //结束Activity A的工作项,使流程流转到B环节
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    IWorkItem wi = workflowSession.findWorkItemById(workItemAId);
                    wi.claim();
                    wi.complete();
                    return null;
                } 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;
            }
        });
       
        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.B");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());   
        final String taskInstanceBId = ((ITaskInstance)taskInstanceList.get(0)).getId();
       
        workItemList = persistenceService.findTodoWorkItems(AssignToCurrentUserAndCompleteWorkItemHandler.ACTOR_ID, "AbortTaskInstance2", "AbortTaskInstance2.B.TaskB");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
        //String workItemBId = ((IWorkItem) workItemList.get(0)).getId();       
     
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
                    ITaskInstance taskInstance = workflowSession.findTaskInstanceById(taskInstanceBId);
                    DynamicAssignmentHandler dynamicHandler = new DynamicAssignmentHandler();
                    List<String> actorsList = new ArrayList<String>();
                    actorsList.add("zhangsan");
                    dynamicHandler.setActorIdsList(actorsList);
                    taskInstance.abort("AbortTaskInstance2.D",dynamicHandler);
                    return null;
                } 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;
            }
        });     
        //IPersistenceService persistenceService = runtimeContext.getPersistenceService();
       
       // List<ITaskInstance>
        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.B");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        int taskInstanceState = ((ITaskInstance)taskInstanceList.get(0)).getState();
        assertEquals(ITaskInstance.CANCELED,taskInstanceState);          
       
        taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "AbortTaskInstance2.D");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        taskInstanceState = ((ITaskInstance)taskInstanceList.get(0)).getState();
        assertEquals(ITaskInstance.RUNNING,taskInstanceState);
     
        //List<IWorkItem>
        workItemList = persistenceService.findTodoWorkItems("zhangsan", "AbortTaskInstance2", "AbortTaskInstance2.D.TaskD");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.RUNNING), ((IWorkItem) workItemList.get(0)).getState());
        //workItemCId = ((IWorkItem) workItemList.get(0)).getId();         
    }
View Full Code Here

         
        });
      
        assertNotNull(currentProcessInstance);

        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
        List<ITaskInstance> taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "Loop.Activity1");
        assertNotNull(taskInstanceList);
        assertEquals(1, taskInstanceList.size());
        ITaskInstance taskInst = ((ITaskInstance) taskInstanceList.get(0));
        assertEquals(new Integer(ITaskInstance.RUNNING),taskInst .getState());
        assertEquals(1,taskInst.getStepNumber().intValue());

        List<IWorkItem> workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "Loop", "Loop.Activity1.Task1");
        assertNotNull(workItemList);
        assertEquals(1, workItemList.size());
        assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());

        List<IToken> tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
        assertNotNull(tokensList);
        assertEquals(1, tokensList.size());
        IToken token = (IToken)tokensList.get(0);
        assertEquals(1,token.getStepNumber().intValue());
View Full Code Here

TOP

Related Classes of org.fireflow.engine.persistence.IPersistenceService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.