private void verifyStringParameterQueryInvocations() { Map<String, String> stringQueryParameters = getCompleteStringQueryParameters(); verify(mockedQuery).processInstanceId(stringQueryParameters.get("processInstanceId")); verify(mockedQuery).variableName(stringQueryParameters.get("variableName")); verify(mockedQuery).variableValueEquals(stringQueryParameters.get("variableName"), stringQueryParameters.get("variableValue")); }
@Deployment(resources={ "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testHistoricProcessVariableOnDeletion() { HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("testVar", "Hallo Christian"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); runtimeService.deleteProcessInstance(processInstance.getId(), "deleted"); assertProcessEnded(processInstance.getId()); // check that process variable is set even if the process is canceled and not ended normally assertEquals(1, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableValueEquals("testVar", "Hallo Christian").count()); }
@Test public void deleteHistoricVariableInstancesWithAuthenticatedTenant() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); String processInstanceId = startProcessInstance(null); runtimeService.setVariable(processInstanceId, "myVariable", "testValue"); runtimeService.setVariable(processInstanceId, "myVariable", "testValue2"); HistoricVariableInstanceQuery variableQuery = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId); assertThat(variableQuery.count(), is(1L)); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); historyService.deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); assertThat(variableQuery.count(), is(0L)); cleanUpAfterVariableInstanceTest(processInstanceId); }
@Test public void deleteHistoricVariableInstanceWithAuthenticatedTenant() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); String processInstanceId = startProcessInstance(null); runtimeService.setVariable(processInstanceId, "myVariable", "testValue"); HistoricVariableInstanceQuery variableQuery = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId); assertThat(variableQuery.count(), is(1L)); String variableInstanceId = variableQuery.singleResult().getId(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); historyService.deleteHistoricVariableInstance(variableInstanceId); assertThat(variableQuery.count(), is(0L)); cleanUpAfterVariableInstanceTest(processInstanceId); }
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationTriggeredByEventSubProcessActivityRef.bpmn20.xml" }) public void testCompensateActivityRefTriggeredByEventSubprocess() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess"); assertProcessEnded(processInstance.getId()); HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("undoBookHotel"); if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) { assertEquals(1, historicVariableInstanceQuery.count()); assertEquals("undoBookHotel", historicVariableInstanceQuery.list().get(0).getVariableName()); assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue()); assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count()); } }
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationTriggeredByEventSubProcessInSubProcessActivityRef.bpmn20.xml" }) public void testCompensateActivityRefTriggeredByEventSubprocessInSubProcess() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess"); assertProcessEnded(processInstance.getId()); HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("undoBookHotel"); if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) { assertEquals(1, historicVariableInstanceQuery.count()); assertEquals("undoBookHotel", historicVariableInstanceQuery.list().get(0).getVariableName()); assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue()); assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count()); } }
@Test public void deleteHistoricVariableInstancesWithDisabledTenantCheck() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); testRule.deployForTenant(TENANT_TWO, BPMN_ONETASK_PROCESS); String processInstanceIdOne = startProcessInstance(TENANT_ONE); String processInstanceIdTwo = startProcessInstance(TENANT_TWO); runtimeService.setVariable(processInstanceIdOne, "myVariable", "testValue"); runtimeService.setVariable(processInstanceIdOne, "mySecondVariable", "testValue2"); runtimeService.setVariable(processInstanceIdTwo, "myVariable", "testValue"); runtimeService.setVariable(processInstanceIdTwo, "mySecondVariable", "testValue2"); HistoricVariableInstanceQuery variableQueryOne = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdOne); HistoricVariableInstanceQuery variableQueryTwo = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdTwo); assertThat(variableQueryOne.count(), is(2L)); assertThat(variableQueryTwo.count(), is(2L)); identityService.setAuthentication("user", null, null); processEngineConfiguration.setTenantCheckEnabled(false); historyService.deleteHistoricVariableInstancesByProcessInstanceId(processInstanceIdOne); assertThat(variableQueryOne.count(), is(0L)); assertThat(variableQueryTwo.count(), is(2L)); historyService.deleteHistoricVariableInstancesByProcessInstanceId(processInstanceIdTwo); assertThat(variableQueryTwo.count(), is(0L));; cleanUpAfterVariableInstanceTest(processInstanceIdOne, processInstanceIdTwo); }
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationInEventSubProcessActivityRef.bpmn20.xml" }) public void testCompensateActivityRefInEventSubprocess() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess"); assertProcessEnded(processInstance.getId()); HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery().variableName("undoBookSecondHotel"); if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) { assertEquals(1, historicVariableInstanceQuery.count()); assertEquals("undoBookSecondHotel", historicVariableInstanceQuery.list().get(0).getVariableName()); assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue()); assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count()); assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookHotel").count()); } }
@Test public void deleteHistoricVariableInstanceWithDisabledTenantCheck() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); testRule.deployForTenant(TENANT_TWO, BPMN_ONETASK_PROCESS); String processInstanceIdOne = startProcessInstance(TENANT_ONE); String processInstanceIdTwo = startProcessInstance(TENANT_TWO); runtimeService.setVariable(processInstanceIdOne, "myVariable", "testValue"); runtimeService.setVariable(processInstanceIdTwo, "myVariable", "testValue"); HistoricVariableInstanceQuery variableQueryOne = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdOne); HistoricVariableInstanceQuery variableQueryTwo = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdTwo); assertThat(variableQueryOne.count(), is(1L)); assertThat(variableQueryTwo.count(), is(1L)); String variableInstanceIdOne = variableQueryOne.singleResult().getId(); String variableInstanceIdTwo = variableQueryTwo.singleResult().getId(); identityService.setAuthentication("user", null, null); processEngineConfiguration.setTenantCheckEnabled(false); historyService.deleteHistoricVariableInstance(variableInstanceIdOne); historyService.deleteHistoricVariableInstance(variableInstanceIdTwo); assertThat(variableQueryOne.count(), is(0L)); assertThat(variableQueryTwo.count(), is(0L));; cleanUpAfterVariableInstanceTest(processInstanceIdOne, processInstanceIdTwo); }
@Test public void testDeployProcessArchive() { // the process can successfully be executed ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess"); HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery() .processInstanceId(pi.getId()) .singleResult(); assertNotNull(variable); assertEquals("executed", variable.getName()); assertEquals(true, variable.getValue()); }
@Deployment(resources={ "org/camunda/bpm/engine/test/api/oneTaskProcessWithIoMappings.bpmn20.xml" }) @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) @Test public void testDeleteProcessInstanceSkipIoMappings() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("ioMappingProcess"); // when the process instance is deleted and we do skip the io mappings runtimeService.deleteProcessInstance(instance.getId(), null, false, true, true); // then testRule.assertProcessEnded(instance.getId()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list().size()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("inputMappingExecuted").count()); }
@Test public void failToDeleteHistoricVariableInstanceNoAuthenticatedTenants() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); String processInstanceId = startProcessInstance(null); runtimeService.setVariable(processInstanceId, "myVariable", "testValue"); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).singleResult().getId(); identityService.setAuthentication("user", null, null); thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot delete the historic variable instance '" + variableInstanceId + "' because it belongs to no authenticated tenant."); try { historyService.deleteHistoricVariableInstance(variableInstanceId); } finally { cleanUpAfterVariableInstanceTest(processInstanceId); } }
@Deployment public void testMultipleAsyncEndEvents() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("multipleAsyncEndEvent"); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); // should stop at both end events List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list(); assertEquals(2, jobs.size()); // execute one of the end events managementService.executeJob(jobs.get(0).getId()); jobs = managementService.createJobQuery().withRetriesLeft().list(); assertEquals(1, jobs.size()); // execute the second one managementService.executeJob(jobs.get(0).getId()); // assert that we have finished our instance now assertEquals(0, runtimeService.createProcessInstanceQuery().count()); if(processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // after the end event we have a event listener HistoricVariableInstanceQuery name = historyService.createHistoricVariableInstanceQuery() .processInstanceId(pi.getId()) .variableName("message"); Assert.assertNotNull(name); Assert.assertEquals(true, name.singleResult().getValue()); } }
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testCascadingDeleteSubprocessInstanceSkipIoMappings.Calling.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testCascadingDeleteSubprocessInstanceSkipIoMappings.Called.bpmn20.xml" }) @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) @Test public void testCascadingDeleteSubprocessInstanceSkipIoMappings() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("callingProcess"); ProcessInstance instance2 = runtimeService.createProcessInstanceQuery().superProcessInstanceId(instance.getId()).singleResult(); // when the process instance is deleted and we do skip the io mappings runtimeService.deleteProcessInstance(instance.getId(), "test_purposes", false, true, true); // then testRule.assertProcessEnded(instance.getId()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().processInstanceId(instance2.getId()).list().size()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("inputMappingExecuted").count()); }
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcessWithIoMappings.bpmn20.xml" }) @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) @Test public void testDeleteProcessInstanceWithoutSkipIoMappings() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("ioMappingProcess"); // when the process instance is deleted and we do not skip the io mappings runtimeService.deleteProcessInstance(instance.getId(), null, false, true, false); // then testRule.assertProcessEnded(instance.getId()); assertEquals(2, historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list().size()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("inputMappingExecuted").count()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("outputMappingExecuted").count()); }
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testCascadingDeleteSubprocessInstanceSkipIoMappings.Calling.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testCascadingDeleteSubprocessInstanceSkipIoMappings.Called.bpmn20.xml" }) @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) @Test public void testCascadingDeleteSubprocessInstanceWithoutSkipIoMappings() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("callingProcess"); ProcessInstance instance2 = runtimeService.createProcessInstanceQuery().superProcessInstanceId(instance.getId()).singleResult(); // when the process instance is deleted and we do not skip the io mappings runtimeService.deleteProcessInstance(instance.getId(), "test_purposes", false, true, false); // then testRule.assertProcessEnded(instance.getId()); assertEquals(2, historyService.createHistoricVariableInstanceQuery().processInstanceId(instance2.getId()).list().size()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("inputMappingExecuted").count()); assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("outputMappingExecuted").count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryByProcessInstanceIdAndVariableId() { // given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("initial", "bar")); VariableInstance variable = runtimeService.createVariableInstanceQuery().variableName("initial").singleResult(); assertNotNull(variable); // when HistoricVariableInstance historyVariable = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()) .variableId(variable.getId()) .singleResult(); // then assertNotNull(historyVariable); assertEquals("initial", historyVariable.getName()); assertEquals("bar", historyVariable.getValue()); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) @Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testDeleteAllHistoricVariablesOnEmpty() { // given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS); String executionId = processInstance.getId(); assertEquals(1L, runtimeService.createProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count()); runtimeService.deleteProcessInstance(executionId, null); assertEquals(0L, runtimeService.createProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count()); assertEquals(1L, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count()); HistoricVariableInstanceQuery histVariableQuery = historyService.createHistoricVariableInstanceQuery().processInstanceId(executionId); assertEquals(0L, histVariableQuery.count()); HistoricDetailQuery detailsQuery = historyService.createHistoricDetailQuery().processInstanceId(executionId); assertEquals(0L, detailsQuery.count()); // when historyService.deleteHistoricVariableInstancesByProcessInstanceId(executionId); // then assertEquals(0, histVariableQuery.count()); assertEquals(0, detailsQuery.count()); }
@Deployment public void testAsyncEndEventListeners() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("asyncEndEvent"); long count = runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).active().count(); Assert.assertNull(runtimeService.getVariable(pi.getId(), "listener")); Assert.assertEquals(1, runtimeService.createExecutionQuery().activityId("endEvent").count()); Assert.assertEquals(1, count); // as we are standing at the end event, we execute it. executeAvailableJobs(); count = runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).active().count(); Assert.assertEquals(0, count); if(processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // after the end event we have a event listener HistoricVariableInstanceQuery name = historyService.createHistoricVariableInstanceQuery() .processInstanceId(pi.getId()) .variableName("listener"); Assert.assertNotNull(name); Assert.assertEquals("listener invoked", name.singleResult().getValue()); } }
.processInstanceId(executionId) .variableName("myVariable"); assertEquals(1, histVariableQuery.count());