@Deployment public void testUseSignalForExceptionsBetweenParallelPaths() { runtimeService.startProcessInstanceByKey("processWithSignal"); // First task should be to select the developers Task task = taskService.createTaskQuery().singleResult(); assertEquals("Enter developers", task.getName()); taskService.complete( task.getId(), CollectionUtil.singletonMap( "developers", Arrays.asList("developerOne", "developerTwo", "developerThree"))); // Should be three distinct tasks for each developer assertEquals( "Develop specifications", taskService.createTaskQuery().taskAssignee("developerOne").singleResult().getName()); assertEquals( "Develop specifications", taskService.createTaskQuery().taskAssignee("developerTwo").singleResult().getName()); assertEquals( "Develop specifications", taskService.createTaskQuery().taskAssignee("developerThree").singleResult().getName()); // Negotiate with client is a task for kermit task = taskService.createTaskQuery().taskAssignee("kermit").singleResult(); assertEquals("Negotiate with client", task.getName()); // When the kermit task is completed, it throws a signal which should cancel the multi instance taskService.complete(task.getId(), CollectionUtil.singletonMap("negotationFailed", true)); // No tasks should be open then and process should have ended assertEquals(0, taskService.createTaskQuery().count()); assertEquals(0, runtimeService.createExecutionQuery().count()); }
@Deployment(resources = {"org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void startProcessInstanceWithBusinessKey() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // by key ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "123"); assertNotNull(processInstance); assertEquals("123", processInstance.getBusinessKey()); assertEquals( 1, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count()); // by key with variables processInstance = runtimeService.startProcessInstanceByKey( "oneTaskProcess", "456", CollectionUtil.singletonMap("var", "value")); assertNotNull(processInstance); assertEquals( 2, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count()); assertEquals("var", runtimeService.getVariable(processInstance.getId(), "var")); // by id processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), "789"); assertNotNull(processInstance); assertEquals( 3, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count()); // by id with variables processInstance = runtimeService.startProcessInstanceById( processDefinition.getId(), "101123", CollectionUtil.singletonMap("var", "value2")); assertNotNull(processInstance); assertEquals( 4, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count()); assertEquals("var", runtimeService.getVariable(processInstance.getId(), "var")); }
@Deployment public void testDeeplyNestedErrorThrown() { // Input = 1 -> error1 will be thrown, which will destroy ALL BUT ONE // subprocess, which leads to an end event, which ultimately leads to ending the process // instance String procId = runtimeService.startProcessInstanceByKey("deeplyNestedErrorThrown").getId(); Task task = taskService.createTaskQuery().singleResult(); assertEquals("Nested task", task.getName()); taskService.complete(task.getId(), CollectionUtil.singletonMap("input", 1)); assertProcessEnded(procId); // Input == 2 -> error2 will be thrown, leading to a userTask outside all subprocesses procId = runtimeService.startProcessInstanceByKey("deeplyNestedErrorThrown").getId(); task = taskService.createTaskQuery().singleResult(); assertEquals("Nested task", task.getName()); taskService.complete(task.getId(), CollectionUtil.singletonMap("input", 2)); task = taskService.createTaskQuery().singleResult(); assertEquals("task after catch", task.getName()); taskService.complete(task.getId()); assertProcessEnded(procId); }
@Deployment public void testAutoStoreVariables() { // The first script should NOT store anything as 'autoStoreVariables' is set to false String id = runtimeService .startProcessInstanceByKey( "testAutoStoreVariables", CollectionUtil.map("a", 20, "b", 22)) .getId(); assertNull(runtimeService.getVariable(id, "sum")); // The second script, after the user task will set the variable taskService.complete(taskService.createTaskQuery().singleResult().getId()); assertEquals(42, ((Number) runtimeService.getVariable(id, "sum")).intValue()); }
@Deployment public void testDeeplyNestedErrorThrownOnlyAutomaticSteps() { // input == 1 -> error2 is thrown -> caught on subprocess2 -> end event in subprocess -> proc // inst end 1 String procId = runtimeService .startProcessInstanceByKey( "deeplyNestedErrorThrown", CollectionUtil.singletonMap("input", 1)) .getId(); assertProcessEnded(procId); HistoricProcessInstance hip; if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { hip = historyService .createHistoricProcessInstanceQuery() .processInstanceId(procId) .singleResult(); assertEquals("processEnd1", hip.getEndActivityId()); } // input == 2 -> error2 is thrown -> caught on subprocess1 -> proc inst end 2 procId = runtimeService .startProcessInstanceByKey( "deeplyNestedErrorThrown", CollectionUtil.singletonMap("input", 1)) .getId(); assertProcessEnded(procId); if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { hip = historyService .createHistoricProcessInstanceQuery() .processInstanceId(procId) .singleResult(); assertEquals("processEnd1", hip.getEndActivityId()); } }