use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableInstance.
@Test
public void testVariableInstance() {
Task newTask = taskService.newTask();
taskService.saveTask(newTask);
String variableName = "someName";
String variableValue = "someValue";
taskService.setVariable(newTask.getId(), variableName, variableValue);
VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();
assertNotNull(variable);
HistoricVariableUpdate result = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().singleResult();
assertNotNull(result);
assertEquals(variable.getId(), result.getVariableInstanceId());
taskService.deleteTask(newTask.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testDisableBinaryFetchingForFileValues.
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
public void testDisableBinaryFetchingForFileValues() {
// given
String fileName = "text.txt";
String encoding = "crazy-encoding";
String mimeType = "martini/dry";
FileValue fileValue = Variables.fileValue(fileName).file("ABC".getBytes()).encoding(encoding).mimeType(mimeType).create();
runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("fileVar", fileValue));
// when enabling binary fetching
HistoricVariableUpdate fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().singleResult();
// then the binary value is accessible
assertNotNull(fileVariableInstance.getValue());
// when disabling binary fetching
fileVariableInstance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().disableBinaryFetching().singleResult();
// then the byte value is not fetched
assertNotNull(fileVariableInstance);
assertEquals("fileVar", fileVariableInstance.getVariableName());
assertNull(fileVariableInstance.getValue());
FileValue typedValue = (FileValue) fileVariableInstance.getTypedValue();
assertNull(typedValue.getValue());
// but typed value metadata is accessible
assertEquals(ValueType.FILE, typedValue.getType());
assertEquals(fileName, typedValue.getFilename());
assertEquals(encoding, typedValue.getEncoding());
assertEquals(mimeType, typedValue.getMimeType());
}
use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testDisableCustomObjectDeserialization.
@Test
public void testDisableCustomObjectDeserialization() {
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);
List<HistoricDetail> results = historyService.createHistoricDetailQuery().disableBinaryFetching().disableCustomObjectDeserialization().variableUpdates().list();
// both variables are not deserialized, but their serialized values are available
assertEquals(2, results.size());
for (HistoricDetail update : results) {
HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) update;
assertNull(variableUpdate.getErrorMessage());
ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue();
assertNotNull(typedValue);
assertFalse(typedValue.isDeserialized());
// cannot access the deserialized value
try {
typedValue.getValue();
} catch (IllegalStateException e) {
Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Object is not deserialized"));
}
assertNotNull(typedValue.getValueSerialized());
}
taskService.deleteTask(newTask.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableUpdatesLinkedToActivity.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("test", "1");
taskService.complete(task.getId(), variables);
// now we are in the subprocess
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
variables.clear();
variables.put("test", "2");
taskService.complete(task.getId(), variables);
// now we are ended
testHelper.assertProcessEnded(pi.getId());
// check history
List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
assertEquals(2, updates.size());
Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
updatesMap.put((String) update.getValue(), update);
update = (HistoricVariableUpdate) updates.get(1);
updatesMap.put((String) update.getValue(), update);
HistoricVariableUpdate update1 = updatesMap.get("1");
HistoricVariableUpdate update2 = updatesMap.get("2");
assertNotNull(update1.getActivityInstanceId());
assertNotNull(update1.getExecutionId());
HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
assertEquals("usertask1", historicActivityInstance1.getActivityId());
assertNotNull(update2.getActivityInstanceId());
HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
assertEquals("usertask2", historicActivityInstance2.getActivityId());
/*
* This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
* stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
*
* execution id: On which execution it was set
* activity id: in which activity was the process instance when setting the variable
*/
assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricVariableUpdateCaseDefinitionProperty.
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testHistoricVariableUpdateCaseDefinitionProperty() {
// given
String key = "oneTaskCase";
CaseInstance caseInstance = caseService.createCaseInstanceByKey(key);
String caseInstanceId = caseInstance.getId();
String humanTask = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
String taskId = taskService.createTaskQuery().singleResult().getId();
caseService.setVariable(caseInstanceId, "aVariable", "aValue");
taskService.setVariableLocal(taskId, "aLocalVariable", "anotherValue");
String firstVariable = runtimeService.createVariableInstanceQuery().variableName("aVariable").singleResult().getId();
String secondVariable = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").singleResult().getId();
// when (1)
HistoricVariableUpdate instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(firstVariable).singleResult();
// then (1)
assertNotNull(instance.getCaseDefinitionKey());
assertEquals(key, instance.getCaseDefinitionKey());
assertNotNull(instance.getCaseDefinitionId());
assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
assertNull(instance.getProcessDefinitionKey());
assertNull(instance.getProcessDefinitionId());
// when (2)
instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(secondVariable).singleResult();
// then (2)
assertNotNull(instance.getCaseDefinitionKey());
assertEquals(key, instance.getCaseDefinitionKey());
assertNotNull(instance.getCaseDefinitionId());
assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
assertNull(instance.getProcessDefinitionKey());
assertNull(instance.getProcessDefinitionId());
}
Aggregations