Exemplo n.º 1
0
  public void testGroovyNumber() throws Exception {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("mulitple", "1.0")
            .addHuman(getLogin())
            .addHumanTask("multi", getLogin())
            .addMultipleActivitiesInstantiator(FixedNumberInstantiator.class.getName())
            .addInputParameter("activityNumber", 10)
            .addMultipleActivitiesJoinChecker(FixedNumberJoinChecker.class.getName())
            .addInputParameter("activityNumber", 3)
            .addHumanTask("next", getLogin())
            .addTransition("multi", "next")
            .done();

    definition =
        getManagementAPI()
            .deploy(
                getBusinessArchive(
                    definition, null, FixedNumberInstantiator.class, FixedNumberJoinChecker.class));
    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(definition.getUUID());
    Collection<TaskInstance> tasks =
        getQueryRuntimeAPI().getTaskList(getLogin(), ActivityState.READY);
    assertEquals(10, tasks.size());
    Iterator<TaskInstance> iterator = tasks.iterator();
    for (int i = 0; i < 3; i++) {
      TaskInstance task = iterator.next();
      executeTask(instanceUUID, task.getActivityName());
    }
    tasks = getQueryRuntimeAPI().getTaskList(getLogin(), ActivityState.READY);
    assertEquals(1, tasks.size());
    assertEquals("next", tasks.iterator().next().getActivityName());
    getManagementAPI().deleteProcess(definition.getUUID());
  }
Exemplo n.º 2
0
  public void testSimpleTimerHumanWithConnectorOnFinish() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addStringData("var")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addConnector(Event.taskOnFinish, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "var")
            .addInputParameter("value", "human")
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 10)}")
            .addConnector(Event.onTimer, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "var")
            .addInputParameter("value", "timer")
            .addDecisionNode("join")
            .addJoinType(JoinType.AND)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process, null, SetVarConnector.class));
    final ProcessDefinitionUUID processUUID = process.getUUID();

    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    // wait the timer is executed so the connector is executed to
    Thread.sleep(2000);

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());
    getRuntimeAPI().executeTask(human.getUUID(), true);

    this.waitForInstanceEnd(5000, 10, instanceUUID);

    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    checkExecutedOnce(instanceUUID, "timer");
    checkExecutedOnce(instanceUUID, "human");

    assertEquals("human", getQueryRuntimeAPI().getProcessInstanceVariable(instanceUUID, "var"));

    getManagementAPI().deleteProcess(processUUID);
  }
Exemplo n.º 3
0
  public void testSimpleTimerHumanTask() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 1000)}")
            .addDecisionNode("join")
            .addJoinType(JoinType.AND)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());

    getRuntimeAPI().executeTask(human.getUUID(), true);

    Thread.sleep(300);
    this.waitForInstanceEnd(5000, 10, instanceUUID);
    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());
    checkExecutedOnce(instanceUUID, "human", "timer");
    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    getManagementAPI().deleteProcess(processUUID);
  }
Exemplo n.º 4
0
 @Test
 public void testExecuteActionsAndTerminate() throws Exception {
   IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
   QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
   Collection<TaskInstance> tasks =
       queryRuntimeAPI.getTaskList(processInstanceUUID, ActivityState.READY);
   for (TaskInstance activityInstance : tasks) {
     ActivityInstanceUUID uuid = activityInstance.getUUID();
     Map<String, FormFieldValue> fieldValues = new HashMap<String, FormFieldValue>();
     FormFieldValue value1 = new FormFieldValue("Excel", String.class.getName());
     fieldValues.put("fieldId1", value1);
     List<FormAction> formActions = new ArrayList<FormAction>();
     formActions.add(
         new FormAction(
             ActionType.SET_VARIABLE,
             "Applications",
             "APPLICATION",
             "field_fieldId1",
             "submitButtonId"));
     api.executeActionsAndTerminate(
         uuid,
         fieldValues,
         formActions,
         Locale.ENGLISH,
         "submitButtonId",
         new HashMap<String, Object>());
   }
   String activityId = null;
   tasks = queryRuntimeAPI.getTaskList(processInstanceUUID, ActivityState.READY);
   for (TaskInstance activityInstance : tasks) {
     activityId = activityInstance.getActivityName();
   }
   Assert.assertNotNull(activityId);
   Assert.assertEquals("Approval", activityId);
   Object variableValue =
       queryRuntimeAPI.getProcessInstanceVariable(processInstanceUUID, "Applications");
   Assert.assertEquals("Excel", variableValue.toString());
 }
Exemplo n.º 5
0
  public void testSimpleTimerXOR() throws Exception {
    final long aDay = 1 * 1000 * 60 * 60 * 24;
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addTimerTask("timer", Long.toString(aDay))
            .addDecisionNode("join")
            .addJoinType(JoinType.XOR)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process, null));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());

    executeTask(instanceUUID, "human");
    ProcessInstance instance = getQueryRuntimeAPI().getProcessInstance(instanceUUID);
    assertEquals(InstanceState.FINISHED, instance.getInstanceState());
    checkExecutedOnce(instanceUUID, "human");

    getManagementAPI().deleteProcess(processUUID);
  }
Exemplo n.º 6
0
  @Test
  public void testIterateOnSubProcess() throws Exception {
    ProcessDefinition subProcess = buildSubProcess();
    ProcessDefinition processWithSubProcess = buildIterationProcess();

    ProcessInstanceUUID processInstanceUUID =
        AccessorUtil.getRuntimeAPI().instantiateProcess(processWithSubProcess.getUUID());

    try {
      Collection<TaskInstance> taskInstances =
          AccessorUtil.getQueryRuntimeAPI().getTaskList(processInstanceUUID, ActivityState.READY);
      Assert.assertEquals(1, taskInstances.size());
      AccessorUtil.getRuntimeAPI().executeTask(taskInstances.iterator().next().getUUID(), true);

      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();

      TaskInstance subprocessTaskInstance = null;

      taskInstances = AccessorUtil.getQueryRuntimeAPI().getTaskList(ActivityState.READY);
      for (TaskInstance taskInstance : taskInstances) {
        if (subProcess.getUUID().equals(taskInstance.getProcessDefinitionUUID())) {
          subprocessTaskInstance = taskInstance;
        }
      }
      Assert.assertNotNull(subprocessTaskInstance);
      Assert.assertEquals("task1sub", subprocessTaskInstance.getActivityName());
      AccessorUtil.getRuntimeAPI().executeTask(subprocessTaskInstance.getUUID(), true);
      Assert.assertNotNull(
          api.getRelatedProcessesNextTask(subprocessTaskInstance.getProcessInstanceUUID()));

      subprocessTaskInstance = null;

      taskInstances = AccessorUtil.getQueryRuntimeAPI().getTaskList(ActivityState.READY);
      for (TaskInstance taskInstance : taskInstances) {
        if (subProcess.getUUID().equals(taskInstance.getProcessDefinitionUUID())) {
          subprocessTaskInstance = taskInstance;
        }
      }
      Assert.assertNotNull(subprocessTaskInstance);
      Assert.assertEquals("task1sub", subprocessTaskInstance.getActivityName());
      AccessorUtil.getRuntimeAPI().executeTask(subprocessTaskInstance.getUUID(), true);
      Assert.assertNotNull(
          api.getRelatedProcessesNextTask(subprocessTaskInstance.getProcessInstanceUUID()));

      subprocessTaskInstance = null;

      taskInstances = AccessorUtil.getQueryRuntimeAPI().getTaskList(ActivityState.READY);
      for (TaskInstance taskInstance : taskInstances) {
        if (subProcess.getUUID().equals(taskInstance.getProcessDefinitionUUID())) {
          subprocessTaskInstance = taskInstance;
        }
      }
      Assert.assertNotNull(subprocessTaskInstance);
      Assert.assertEquals("task1sub", subprocessTaskInstance.getActivityName());
      AccessorUtil.getRuntimeAPI()
          .setVariable(subprocessTaskInstance.getUUID(), "terminateit", true);
      AccessorUtil.getRuntimeAPI().executeTask(subprocessTaskInstance.getUUID(), true);
      Assert.assertNotNull(
          api.getRelatedProcessesNextTask(subprocessTaskInstance.getProcessInstanceUUID()));

      TaskInstance processTaskInstance = null;

      taskInstances = AccessorUtil.getQueryRuntimeAPI().getTaskList(ActivityState.READY);
      for (TaskInstance taskInstance : taskInstances) {
        if (processWithSubProcess.getUUID().equals(taskInstance.getProcessDefinitionUUID())) {
          processTaskInstance = taskInstance;
        }
      }
      Assert.assertNotNull(processTaskInstance);
      Assert.assertEquals("task2", processTaskInstance.getActivityName());
      AccessorUtil.getRuntimeAPI().executeTask(processTaskInstance.getUUID(), true);
    } finally {
      AccessorUtil.getRuntimeAPI().deleteAllProcessInstances(processWithSubProcess.getUUID());
      AccessorUtil.getRuntimeAPI().deleteAllProcessInstances(subProcess.getUUID());
      AccessorUtil.getManagementAPI().deleteProcess(processWithSubProcess.getUUID());
      AccessorUtil.getManagementAPI().deleteProcess(subProcess.getUUID());
    }
  }
Exemplo n.º 7
0
  @Test
  public void testGetSubprocessLoopNextTask() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
    QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
    IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();

    ProcessDefinition childProcess =
        ProcessBuilder.createProcess("sub_process", "1.0")
            .addIntegerData("counter")
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addConnector(Event.taskOnFinish, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "counter")
            .addInputParameter("value", "${++counter}")
            .addTransition("transition1", "task1", "task2")
            .done();

    ProcessDefinition processWithSubProcess =
        ProcessBuilder.createProcess("parent_process", "1.0")
            .addHuman("john")
            .addIntegerData("counter", 0)
            .addSubProcess("subprocess", "sub_process")
            .addSubProcessInParameter("counter", "counter")
            .addSubProcessOutParameter("counter", "counter")
            .addLoop("counter < 10", false)
            .addHumanTask("task3", "john")
            .addTransition("transition2", "subprocess", "task3")
            .done();

    BusinessArchive childBusinessArchive = BusinessArchiveFactory.getBusinessArchive(childProcess);
    childProcess = managementAPI.deploy(childBusinessArchive);

    BusinessArchive parentBusinessArchive =
        BusinessArchiveFactory.getBusinessArchive(processWithSubProcess);
    processWithSubProcess = managementAPI.deploy(parentBusinessArchive);

    ProcessInstanceUUID processInstanceUUID =
        runtimeAPI.instantiateProcess(processWithSubProcess.getUUID());

    try {
      for (int i = 0; i < 10; i++) {
        Set<ActivityInstance> activityInstances =
            queryRuntimeAPI.getActivityInstances(processInstanceUUID);
        Assert.assertEquals(i + 1, activityInstances.size());
        for (ActivityInstance activityInstance : activityInstances) {
          Assert.assertEquals("subprocess", activityInstance.getActivityName());
        }

        ProcessInstance processInstance = queryRuntimeAPI.getProcessInstance(processInstanceUUID);
        Set<ProcessInstanceUUID> childrenInstanceUUID = processInstance.getChildrenInstanceUUID();
        for (ProcessInstanceUUID childInstanceUUID : childrenInstanceUUID) {
          ProcessInstance childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
          if (InstanceState.STARTED.equals(childInstance.getInstanceState())) {
            Collection<TaskInstance> taskInstances =
                queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            TaskInstance childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task1", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            taskInstances = queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task2", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            if (i < 9) {
              ActivityInstanceUUID activityInstanceUUID =
                  api.getRelatedProcessesNextTask(childInstance.getUUID());
              Assert.assertEquals("task1", activityInstanceUUID.getActivityName());
            }

            childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
            Assert.assertEquals(InstanceState.FINISHED, childInstance.getInstanceState());
          }
        }
      }

      Collection<TaskInstance> taskInstances =
          queryRuntimeAPI.getTaskList(processInstanceUUID, ActivityState.READY);
      Assert.assertEquals(1, taskInstances.size());
      TaskInstance taskInstance = taskInstances.iterator().next();
      Assert.assertEquals("task3", taskInstance.getActivityName());
      Assert.assertEquals(ActivityState.READY, taskInstance.getState());
      runtimeAPI.executeTask(taskInstance.getUUID(), true);
    } finally {
      managementAPI.deleteProcess(processWithSubProcess.getUUID());
      managementAPI.deleteProcess(childProcess.getUUID());
    }
  }