public static HistoricVariableInstanceDto fromHistoricVariableInstance(HistoricVariableInstance historicVariableInstance) { HistoricVariableInstanceDto dto = new HistoricVariableInstanceDto(); dto.id = historicVariableInstance.getId(); dto.name = historicVariableInstance.getName(); dto.processDefinitionKey = historicVariableInstance.getProcessDefinitionKey(); dto.processDefinitionId = historicVariableInstance.getProcessDefinitionId(); dto.processInstanceId = historicVariableInstance.getProcessInstanceId(); dto.executionId = historicVariableInstance.getExecutionId(); dto.activityInstanceId = historicVariableInstance.getActivityInstanceId(); dto.caseDefinitionKey = historicVariableInstance.getCaseDefinitionKey(); dto.caseDefinitionId = historicVariableInstance.getCaseDefinitionId(); dto.caseInstanceId = historicVariableInstance.getCaseInstanceId(); dto.caseExecutionId = historicVariableInstance.getCaseExecutionId(); dto.taskId = historicVariableInstance.getTaskId(); dto.tenantId = historicVariableInstance.getTenantId(); dto.state = historicVariableInstance.getState(); dto.createTime = historicVariableInstance.getCreateTime(); dto.removalTime = historicVariableInstance.getRemovalTime(); dto.rootProcessInstanceId = historicVariableInstance.getRootProcessInstanceId(); if(historicVariableInstance.getErrorMessage() == null) { VariableValueDto.fromTypedValue(dto, historicVariableInstance.getTypedValue()); } else { dto.errorMessage = historicVariableInstance.getErrorMessage(); dto.type = VariableValueDto.toRestApiTypeName(historicVariableInstance.getTypeName()); } return dto; }
public HistoricVariableInstance build() { HistoricVariableInstance mockVariable = mock(HistoricVariableInstance.class); when(mockVariable.getId()).thenReturn(id); when(mockVariable.getName()).thenReturn(name); when(mockVariable.getVariableName()).thenReturn(name); when(mockVariable.getTypeName()).thenReturn(value.getType().getName()); when(mockVariable.getVariableTypeName()).thenReturn(value.getType().getName()); when(mockVariable.getValue()).thenReturn(value.getValue()); } else { when(mockVariable.getValue()).thenReturn(null); when(mockVariable.getValue()).thenReturn(value.getValue()); when(mockVariable.getTypedValue()).thenReturn(value); when(mockVariable.getProcessDefinitionKey()).thenReturn(processDefinitionKey); when(mockVariable.getProcessDefinitionId()).thenReturn(processDefinitionId); when(mockVariable.getProcessInstanceId()).thenReturn(processInstanceId); when(mockVariable.getExecutionId()).thenReturn(executionId); when(mockVariable.getErrorMessage()).thenReturn(errorMessage); when(mockVariable.getActivtyInstanceId()).thenReturn(activityInstanceId); when(mockVariable.getActivityInstanceId()).thenReturn(activityInstanceId); when(mockVariable.getCaseDefinitionKey()).thenReturn(caseDefinitionKey); when(mockVariable.getCaseDefinitionId()).thenReturn(caseDefinitionId); when(mockVariable.getCaseInstanceId()).thenReturn(caseInstanceId); when(mockVariable.getCaseExecutionId()).thenReturn(caseExecutionId); when(mockVariable.getTaskId()).thenReturn(taskId); when(mockVariable.getTenantId()).thenReturn(tenantId); when(mockVariable.getCreateTime()).thenReturn(createTime); when(mockVariable.getRemovalTime()).thenReturn(removalTime);
protected void assertCaseVariable(String key, CaseInstance caseInstance, HistoricVariableInstance instance) { assertNotNull(instance.getCaseDefinitionKey()); assertEquals(key, instance.getCaseDefinitionKey()); assertNotNull(instance.getCaseDefinitionId()); assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId()); assertNull(instance.getProcessDefinitionKey()); assertNull(instance.getProcessDefinitionId()); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testHistoricVariableInstanceForSingleActivityInstantiation() { // when ProcessInstance instance = runtimeService .createProcessInstanceByKey("exclusiveGateway") .startBeforeActivity("task1") .setVariable("aVar", "aValue") .execute(); ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId()); // then HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery() .variableName("aVar") .singleResult(); assertNotNull(historicVariable); assertEquals(instance.getId(), historicVariable.getProcessInstanceId()); assertEquals(activityInstance.getId(), historicVariable.getActivityInstanceId()); assertEquals("aVar", historicVariable.getName()); assertEquals("aValue", historicVariable.getValue()); HistoricDetail historicDetail = historyService.createHistoricDetailQuery() .variableInstanceId(historicVariable.getId()).singleResult(); assertEquals(instance.getId(), historicDetail.getProcessInstanceId()); assertNotNull(historicDetail); // TODO: fix if this is not ok due to CAM-3886 assertNull(historicDetail.getActivityInstanceId()); assertTrue(historicDetail instanceof HistoricVariableUpdate); assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName()); assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testNativeHistoricVariableInstanceTest() { Date date = Calendar.getInstance().getTime(); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("stringVar", "abcdef"); vars.put("dateVar", date); runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, vars); assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricVariableInstance.class)).count()); assertEquals(1, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).listPage(0, 1).size()); List<HistoricVariableInstance> variables = historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).list(); assertEquals(2, variables.size()); for (HistoricVariableInstance variable : variables) { assertTrue(vars.containsKey(variable.getName())); assertEquals(vars.get(variable.getName()), variable.getValue()); vars.remove(variable.getName()); } }
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; }
assertEquals("process", historicProcessVariable.getVariableName()); assertEquals("one", historicProcessVariable.getValue()); assertEquals(ValueType.STRING.getName(), historicProcessVariable.getVariableTypeName()); assertEquals(ValueType.STRING.getName(), historicProcessVariable.getTypeName()); assertEquals(historicProcessVariable.getValue(), historicProcessVariable.getTypedValue().getValue()); assertEquals(historicProcessVariable.getTypeName(), historicProcessVariable.getTypedValue().getType().getName());
assertNotNull(fileVariableInstance.getValue()); assertEquals("fileVar", fileVariableInstance.getName()); assertNull(fileVariableInstance.getValue()); FileValue typedValue = (FileValue) fileVariableInstance.getTypedValue(); assertNull(typedValue.getValue());
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testQueryByVariableTypeIn() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("boolVar", true); runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); // when HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery().variableTypeIn("string"); // then assertEquals(1, query.list().size()); assertEquals(1, query.count()); assertEquals(query.list().get(0).getName(), "stringVar"); }
@Test @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT) public void testMigrateHistoryVariableInstance() { //given ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS) .changeElementId(ProcessModels.PROCESS_KEY, "new" + ProcessModels.PROCESS_KEY)); ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceDefinition.getId()); runtimeService.setVariable(processInstance.getId(), "test", 3537); HistoricVariableInstance instance = historyService.createHistoricVariableInstanceQuery().singleResult(); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities("userTask", "userTask") .build(); //when runtimeService.newMigration(migrationPlan) .processInstanceIds(Arrays.asList(processInstance.getId())) .execute(); //then HistoricVariableInstance migratedInstance = historyService.createHistoricVariableInstanceQuery().singleResult(); assertEquals(targetDefinition.getKey(), migratedInstance.getProcessDefinitionKey()); assertEquals(targetDefinition.getId(), migratedInstance.getProcessDefinitionId()); assertEquals(instance.getActivityInstanceId(), migratedInstance.getActivityInstanceId()); assertEquals(instance.getExecutionId(), migratedInstance.getExecutionId()); }
public void testDisableCustomObjectDeserialization() { // given Task newTask = taskService.newTask(); taskService.saveTask(newTask); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("customSerializable", new CustomSerializable()); variables.put("failingSerializable", new FailingSerializable()); taskService.setVariables(newTask.getId(), variables); // when List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery() .disableCustomObjectDeserialization() .list(); // then assertEquals(2, variableInstances.size()); for (HistoricVariableInstance variableInstance : variableInstances) { assertNull(variableInstance.getErrorMessage()); ObjectValue typedValue = (ObjectValue) variableInstance.getTypedValue(); assertNotNull(typedValue); assertFalse(typedValue.isDeserialized()); // cannot access the deserialized value try { typedValue.getValue(); } catch(IllegalStateException e) { assertTextPresent("Object is not deserialized", e.getMessage()); } assertNotNull(typedValue.getValueSerialized()); } taskService.deleteTask(newTask.getId(), true); }
assertEquals("aVariable", historicVariable.getVariableName()); assertEquals("updated value", historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("bVariable", historicVariable.getVariableName()); assertEquals(123, historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("cVariable", historicVariable.getVariableName()); assertEquals(12345L, historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("dVariable", historicVariable.getVariableName()); assertEquals(1234.567, historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("eVariable", historicVariable.getVariableName()); assertEquals((short) 12, historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("fVariable", historicVariable.getVariableName()); assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("gVariable", historicVariable.getVariableName()); assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue()); assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId()); assertEquals("hVariable", historicVariable.getVariableName());
/** * enable test case when bug is fixed * * @see https://app.camunda.com/jira/browse/CAM-4304 */ @Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationInEventSubProcess.bpmn20.xml" }) public void testCompensateInEventSubprocess() { 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()); historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery().variableName("undoBookFlight"); assertEquals(1, historicVariableInstanceQuery.count()); assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue()); historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery().variableName("undoBookHotel"); assertEquals(1, historicVariableInstanceQuery.count()); assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue()); } }
@Override protected TypedValue transformQueryResultIntoTypedValue(HistoricVariableInstance queryResult) { return queryResult.getTypedValue(); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml"}) public void testQueryNotIncludeDeleted() { //given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksProcess", Variables.createVariables().putValue("initial", "foo")); Task task = taskService.createTaskQuery().singleResult(); taskService.setVariables(task.getId(), Variables.createVariables().putValue("bar", "abc")); taskService.complete(task.getId()); //when runtimeService.removeVariable(processInstance.getId(), "bar"); //then HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertEquals(HistoricVariableInstance.STATE_CREATED, variable.getState()); assertEquals("initial", variable.getName()); assertEquals("foo", variable.getValue()); }
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); }
@Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testSetVariableOnProcessIntanceStartAndSetVariableLocalOnUserTask() { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("testVar", "testValue"); ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); taskService.setVariableLocal(task.getId(), "testVar", "anotherTestValue"); ExecutionEntity taskExecution = (ExecutionEntity) runtimeService.createExecutionQuery().singleResult(); assertNotNull(taskExecution); HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(2, query.count()); List<HistoricVariableInstance> result = query.list(); HistoricVariableInstance firstVar = result.get(0); assertEquals("testVar", firstVar.getVariableName()); assertEquals("testValue", firstVar.getValue()); // the variable is in the process instance scope assertEquals(pi.getId(), firstVar.getActivityInstanceId()); HistoricVariableInstance secondVar = result.get(1); assertEquals("testVar", secondVar.getVariableName()); assertEquals("anotherTestValue", secondVar.getValue()); // the variable is in the task scope assertEquals(taskExecution.getActivityInstanceId(), secondVar.getActivityInstanceId()); taskService.complete(task.getId()); assertProcessEnded(pi.getId()); }
public void testErrorMessage() { Task newTask = taskService.newTask(); taskService.saveTask(newTask); String variableName = "failingSerializable"; taskService.setVariable(newTask.getId(), variableName, new FailingSerializable()); HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() .variableName(variableName) .singleResult(); assertNull(variableInstance.getValue()); assertNotNull(variableInstance.getErrorMessage()); taskService.deleteTask(newTask.getId(), true); }
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 testAsyncStartEventWithAddedVariable() { // given a process definition with asynchronous start event deployment(Bpmn.createExecutableProcess("testProcess") .startEvent() .camundaAsyncBefore() .endEvent() .done()); // when create an instance with a variable ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", Variables.putValue("var1", "foo")); // and add a variable before the instance is created runtimeService.setVariable(processInstance.getId(), "var2", "bar"); executeAvailableJobs(); assertProcessEnded(processInstance.getId()); if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // then the history contains one entry for each variable HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(query.count(), 2); HistoricVariableInstance firstVariable = query.variableName("var1").singleResult(); assertNotNull(firstVariable); assertEquals(firstVariable.getValue(), "foo"); assertNotNull(firstVariable.getActivityInstanceId()); HistoricVariableInstance secondVariable = query.variableName("var2").singleResult(); assertNotNull(secondVariable); assertEquals(secondVariable.getValue(), "bar"); assertNotNull(secondVariable.getActivityInstanceId()); } }