@Test public void testGetSubprocessNextTask() throws Exception { RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI(); ManagementAPI managementAPI = AccessorUtil.getManagementAPI(); ProcessDefinition childProcess = ProcessBuilder.createProcess("child_process", "1.0") .addHuman("john") .addHumanTask("childTask", "john") .done(); ProcessDefinition parentProcess = ProcessBuilder.createProcess("parent_process", "1.0") .addHuman("john") .addSubProcess("subTask", "child_process") .addHumanTask("parentTask", "john") .addTransition("transition", "subTask", "parentTask") .done(); BusinessArchive childBusinessArchive = BusinessArchiveFactory.getBusinessArchive(childProcess); childProcess = managementAPI.deploy(childBusinessArchive); BusinessArchive parentBusinessArchive = BusinessArchiveFactory.getBusinessArchive(parentProcess); parentProcess = managementAPI.deploy(parentBusinessArchive); ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(parentProcess.getUUID()); try { IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI(); ActivityInstanceUUID activityInstanceUUID = api.getProcessInstanceNextTask(instanceUUID); Assert.assertNull(activityInstanceUUID); activityInstanceUUID = api.getRelatedProcessesNextTask(instanceUUID); Assert.assertEquals("childTask", activityInstanceUUID.getActivityName()); runtimeAPI.executeTask(activityInstanceUUID, true); activityInstanceUUID = api.getRelatedProcessesNextTask(activityInstanceUUID.getProcessInstanceUUID()); Assert.assertEquals("parentTask", activityInstanceUUID.getActivityName()); } finally { runtimeAPI.deleteProcessInstance(instanceUUID); managementAPI.deleteProcess(parentProcess.getUUID()); managementAPI.deleteProcess(childProcess.getUUID()); } }
@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()); } }