@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()); } }
@Override protected void applyFilters(HistoricVariableInstanceQuery query) { if (processInstanceId != null) { query.processInstanceId(processInstanceId); query.processDefinitionId(processDefinitionId); query.processDefinitionKey(processDefinitionKey); query.caseInstanceId(caseInstanceId); query.variableName(variableName); query.variableNameLike(variableNameLike); query.variableValueEquals(variableName, variableValue); } else { throw new InvalidRequestException(Status.BAD_REQUEST, query.variableTypeIn(variableTypeIn); query.executionIdIn(executionIdIn); query.taskIdIn(taskIdIn); query.processInstanceIdIn(processInstanceIdIn); query.activityInstanceIdIn(activityInstanceIdIn); query.caseExecutionIdIn(caseExecutionIdIn);
@Override public List<HistoricVariableInstanceDto> queryHistoricVariableInstances(HistoricVariableInstanceQueryDto queryDto, Integer firstResult, Integer maxResults, boolean deserializeObjectValues) { queryDto.setObjectMapper(objectMapper); HistoricVariableInstanceQuery query = queryDto.toQuery(processEngine); query.disableBinaryFetching(); if (!deserializeObjectValues) { query.disableCustomObjectDeserialization(); } List<HistoricVariableInstance> matchingHistoricVariableInstances; if (firstResult != null || maxResults != null) { matchingHistoricVariableInstances = executePaginatedQuery(query, firstResult, maxResults); } else { matchingHistoricVariableInstances = query.list(); } List<HistoricVariableInstanceDto> historicVariableInstanceDtoResults = new ArrayList<HistoricVariableInstanceDto>(); for (HistoricVariableInstance historicVariableInstance : matchingHistoricVariableInstances) { HistoricVariableInstanceDto resultHistoricVariableInstance = HistoricVariableInstanceDto.fromHistoricVariableInstance(historicVariableInstance); historicVariableInstanceDtoResults.add(resultHistoricVariableInstance); } return historicVariableInstanceDtoResults; }
@Override protected Query<HistoricVariableInstanceQuery, HistoricVariableInstance> baseQueryForVariable(boolean deserializeObjectValue) { HistoricVariableInstanceQuery query = baseQuery().disableBinaryFetching(); if (!deserializeObjectValue) { query.disableCustomObjectDeserialization(); } return query; }
@Test public void testGetNonExistingVariableInstance() { String nonExistingId = "nonExistingId"; when(variableInstanceQueryMock.variableId(nonExistingId)).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.singleResult()).thenReturn(null); given().pathParam("id", nonExistingId) .then().expect().statusCode(Status.NOT_FOUND.getStatusCode()) .body(containsString("Historic variable instance with Id 'nonExistingId' does not exist.")) .when().get(VARIABLE_INSTANCE_URL); verify(variableInstanceQueryMock, times(1)).disableBinaryFetching(); }
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testHistoricVariableInstanceQueryByExecutionIds() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("myVar", "test123"); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery().executionIdIn(processInstance1.getId()); assertEquals(2, query.count()); List<HistoricVariableInstance> variableInstances = query.list(); assertEquals(2, variableInstances.size()); for (HistoricVariableInstance variableInstance : variableInstances) { assertEquals(processInstance1.getId(), variableInstance.getExecutionId()); } Map<String, Object> variables2 = new HashMap<String, Object>(); variables2.put("myVar", "test123"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2); query = historyService.createHistoricVariableInstanceQuery().executionIdIn(processInstance1.getId(), processInstance2.getId()); assertEquals(3, query.list().size()); assertEquals(3, query.count()); }
protected VariableMap collectLastVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery() .executionIdIn(processInstance.getId()) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricVariableInstance variable : historicVariables) { variables.putValueTyped(variable.getName(), variable.getTypedValue()); } return variables; }
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testQueryByActivityInstanceIdIn() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("myVar", "test123"); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); query.activityInstanceIdIn(processInstance1.getId()); assertEquals(2, query.list().size()); assertEquals(2, query.count()); Map<String, Object> variables2 = new HashMap<String, Object>(); variables2.put("myVar", "test123"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2); query.activityInstanceIdIn(processInstance1.getId(), processInstance2.getId()); assertEquals(3, query.list().size()); assertEquals(3, query.count()); }
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")); }
.caseInstanceId(caseInstanceId) .variableName("aVariable") .singleResult(); .caseInstanceId(caseInstanceId) .variableName("aLocalVariable") .singleResult(); .caseInstanceId(caseInstanceId) .variableId(variable.getId()) .singleResult();
public void testQueryByTenantId() { HistoricVariableInstanceQuery query = historyService .createHistoricVariableInstanceQuery() .tenantIdIn(TENANT_ONE); assertThat(query.count(), is(1L)); assertEquals(query.list().get(0).getValue(), TENANT_ONE_VAR); query = historyService .createHistoricVariableInstanceQuery() .tenantIdIn(TENANT_TWO); assertThat(query.count(), is(1L)); assertEquals(query.list().get(0).getValue(), TENANT_TWO_VAR); }
@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/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()); }
public void testQuerySortingAsc() { List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery() .orderByTenantId() .asc() .list(); assertThat(historicVariableInstances.size(), is(2)); assertThat(historicVariableInstances.get(0).getTenantId(), is(TENANT_ONE)); assertEquals(historicVariableInstances.get(0).getValue(), TENANT_ONE_VAR); assertThat(historicVariableInstances.get(1).getTenantId(), is(TENANT_TWO)); assertEquals(historicVariableInstances.get(1).getValue(), TENANT_TWO_VAR); }
public void testQuerySortingDesc() { List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery() .orderByTenantId() .desc() .list(); assertThat(historicVariableInstances.size(), is(2)); assertThat(historicVariableInstances.get(0).getTenantId(), is(TENANT_TWO)); assertEquals(historicVariableInstances.get(0).getValue(), TENANT_TWO_VAR); assertThat(historicVariableInstances.get(1).getTenantId(), is(TENANT_ONE)); assertEquals(historicVariableInstances.get(1).getValue(), TENANT_ONE_VAR); }
HistoricVariableInstance eventScopeVariable = historyService .createHistoricVariableInstanceQuery() .executionIdIn(eventScopeExecution.getId()) .singleResult(); .variableId(eventScopeVariable.getId()) .singleResult(); Assert.assertEquals(targetDefinition.getId(), historicVariableInstance.getProcessDefinitionId());
private void createHistoricVariableInstanceMock() { List<HistoricVariableInstance> variables = new ArrayList<HistoricVariableInstance>(); HistoricVariableInstance mockInstance = MockProvider.createMockHistoricVariableInstance(); variables.add(mockInstance); HistoricVariableInstanceQuery mockHistoricVariableInstanceQuery = mock(HistoricVariableInstanceQuery.class); when(mockHistoricVariableInstanceQuery.list()).thenReturn(variables); when(mockHistoryService.createHistoricVariableInstanceQuery()).thenReturn(mockHistoricVariableInstanceQuery); }
public void execute(DelegateExecution execution) throws Exception { HistoryService historyService = execution.getProcessEngineServices().getHistoryService(); HistoricVariableInstance variableInstance = historyService .createHistoricVariableInstanceQuery() .variableName("listVar") .singleResult(); List<String> list = (List<String>) variableInstance.getValue(); // implicit update of the list, should not trigger an update // of the value since we deal with historic variables list.add(NEW_ELEMENT); }
private HistoricVariableInstanceQuery setUpMockHistoricVariableInstanceQuery(List<HistoricVariableInstance> mockedHistoricVariableInstances) { HistoricVariableInstanceQuery mockedHistoricVariableInstanceQuery = mock(HistoricVariableInstanceQuery.class); when(mockedHistoricVariableInstanceQuery.list()).thenReturn(mockedHistoricVariableInstances); when(mockedHistoricVariableInstanceQuery.count()).thenReturn((long) mockedHistoricVariableInstances.size()); when(processEngine.getHistoryService().createHistoricVariableInstanceQuery()).thenReturn(mockedHistoricVariableInstanceQuery); return mockedHistoricVariableInstanceQuery; }
@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); }