@Test public void restartNotExistingProcessInstance() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("bar").processInstanceIds("aaa").execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Historic process instance cannot be found")); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceAsyncWithOtherTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .executeAsync(); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Cannot restart process instances of process definition '" + processInstance.getProcessDefinitionId() + "' because it belongs to no authenticated tenant.")); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceSyncWithOtherTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .execute(); fail("expected exception"); } catch (BadUserRequestException e) { // then assertThat(e.getMessage(), containsString("Historic process instance cannot be found: historicProcessInstanceId is null")); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceAsyncWithOtherTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .executeAsync(); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("processInstanceIds is empty")); } }
@Test public void restartNotExistingProcessInstance() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("bar") .processInstanceIds("aaa") .executeAsync(); helper.executeSeedJob(batch); try { helper.executeJobs(batch); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Historic process instance cannot be found")); } }
@Test public void shouldNotRestartActiveProcessInstance() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); // then thrown.expect(ProcessEngineException.class); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .initialSetOfVariables() .processInstanceIds(processInstance.getId()) .execute(); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceSyncWithTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void shouldSkipCustomListeners() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(modify(ProcessModels.TWO_TASKS_PROCESS).activityBuilder("userTask1") .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, IncrementCounterListener.class.getName()).done()); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); IncrementCounterListener.counter = 0; // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .skipCustomListeners() .execute(); // then assertEquals(0, IncrementCounterListener.counter); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceAsyncWithTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when Batch batch = runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .executeAsync(); batchHelper.completeBatch(batch); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceSyncWithTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .execute(); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void shouldNotSetInitialVersionOfVariables() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValue("var", "bar")); runtimeService.setVariable(processInstance.getId(), "bar", "foo"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .initialSetOfVariables() .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(restartedProcessInstance.getId()).list(); assertEquals(1, variables.size()); assertEquals("var", variables.get(0).getName()); assertEquals("bar", variables.get(0).getValue()); }
@Test public void restartProcessInstanceWithNotMatchingProcessDefinition() { BpmnModelInstance instance = Bpmn.createExecutableProcess("Process2").startEvent().userTask().endEvent().done(); ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessDefinition processDefinition2 = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), null); try { runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("userTask").processInstanceIds(processInstance.getId()).execute(); fail("exception expected"); } catch (ProcessEngineException e) { Assert.assertThat(e.getMessage(), containsString("Its process definition '" + processDefinition2.getId() + "' does not match given process definition '" + processDefinition.getId() +"'" )); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceAsyncWithTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when Batch batch = runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .executeAsync(); batchHelper.completeBatch(batch); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void shouldRestartProcessInstanceWithoutCaseInstanceId() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", null, "caseInstanceId"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNull(restartedProcessInstance.getCaseInstanceId()); }
@Test public void shouldRestartProcessInstanceWithoutBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", "businessKey", (String) null); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .withoutBusinessKey() .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNull(restartedProcessInstance.getBusinessKey()); }
@Test public void shouldRestartProcessInstanceWithBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", "businessKey", (String) null); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNotNull(restartedProcessInstance.getBusinessKey()); assertEquals("businessKey", restartedProcessInstance.getBusinessKey()); }
@Test public void testNoCreationOnSyncBatchJobExecution() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("user1").processInstanceIds(processInstance.getId()).executeAsync(); helper.executeSeedJob(batch); // when rule.getIdentityService().setAuthenticatedUserId("userId"); helper.executeJobs(batch); rule.getIdentityService().clearAuthentication(); // then Assert.assertEquals(0, rule.getHistoryService().createUserOperationLogQuery().count()); }
@Test public void shouldRestartProcessInstanceWithTenant() { // given ProcessDefinition processDefinition = testRule.deployForTenantAndGetDefinition("tenantId", ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNotNull(restartedProcessInstance.getTenantId()); assertEquals(processInstance.getTenantId(), restartedProcessInstance.getTenantId()); }
@Test public void shouldSkipIoMappings() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition( modify(ProcessModels.TWO_TASKS_PROCESS).activityBuilder("userTask1").camundaInputParameter("foo", "bar").done()); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .skipIoMappings() .processInstanceIds(processInstance.getId()) .execute(); // then Execution task1Execution = runtimeService.createExecutionQuery().activityId("userTask1").singleResult(); assertNotNull(task1Execution); assertNull(runtimeService.getVariable(task1Execution.getId(), "foo")); }
@Test public void shouldRestartSimpleProcessInstance() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).active().singleResult(); // process instance was deleted runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().active().singleResult(); Task restartedTask = engineRule.getTaskService().createTaskQuery().processInstanceId(restartedProcessInstance.getId()).active().singleResult(); Assert.assertEquals(task.getTaskDefinitionKey(), restartedTask.getTaskDefinitionKey()); }