private void assertThatUpdateHasAllImportantInformation(HistoricVariableUpdate variableUpdate) { assertThat(variableUpdate, notNullValue()); assertThat(variableUpdate.getId(), notNullValue()); assertThat(variableUpdate.getProcessDefinitionKey(), is("process")); assertThat(variableUpdate.getProcessDefinitionId(), notNullValue()); assertThat(variableUpdate.getVariableName(), is("stringVar")); assertThat(variableUpdate.getValue().toString(), is("foo")); assertThat(variableUpdate.getTypeName(), is("string")); assertThat(variableUpdate.getTime(), notNullValue()); }
assertThat(variableUpdates.get(0).getVariableName(), is("var1")); assertThat(variableUpdates.get(1).getVariableName(), is("var2")); assertThat(variableUpdates.get(2).getVariableName(), is("var3"));
public HistoricVariableUpdate build() { HistoricVariableUpdate mockVariable = mock(HistoricVariableUpdate.class); when(mockVariable.getId()).thenReturn(id); when(mockVariable.getVariableName()).thenReturn(name); when(mockVariable.getVariableInstanceId()).thenReturn(variableInstanceId); when(mockVariable.getVariableTypeName()).thenReturn(typedValue.getType().getName());
protected static void fromHistoricVariableUpdate(HistoricVariableUpdateDto dto, HistoricVariableUpdate historicVariableUpdate) { dto.revision = historicVariableUpdate.getRevision(); dto.variableName = historicVariableUpdate.getVariableName(); dto.variableInstanceId = historicVariableUpdate.getVariableInstanceId(); if (historicVariableUpdate.getErrorMessage() == null) { try { VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(historicVariableUpdate.getTypedValue()); dto.value = variableValueDto.getValue(); dto.variableType = variableValueDto.getType(); dto.valueInfo = variableValueDto.getValueInfo(); } catch (RuntimeException e) { dto.errorMessage = e.getMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } } else { dto.errorMessage = historicVariableUpdate.getErrorMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } }
protected static void fromHistoricVariableUpdate(HistoricVariableUpdateDto dto, HistoricVariableUpdate historicVariableUpdate) { dto.revision = historicVariableUpdate.getRevision(); dto.variableName = historicVariableUpdate.getVariableName(); dto.variableInstanceId = historicVariableUpdate.getVariableInstanceId(); if (historicVariableUpdate.getErrorMessage() == null) { try { VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(historicVariableUpdate.getTypedValue()); dto.value = variableValueDto.getValue(); dto.variableType = variableValueDto.getType(); dto.valueInfo = variableValueDto.getValueInfo(); } catch (RuntimeException e) { dto.errorMessage = e.getMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } } else { dto.errorMessage = historicVariableUpdate.getErrorMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } }
@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricVariableInstanceTest.testImplicitVariableUpdate.bpmn20.xml") public void testImplicitVariableRemoveAndUpdateInOneTransaction() { // given runtimeService.startProcessInstanceByKey("serviceTaskProcess", Variables.createVariables() .putValue("listVar", new ArrayList<String>()) .putValue("delegate", new RemoveAndUpdateValueDelegate())); if (isFullHistoryEnabled()) { List<HistoricDetail> historicDetails = historyService .createHistoricDetailQuery() .variableUpdates() .orderPartiallyByOccurrence().asc() .list(); Iterator<HistoricDetail> detailsIt = historicDetails.iterator(); while(detailsIt.hasNext()) { if (!"listVar".equals(((HistoricVariableUpdate) detailsIt.next()).getVariableName())) { detailsIt.remove(); } } // one for creation, one for deletion, none for update assertEquals(2, historicDetails.size()); HistoricVariableUpdate update1 = (HistoricVariableUpdate) historicDetails.get(0); List<String> value1 = (List<String>) update1.getValue(); assertNotNull(value1); assertTrue(value1.isEmpty()); HistoricVariableUpdate update2 = (HistoricVariableUpdate) historicDetails.get(1); assertNull(update2.getValue()); } }
@Test @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 HistoricDetailQuery query = historyService.createHistoricDetailQuery() .variableTypeIn("string"); // then assertEquals(1, query.list().size()); assertEquals(1, query.count()); HistoricDetail historicDetail = query.list().get(0); if (historicDetail instanceof HistoricVariableUpdate) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicDetail; assertEquals(variableUpdate.getVariableName(), "stringVar"); assertEquals(variableUpdate.getTypeName(), "string"); } else { fail("Historic detail should be a variable update!"); } }
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testQueryByVariableTypeInWithCapitalLetter() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("boolVar", true); runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); // when HistoricDetailQuery query = historyService.createHistoricDetailQuery() .variableTypeIn("Boolean"); // then assertEquals(1, query.list().size()); assertEquals(1, query.count()); HistoricDetail historicDetail = query.list().get(0); if (historicDetail instanceof HistoricVariableUpdate) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicDetail; assertEquals(variableUpdate.getVariableName(), "boolVar"); assertEquals(variableUpdate.getTypeName(), "boolean"); } else { fail("Historic detail should be a variable update!"); } }
assertEquals("variable1", varUpdate1.getVariableName()); assertEquals("activiti rocks!", varUpdate1.getValue()); assertEquals("variable2", varUpdate2.getVariableName()); assertEquals(12345L, varUpdate2.getValue());
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance); HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery() .variableUpdates() .executionId(processInstance.getId()) .activityInstanceId(startActivityInstance.getId()); List<HistoricDetail> historicDetails = query .sequenceCounter(1) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricDetail detail : historicDetails) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail; variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue()); } return variables; }
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance); HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery() .variableUpdates() .executionId(processInstance.getId()) .activityInstanceId(startActivityInstance.getId()); List<HistoricDetail> historicDetails = query .sequenceCounter(1) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricDetail detail : historicDetails) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail; variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue()); } return variables; }
assertEquals("bytes", historicVariableUpdate.getVariableName()); assertEquals(":-(", new String((byte[])historicVariableUpdate.getValue())); assertEquals(0, historicVariableUpdate.getRevision()); assertEquals("bytes", historicVariableUpdate.getVariableName()); assertEquals(":-)", new String((byte[])historicVariableUpdate.getValue())); assertEquals(1, historicVariableUpdate.getRevision()); assertEquals("character", historicVariableUpdate.getVariableName()); assertEquals("a", historicVariableUpdate.getValue()); assertEquals(0, historicVariableUpdate.getRevision()); assertEquals("number", historicVariableUpdate.getVariableName()); assertEquals("one", historicVariableUpdate.getValue()); assertEquals(0, historicVariableUpdate.getRevision()); assertEquals("number", historicVariableUpdate.getVariableName()); assertEquals("two", historicVariableUpdate.getValue()); assertEquals(1, historicVariableUpdate.getRevision()); assertEquals("zVar1", historicVariableUpdate.getVariableName()); assertEquals("Event: start", historicVariableUpdate.getValue()); assertEquals(0, historicVariableUpdate.getRevision()); assertEquals("zVar2", historicVariableUpdate.getVariableName()); assertEquals("Event: take", historicVariableUpdate.getValue()); assertEquals(0, historicVariableUpdate.getRevision()); assertEquals("zVar3", historicVariableUpdate.getVariableName());
assertEquals("aVariable", startVarUpdate.getVariableName()); assertEquals("initial value", startVarUpdate.getValue()); assertEquals(0, startVarUpdate.getRevision()); assertEquals("aVariable", updatedStringVariable.getVariableName()); assertEquals("updated value", updatedStringVariable.getValue()); assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId()); assertEquals("bVariable", intVariable.getVariableName()); assertEquals(123, intVariable.getValue()); assertEquals(processInstance.getId(), intVariable.getProcessInstanceId()); assertEquals("cVariable", longVariable.getVariableName()); assertEquals(12345L, longVariable.getValue()); assertEquals(processInstance.getId(), longVariable.getProcessInstanceId()); assertEquals("dVariable", doubleVariable.getVariableName()); assertEquals(1234.567, doubleVariable.getValue()); assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId()); assertEquals("eVariable", shortVariable.getVariableName()); assertEquals((short)12, shortVariable.getValue()); assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId()); assertEquals("fVariable", dateVariable.getVariableName()); assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue()); assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId()); assertEquals("gVariable", serializableVariable.getVariableName());
private void assertThatUpdateHasAllImportantInformation(HistoricVariableUpdate variableUpdate) { assertThat(variableUpdate, notNullValue()); assertThat(variableUpdate.getId(), notNullValue()); assertThat(variableUpdate.getProcessDefinitionKey(), is("process")); assertThat(variableUpdate.getProcessDefinitionId(), notNullValue()); assertThat(variableUpdate.getVariableName(), is("stringVar")); assertThat(variableUpdate.getValue().toString(), is("foo")); assertThat(variableUpdate.getTypeName(), is("string")); assertThat(variableUpdate.getTime(), notNullValue()); }
@Test public void testHistoricDetailQueryById() { Task newTask = taskService.newTask(); taskService.saveTask(newTask); String variableName = "someName"; String variableValue = "someValue"; taskService.setVariable(newTask.getId(), variableName, variableValue); HistoricDetail result = historyService.createHistoricDetailQuery() .singleResult(); HistoricDetail resultById = historyService.createHistoricDetailQuery().detailId(result.getId()).singleResult(); assertNotNull(resultById); assertEquals(result.getId(), resultById.getId()); assertEquals(variableName, ((HistoricVariableUpdate)resultById).getVariableName()); assertEquals(variableValue, ((HistoricVariableUpdate)resultById).getValue()); assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate)resultById).getVariableTypeName()); assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate)resultById).getTypeName()); taskService.deleteTask(newTask.getId(), true); }
assertEquals("fileVar", fileVariableInstance.getVariableName());
@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 = EXCLUSIVE_GATEWAY_PROCESS) public void testHistoricVariableInstanceSetOnProcessInstance() { // when ProcessInstance instance = runtimeService .createProcessInstanceByKey("exclusiveGateway") // set the variables directly one the instance .setVariable("aVar", "aValue") .startBeforeActivity("task1") .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 assertEquals(instance.getId(), historicDetail.getActivityInstanceId()); assertTrue(historicDetail instanceof HistoricVariableUpdate); assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName()); assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue()); }
assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName()); assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue());
@Test public void testHistoricDetailQueryById() { Task newTask = taskService.newTask(); taskService.saveTask(newTask); String variableName = "someName"; String variableValue = "someValue"; taskService.setVariable(newTask.getId(), variableName, variableValue); HistoricDetail result = historyService.createHistoricDetailQuery() .singleResult(); HistoricDetail resultById = historyService.createHistoricDetailQuery().detailId(result.getId()).singleResult(); assertNotNull(resultById); assertEquals(result.getId(), resultById.getId()); assertEquals(variableName, ((HistoricVariableUpdate)resultById).getVariableName()); assertEquals(variableValue, ((HistoricVariableUpdate)resultById).getValue()); assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate)resultById).getVariableTypeName()); assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate)resultById).getTypeName()); taskService.deleteTask(newTask.getId(), true); }