use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class PaDataFormatConfiguratorTest method testExecutionVariableImplicitObjectValueUpdate.
/**
* Tests that an implicit object value update happens in the context of the
* process application.
*/
@Test
public void testExecutionVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
// given a process instance and a task
ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitProcessVariableUpdate");
// when setting a variable such that the process-application-local dataformat applies
// 10th of January 1970
Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
JsonSerializable jsonSerializable = new JsonSerializable(date);
try {
ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
runtimeService.setVariable(pi.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
} finally {
ProcessApplicationContext.clear();
}
// and triggering an implicit update of the object value variable
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
taskService.complete(task.getId());
// then the process-application-local format was used for making the update
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, false);
ImplicitObjectValueUpdateHandler.addADay(jsonSerializable);
String serializedValue = objectValue.getValueSerialized();
String expectedSerializedValue = jsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
// JsonNode#equals makes a deep comparison
Assert.assertEquals(expectedJsonTree, actualJsonTree);
// and it is also correct in the history
HistoricVariableInstance historicObjectValue = historyService.createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName(ImplicitObjectValueUpdateHandler.VARIABLE_NAME).disableCustomObjectDeserialization().singleResult();
serializedValue = ((ObjectValue) historicObjectValue.getTypedValue()).getValueSerialized();
actualJsonTree = objectMapper.readTree(serializedValue);
Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class CamundaScriptResourceTest method testDeployProcessArchive.
@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());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricVariableInstanceQuery.
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/standalone/history/FullHistoryTest.testVariableUpdates.bpmn20.xml")
public void testHistoricVariableInstanceQuery() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("process", "one");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
runtimeService.signal(processInstance.getProcessInstanceId());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("process").count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count());
Map<String, Object> variables2 = new HashMap<String, Object>();
variables2.put("process", "two");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("receiveTask", variables2);
runtimeService.signal(processInstance2.getProcessInstanceId());
assertEquals(2, historyService.createHistoricVariableInstanceQuery().variableName("process").count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "two").count());
HistoricVariableInstance historicProcessVariable = historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").singleResult();
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());
Map<String, Object> variables3 = new HashMap<String, Object>();
variables3.put("long", 1000l);
variables3.put("double", 25.43d);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("receiveTask", variables3);
runtimeService.signal(processInstance3.getProcessInstanceId());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("long").count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("long", 1000l).count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("double").count());
assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("double", 25.43d).count());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.
@Test
@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aVariable", "initial value");
Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
// In the javaDelegate, the current time is manipulated
Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
ClockUtil.setCurrentTime(startedDate);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
// 8 variable updates should be present, one performed when starting process
// the other 7 are set in VariableSetter serviceTask
assertEquals(9, details.size());
// Since we order by varName, first entry should be aVariable update from startTask
HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
assertEquals("aVariable", startVarUpdate.getVariableName());
assertEquals("initial value", startVarUpdate.getValue());
assertEquals(0, startVarUpdate.getRevision());
assertEquals(processInstance.getId(), startVarUpdate.getProcessInstanceId());
// Date should the the one set when starting
assertEquals(startedDate, startVarUpdate.getTime());
HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
assertEquals("aVariable", updatedStringVariable.getVariableName());
assertEquals("updated value", updatedStringVariable.getValue());
assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId());
// Date should be the updated date
assertEquals(updatedDate, updatedStringVariable.getTime());
HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
assertEquals("bVariable", intVariable.getVariableName());
assertEquals(123, intVariable.getValue());
assertEquals(processInstance.getId(), intVariable.getProcessInstanceId());
assertEquals(updatedDate, intVariable.getTime());
HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
assertEquals("cVariable", longVariable.getVariableName());
assertEquals(12345L, longVariable.getValue());
assertEquals(processInstance.getId(), longVariable.getProcessInstanceId());
assertEquals(updatedDate, longVariable.getTime());
HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
assertEquals("dVariable", doubleVariable.getVariableName());
assertEquals(1234.567, doubleVariable.getValue());
assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId());
assertEquals(updatedDate, doubleVariable.getTime());
HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
assertEquals("eVariable", shortVariable.getVariableName());
assertEquals((short) 12, shortVariable.getValue());
assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId());
assertEquals(updatedDate, shortVariable.getTime());
HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
assertEquals("fVariable", dateVariable.getVariableName());
assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue());
assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId());
assertEquals(updatedDate, dateVariable.getTime());
HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
assertEquals("gVariable", serializableVariable.getVariableName());
assertEquals(new SerializableVariable("hello hello"), serializableVariable.getValue());
assertEquals(processInstance.getId(), serializableVariable.getProcessInstanceId());
assertEquals(updatedDate, serializableVariable.getTime());
HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
assertEquals("hVariable", byteArrayVariable.getVariableName());
assertEquals(";-)", new String((byte[]) byteArrayVariable.getValue()));
assertEquals(processInstance.getId(), byteArrayVariable.getProcessInstanceId());
assertEquals(updatedDate, byteArrayVariable.getTime());
// end process instance
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(1, tasks.size());
taskService.complete(tasks.get(0).getId());
testHelper.assertProcessEnded(processInstance.getId());
// check for historic process variables set
HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
assertEquals(8, historicProcessVariableQuery.count());
List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
// Variable status when process is finished
HistoricVariableInstance historicVariable = historicVariables.get(0);
assertEquals("aVariable", historicVariable.getVariableName());
assertEquals("updated value", historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(1);
assertEquals("bVariable", historicVariable.getVariableName());
assertEquals(123, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(2);
assertEquals("cVariable", historicVariable.getVariableName());
assertEquals(12345L, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(3);
assertEquals("dVariable", historicVariable.getVariableName());
assertEquals(1234.567, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(4);
assertEquals("eVariable", historicVariable.getVariableName());
assertEquals((short) 12, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(5);
assertEquals("fVariable", historicVariable.getVariableName());
assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(6);
assertEquals("gVariable", historicVariable.getVariableName());
assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(7);
assertEquals("hVariable", historicVariable.getVariableName());
assertEquals(";-)", ";-)", new String((byte[]) historicVariable.getValue()));
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricDetailQueryByVariableInstanceId.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricDetailQueryByVariableInstanceId() throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("testVar", "testValue");
runtimeService.startProcessInstanceByKey("oneTaskProcess", params);
HistoricVariableInstance testVariable = historyService.createHistoricVariableInstanceQuery().variableName("testVar").singleResult();
HistoricDetailQuery query = historyService.createHistoricDetailQuery();
query.variableInstanceId(testVariable.getId());
assertEquals(1, query.count());
assertEquals(1, query.list().size());
}
Aggregations