Exemple #1
0
 /**
  * Wait until the process return the state in parameter
  *
  * @param apiSession
  * @param state
  * @throws Exception
  */
 public void waitProcessState(final APISession apiSession, final String state) {
   final ProcessAPI processAPI = TestProcess.getProcessAPI(apiSession);
   for (int i = 0; i < GET_NEXT_NB_ATTEMPT; i++) {
     ProcessInstance instance;
     try {
       instance = processAPI.getProcessInstance(this.processInstance.getId());
       if (instance != null && state.equals(instance.getState())) {
         break;
       }
       Thread.sleep(SLEEP_TIME_MS);
     } catch (final Exception e) {
       throw new TestToolkitException(
           "Can't get process instance <" + this.processInstance.getId() + ">.", e);
     }
   }
 }
 /**
  * @param serverURL Bonita server host URL
  *     <p>Examples: http://localhost:8080 or http://localhost or https://localhost:8081 *
  * @param processInstanceId * @param formMode app or form
  * @param processAPI
  * @return URL to access to a process case overview form
  * @throws ProcessDefinitionNotFoundException
  */
 public static String getOverviewCaseURL(
     String serverURL, long processInstanceId, FormMode formMode, ProcessAPI processAPI)
     throws ProcessDefinitionNotFoundException, ProcessInstanceNotFoundException {
   ProcessInstance processInstance = processAPI.getProcessInstance(processInstanceId);
   String formName = getProcessFormName(processInstance.getProcessDefinitionId(), processAPI);
   StringBuffer buffer = new StringBuffer(serverURL);
   buffer.append(APPLICATION_URL);
   buffer.append("?ui=form");
   buffer.append("#form=");
   buffer.append(formName);
   buffer.append("$recap&mode=");
   buffer.append(formMode.toString());
   buffer.append("&instance=");
   buffer.append(processInstanceId);
   buffer.append("&recap=true");
   return buffer.toString();
 }
  protected void executionWitherrorEventTriggered(final String catchErrorCode) throws Exception {
    final ProcessDefinition calledProcDef =
        deployAndEnableProcessWithEndThrowErrorEvent("calledProcess", "error1");
    final ProcessDefinition callerProcDef =
        deployAndEnableProcessWithBoundaryErrorEventOnCallActivity(
            "pErrorBoundary", "calledProcess", "callStep", catchErrorCode, "delivery");

    final ProcessInstance processInstance = getProcessAPI().startProcess(callerProcDef.getId());
    final FlowNodeInstance callActivity =
        waitForFlowNodeInExecutingState(processInstance, "callStep", false);
    final ActivityInstance calledStep1 = waitForUserTaskAndGetIt(processInstance, "calledStep1");
    final long calledStep2Id = waitForUserTask(processInstance, "calledStep2");
    final ProcessInstance calledProcessInstance =
        getProcessAPI().getProcessInstance(calledStep1.getParentProcessInstanceId());
    assignAndExecuteStep(calledStep1, user);

    waitForProcessToFinish(calledProcessInstance);
    try {
      waitForArchivedActivity(calledStep2Id, TestStates.ABORTED);
    } catch (final Exception e) {
      final List<ArchivedActivityInstance> archivedActivityInstances =
          getProcessAPI()
              .getArchivedActivityInstances(
                  processInstance.getId(), 0, 100, ActivityInstanceCriterion.DEFAULT);
      System.out.println("After completion of the called process");
      for (final ArchivedActivityInstance archivedActivityInstance : archivedActivityInstances) {
        System.out.println(
            "name="
                + archivedActivityInstance.getName()
                + ", state="
                + archivedActivityInstance.getState()
                + ", archivedDate="
                + archivedActivityInstance.getArchiveDate().getTime());
      }
      throw new Exception(archivedActivityInstances.toString(), e);
    }
    waitForUserTaskAndExecuteIt(processInstance, EXCEPTION_STEP, user);

    waitForProcessToFinish(processInstance);
    waitForArchivedActivity(callActivity.getId(), TestStates.ABORTED);
    checkWasntExecuted(processInstance, "step2");

    disableAndDeleteProcess(calledProcDef, callerProcDef);
  }
  /*
   * 1 receiveProcess, no message sent
   * dynamic -> deployAndEnable(receiveProcess), startProcess(receiveProcess)
   * checks : receiveProcess wait on receive task and don't and halt on the user task.
   */
  @SuppressWarnings("unchecked")
  @Cover(
      classes = {EventInstance.class, ReceiveTaskInstance.class},
      concept = BPMNConcept.EVENTS,
      keywords = {"Event", "Message event", "Receive task", "Send", "Receive"},
      jira = "")
  @Test
  public void noMessageSentSoReceiveProcessIsWaiting() throws Exception {
    final ProcessDefinition receiveMessageProcess =
        deployAndEnableProcessWithReceivedTask(
            "receiveMessageProcess",
            "waitForMessage",
            "userTask1",
            "delivery",
            user,
            "m1",
            null,
            null,
            null);

    final ProcessInstance receiveMessageProcessInstance =
        getProcessAPI().startProcess(receiveMessageProcess.getId());
    waitForFlowNodeInState(
        receiveMessageProcessInstance, "waitForMessage", TestStates.WAITING, true);

    // we check after that that the waiting event is still here
    forceMatchingOfEvents();

    final SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 10);
    searchOptionsBuilder.filter(
        WaitingEventSearchDescriptor.ROOT_PROCESS_INSTANCE_ID,
        receiveMessageProcessInstance.getId());

    final Map<String, Serializable> parameters = new HashMap<String, Serializable>(1);
    parameters.put(SEARCH_OPTIONS_KEY, searchOptionsBuilder.done());

    final SearchResult<WaitingEvent> searchResult =
        (SearchResult<WaitingEvent>)
            getCommandAPI().execute(SEARCH_WAITING_EVENTS_COMMAND, parameters);
    assertEquals(1, searchResult.getCount());

    disableAndDeleteProcess(receiveMessageProcess);
  }
  /*
   * dynamic -> deployAndEnable(receiveProcess), startProcess(receiveProcess), cancelProcessInstance(receiveProcess)
   * checks : receiveProcess wait on receive task, 1 waiting event, receiveProcess is cancelled, receiveProcess is archived, no more waiting event
   */
  @SuppressWarnings("unchecked")
  @Cover(
      classes = {EventInstance.class, ReceiveTaskInstance.class},
      concept = BPMNConcept.EVENTS,
      keywords = {"Event", "Message event", "Receive task", "Send", "Receive"},
      jira = "")
  @Test
  public void cancelInstanceShouldDeleteWaitingEvents() throws Exception {
    final ProcessDefinition receiveMessageProcess =
        deployAndEnableProcessWithReceivedTask(
            "receiveMessageProcess",
            "waitForMessage",
            "userTask1",
            "delivery",
            user,
            "m1",
            null,
            null,
            null);

    final ProcessInstance receiveMessageProcessInstance =
        getProcessAPI().startProcess(receiveMessageProcess.getId());
    waitForFlowNodeInState(
        receiveMessageProcessInstance, "waitForMessage", TestStates.WAITING, true);

    SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 10);
    searchOptionsBuilder.filter(
        WaitingEventSearchDescriptor.ROOT_PROCESS_INSTANCE_ID,
        receiveMessageProcessInstance.getId());

    final Map<String, Serializable> parameters = new HashMap<String, Serializable>(1);
    parameters.put(SEARCH_OPTIONS_KEY, searchOptionsBuilder.done());

    SearchResult<WaitingEvent> searchResult =
        (SearchResult<WaitingEvent>)
            getCommandAPI().execute(SEARCH_WAITING_EVENTS_COMMAND, parameters);
    assertEquals(1, searchResult.getCount());

    getProcessAPI().cancelProcessInstance(receiveMessageProcessInstance.getId());
    waitForProcessToBeInState(receiveMessageProcessInstance, ProcessInstanceState.CANCELLED);

    searchOptionsBuilder = new SearchOptionsBuilder(0, 10);
    searchOptionsBuilder.filter(
        ArchivedActivityInstanceSearchDescriptor.ROOT_PROCESS_INSTANCE_ID,
        receiveMessageProcessInstance.getId());
    searchOptionsBuilder.filter(
        ArchivedActivityInstanceSearchDescriptor.ACTIVITY_TYPE, FlowNodeType.RECEIVE_TASK);
    final SearchResult<ArchivedActivityInstance> archivedActivityInstancesSearch =
        getProcessAPI().searchArchivedActivities(searchOptionsBuilder.done());
    assertEquals(1, archivedActivityInstancesSearch.getCount());
    assertTrue(
        archivedActivityInstancesSearch.getResult().get(0) instanceof ArchivedReceiveTaskInstance);
    assertEquals(
        TestStates.CANCELLED.getStateName(),
        archivedActivityInstancesSearch.getResult().get(0).getState());

    searchResult =
        (SearchResult<WaitingEvent>)
            getCommandAPI().execute(SEARCH_WAITING_EVENTS_COMMAND, parameters);
    assertEquals(0, searchResult.getCount());

    disableAndDeleteProcess(receiveMessageProcess);
  }
Exemple #6
0
  @Test
  public void checkProcessCommentAreArchived() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final SCommentService commentService = tenantAccessor.getCommentService();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final ProcessDefinitionBuilder processDef =
        new ProcessDefinitionBuilder().createNewInstance("processToTestComment", "1.0");
    processDef.addStartEvent("start");
    processDef.addUserTask("step1", ACTOR_NAME);
    processDef.addEndEvent("end");
    processDef.addTransition("start", "step1");
    processDef.addTransition("step1", "end");
    processDef.addActor(ACTOR_NAME);
    final ProcessDefinition definition =
        deployAndEnableProcessWithActor(processDef.done(), ACTOR_NAME, john);
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    final Callable<Long> getNumberOfComments =
        new Callable<Long>() {

          @Override
          public Long call() throws Exception {
            return commentService.getNumberOfComments(QueryOptions.countQueryOptions());
          }
        };
    final Callable<Long> getNumberOfArchivedComments =
        new Callable<Long>() {

          @Override
          public Long call() throws Exception {
            return commentService.getNumberOfArchivedComments(QueryOptions.countQueryOptions());
          }
        };
    assertEquals(0, (long) transactionService.executeInTransaction(getNumberOfComments));
    final long numberOfInitialArchivedComments =
        transactionService.executeInTransaction(getNumberOfArchivedComments);
    final ProcessInstance processInstance = getProcessAPI().startProcess(definition.getId());
    final Long step1Id = waitForUserTask(processInstance, "step1");
    getProcessAPI().addProcessComment(processInstance.getId(), "kikoo lol");
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(1, (long) transactionService.executeInTransaction(getNumberOfComments));
    assertEquals(
        numberOfInitialArchivedComments,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    assignAndExecuteStep(step1Id, john);

    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(
        2,
        (long)
            transactionService.executeInTransaction(getNumberOfComments)); // claim add a comment...
    assertEquals(
        numberOfInitialArchivedComments,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    waitForProcessToFinish(processInstance);

    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(0, (long) transactionService.executeInTransaction(getNumberOfComments));
    assertEquals(
        numberOfInitialArchivedComments + 2,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    disableAndDeleteProcess(definition);
  }