示例#1
0
 public boolean hasBeenExecuted(BpelActivity activity, List<Token> closedChildTokens) {
   if (closedChildTokens == null || closedChildTokens.size() == 0) {
     return false;
   }
   for (Token childToken : closedChildTokens) {
     if (childToken.getElementId().equals(activity.getId())) {
       return true;
     }
   }
   return false;
 }
  public void assertResult(WorkflowSession session) {
    super.assertResult(session);

    // 验证ProcessInstance信息
    WorkflowQuery<ProcessInstance> q4ProcInst = session.createWorkflowQuery(ProcessInstance.class);
    ProcessInstance procInst = q4ProcInst.get(processInstanceId);
    Assert.assertNotNull(procInst);

    Assert.assertEquals(bizId, procInst.getBizId());
    Assert.assertEquals(processName, procInst.getProcessId());
    Assert.assertEquals(FpdlConstants.PROCESS_TYPE_FPDL20, procInst.getProcessType());
    Assert.assertEquals(new Integer(1), procInst.getVersion());
    Assert.assertEquals(processName, procInst.getProcessName()); // name 为空的情况下默认等于processId,
    Assert.assertEquals(
        processDisplayName, procInst.getProcessDisplayName()); // displayName为空的情况下默认等于name
    Assert.assertEquals(ProcessInstanceState.COMPENSATED, procInst.getState());
    Assert.assertEquals(Boolean.FALSE, procInst.isSuspended());
    Assert.assertEquals(FireWorkflowSystem.getInstance().getId(), procInst.getCreatorId());
    Assert.assertEquals(FireWorkflowSystem.getInstance().getName(), procInst.getCreatorName());
    Assert.assertEquals(FireWorkflowSystem.getInstance().getDeptId(), procInst.getCreatorDeptId());
    Assert.assertEquals(
        FireWorkflowSystem.getInstance().getDeptName(), procInst.getCreatorDeptName());
    Assert.assertNotNull(procInst.getCreatedTime());
    Assert.assertNotNull(procInst.getEndTime());
    Assert.assertNull(procInst.getExpiredTime());
    Assert.assertNull(procInst.getParentActivityInstanceId());
    Assert.assertNull(procInst.getParentProcessInstanceId());
    Assert.assertNull(procInst.getParentScopeId());
    Assert.assertNull(procInst.getNote());

    // 验证Token信息
    WorkflowQuery<Token> q4Token = session.createWorkflowQuery(Token.class);
    q4Token
        .add(Restrictions.eq(TokenProperty.PROCESS_INSTANCE_ID, processInstanceId))
        .addOrder(Order.asc(TokenProperty.STEP_NUMBER));

    List<Token> tokenList = q4Token.list();
    Assert.assertNotNull(tokenList);
    Assert.assertEquals(18, tokenList.size());

    Token procInstToken = tokenList.get(0);
    Assert.assertEquals(
        processName + ModelElement.ID_SEPARATOR + WorkflowProcess.MAIN_PROCESS_NAME,
        procInstToken.getElementId());
    Assert.assertEquals(processInstanceId, procInstToken.getElementInstanceId());
    Assert.assertEquals(processName, procInstToken.getProcessId());
    Assert.assertEquals(FpdlConstants.PROCESS_TYPE_FPDL20, procInstToken.getProcessType());
    Assert.assertEquals(new Integer(1), procInstToken.getVersion());
    Assert.assertEquals(TokenState.COMPENSATED, procInstToken.getState());
    Assert.assertNull(procInstToken.getParentTokenId());
    Assert.assertTrue(procInstToken.isBusinessPermitted());
    Assert.assertEquals(procInst.getTokenId(), procInstToken.getId());

    Token startNodeToken = tokenList.get(1);
    Assert.assertEquals(processName, startNodeToken.getProcessId());
    Assert.assertEquals(new Integer(1), startNodeToken.getVersion());
    Assert.assertEquals(FpdlConstants.PROCESS_TYPE_FPDL20, startNodeToken.getProcessType());
    Assert.assertEquals(procInstToken.getId(), startNodeToken.getParentTokenId());
    Assert.assertTrue(startNodeToken.isBusinessPermitted());

    Token activity1Token = tokenList.get(3);
    // 检验fromToken的有效性
    for (Token t : tokenList) {
      if (t != procInstToken) {
        Assert.assertNotNull(t.getFromToken());
      }
    }

    // 验证ActivityInstance信息
    WorkflowQuery<ActivityInstance> q4ActInst = session.createWorkflowQuery(ActivityInstance.class);
    q4ActInst
        .add(Restrictions.eq(ActivityInstanceProperty.PROCESS_INSTANCE_ID, processInstanceId))
        .add(
            Restrictions.eq(
                ActivityInstanceProperty.NODE_ID,
                processName
                    + ModelElement.ID_SEPARATOR
                    + WorkflowProcess.MAIN_PROCESS_NAME
                    + ".Activity1"));
    List<ActivityInstance> actInstList = q4ActInst.list();
    Assert.assertNotNull(actInstList);
    Assert.assertEquals(1, actInstList.size());
    ActivityInstance activityInstance = actInstList.get(0);
    Assert.assertEquals(bizId, activityInstance.getBizId());
    Assert.assertEquals("Activity1", activityInstance.getName());
    Assert.assertEquals("Activity1", activityInstance.getDisplayName());
    Assert.assertEquals(processInstanceId, activityInstance.getParentScopeId());
    Assert.assertNotNull(activityInstance.getCreatedTime());
    Assert.assertNotNull(activityInstance.getStartedTime());
    Assert.assertNotNull(activityInstance.getEndTime());
    Assert.assertNull(activityInstance.getExpiredTime());
    Assert.assertNotNull(activityInstance.getTokenId());
    Assert.assertEquals(activity1Token.getId(), activityInstance.getTokenId());
    Assert.assertEquals(activity1Token.getElementId(), activityInstance.getNodeId());
    Assert.assertEquals(activity1Token.getElementInstanceId(), activityInstance.getId());
    Assert.assertNotNull(activityInstance.getScopeId());

    Assert.assertEquals(new Integer(1), activityInstance.getVersion());
    Assert.assertEquals(FpdlConstants.PROCESS_TYPE_FPDL20, activityInstance.getProcessType());
    Assert.assertEquals(procInst.getProcessName(), activityInstance.getProcessName());
    Assert.assertEquals(procInst.getProcessDisplayName(), activityInstance.getProcessDisplayName());

    Assert.assertEquals(ActivityInstanceState.COMPLETED, activityInstance.getState());

    // Activity2,Activity3应该是被补偿状态
    q4ActInst.reset();
    q4ActInst
        .add(Restrictions.eq(ActivityInstanceProperty.PROCESS_INSTANCE_ID, processInstanceId))
        .add(
            Restrictions.eq(
                ActivityInstanceProperty.NODE_ID,
                processName
                    + ModelElement.ID_SEPARATOR
                    + WorkflowProcess.MAIN_PROCESS_NAME
                    + ".Activity2"));
    actInstList = q4ActInst.list();
    Assert.assertNotNull(actInstList);
    Assert.assertEquals(1, actInstList.size());
    activityInstance = actInstList.get(0);
    Assert.assertEquals(ActivityInstanceState.COMPENSATED, activityInstance.getState());

    q4ActInst.reset();
    q4ActInst
        .add(Restrictions.eq(ActivityInstanceProperty.PROCESS_INSTANCE_ID, processInstanceId))
        .add(
            Restrictions.eq(
                ActivityInstanceProperty.NODE_ID,
                processName
                    + ModelElement.ID_SEPARATOR
                    + WorkflowProcess.MAIN_PROCESS_NAME
                    + ".Activity3"));
    actInstList = q4ActInst.list();
    Assert.assertNotNull(actInstList);
    Assert.assertEquals(1, actInstList.size());
    activityInstance = actInstList.get(0);
    Assert.assertEquals(ActivityInstanceState.COMPENSATED, activityInstance.getState());
  }