use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationInTransactionTest method shouldBeAbleToPerformModification.
@Test
public void shouldBeAbleToPerformModification() {
// given
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("TestProcess").startEvent().intermediateCatchEvent("TimerEvent").timerWithDate("${calculateTimerDate.execute(execution)}").camundaExecutionListenerDelegateExpression("end", "${deleteVariableListener}").endEvent().done();
deployModelInstance(modelInstance);
final ProcessInstance procInst = runtimeService.startProcessInstanceByKey("TestProcess");
// when
userBean.completeUserTaskAndModifyInstanceInOneTransaction(procInst);
// then
VariableInstance variable = rule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(procInst.getId()).variableName("createDate").singleResult();
assertNotNull(variable);
HistoricVariableInstance historicVariable = rule.getHistoryService().createHistoricVariableInstanceQuery().singleResult();
assertEquals(variable.getName(), historicVariable.getName());
assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricVariablesTest method testMigrateEventScopeVariable.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testMigrateEventScopeVariable() {
// given
ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("subProcess", "subProcess").mapActivities("compensationBoundary", "compensationBoundary").build();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceDefinition.getId());
Execution subProcessExecution = runtimeService.createExecutionQuery().activityId("userTask1").singleResult();
runtimeService.setVariableLocal(subProcessExecution.getId(), "foo", "bar");
testHelper.completeTask("userTask1");
Execution eventScopeExecution = runtimeService.createExecutionQuery().activityId("subProcess").singleResult();
HistoricVariableInstance eventScopeVariable = historyService.createHistoricVariableInstanceQuery().executionIdIn(eventScopeExecution.getId()).singleResult();
// when
runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
// then
HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().variableId(eventScopeVariable.getId()).singleResult();
Assert.assertEquals(targetDefinition.getId(), historicVariableInstance.getProcessDefinitionId());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableUpdates.
@Test
@Deployment
public void testVariableUpdates() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("number", "one");
variables.put("character", "a");
variables.put("bytes", ":-(".getBytes());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
runtimeService.setVariable(processInstance.getId(), "number", "two");
runtimeService.setVariable(processInstance.getId(), "bytes", ":-)".getBytes());
// Start-task should be added to history
HistoricActivityInstance historicStartEvent = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theStart").singleResult();
assertNotNull(historicStartEvent);
HistoricActivityInstance waitStateActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("waitState").singleResult();
assertNotNull(waitStateActivity);
HistoricActivityInstance serviceTaskActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("serviceTask").singleResult();
assertNotNull(serviceTaskActivity);
List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().orderByVariableName().asc().orderByVariableRevision().asc().list();
assertEquals(10, historicDetails.size());
HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(0);
assertEquals("bytes", historicVariableUpdate.getVariableName());
assertEquals(":-(", new String((byte[]) historicVariableUpdate.getValue()));
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable is updated when process was in waitstate
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(1);
assertEquals("bytes", historicVariableUpdate.getVariableName());
assertEquals(":-)", new String((byte[]) historicVariableUpdate.getValue()));
assertEquals(1, historicVariableUpdate.getRevision());
assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(2);
assertEquals("character", historicVariableUpdate.getVariableName());
assertEquals("a", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(3);
assertEquals("number", historicVariableUpdate.getVariableName());
assertEquals("one", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable is updated when process was in waitstate
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(4);
assertEquals("number", historicVariableUpdate.getVariableName());
assertEquals("two", historicVariableUpdate.getValue());
assertEquals(1, historicVariableUpdate.getRevision());
assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from process-start execution listener
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(5);
assertEquals("zVar1", historicVariableUpdate.getVariableName());
assertEquals("Event: start", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from transition take execution listener
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(6);
assertEquals("zVar2", historicVariableUpdate.getVariableName());
assertEquals("Event: take", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertNull(historicVariableUpdate.getActivityInstanceId());
// Variable set from activity start execution listener on the servicetask
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(7);
assertEquals("zVar3", historicVariableUpdate.getVariableName());
assertEquals("Event: start", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from activity end execution listener on the servicetask
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(8);
assertEquals("zVar4", historicVariableUpdate.getVariableName());
assertEquals("Event: end", historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// Variable set from service-task
historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(9);
assertEquals("zzz", historicVariableUpdate.getVariableName());
assertEquals(123456789L, historicVariableUpdate.getValue());
assertEquals(0, historicVariableUpdate.getRevision());
assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
// trigger receive task
runtimeService.signal(processInstance.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("bytes", historicVariable.getVariableName());
assertEquals(":-)", new String((byte[]) historicVariable.getValue()));
historicVariable = historicVariables.get(1);
assertEquals("character", historicVariable.getVariableName());
assertEquals("a", historicVariable.getValue());
historicVariable = historicVariables.get(2);
assertEquals("number", historicVariable.getVariableName());
assertEquals("two", historicVariable.getValue());
historicVariable = historicVariables.get(3);
assertEquals("zVar1", historicVariable.getVariableName());
assertEquals("Event: start", historicVariable.getValue());
historicVariable = historicVariables.get(4);
assertEquals("zVar2", historicVariable.getVariableName());
assertEquals("Event: take", historicVariable.getValue());
historicVariable = historicVariables.get(5);
assertEquals("zVar3", historicVariable.getVariableName());
assertEquals("Event: start", historicVariable.getValue());
historicVariable = historicVariables.get(6);
assertEquals("zVar4", historicVariable.getVariableName());
assertEquals("Event: end", historicVariable.getValue());
historicVariable = historicVariables.get(7);
assertEquals("zzz", historicVariable.getVariableName());
assertEquals(123456789L, historicVariable.getValue());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class AuditHistoryTest method testReceivesNoHistoricVariableUpdatesAsDetails.
@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testReceivesNoHistoricVariableUpdatesAsDetails() {
// given
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// when
String value = "a Variable Value";
runtimeService.setVariable(instance.getId(), "aStringVariable", value);
runtimeService.setVariable(instance.getId(), "aBytesVariable", value.getBytes());
String newValue = "a new Variable Value";
runtimeService.setVariable(instance.getId(), "aStringVariable", newValue);
runtimeService.setVariable(instance.getId(), "aBytesVariable", newValue.getBytes());
// then the historic variable instances exist and they have the latest values
assertEquals(2, historyService.createHistoricVariableInstanceQuery().count());
HistoricVariableInstance historicStringVariable = historyService.createHistoricVariableInstanceQuery().variableName("aStringVariable").singleResult();
assertNotNull(historicStringVariable);
assertEquals(newValue, historicStringVariable.getValue());
HistoricVariableInstance historicBytesVariable = historyService.createHistoricVariableInstanceQuery().variableName("aBytesVariable").singleResult();
assertNotNull(historicBytesVariable);
assertTrue(Arrays.equals(newValue.getBytes(), (byte[]) historicBytesVariable.getValue()));
// and no historic details exist
assertEquals(0, historyService.createHistoricDetailQuery().variableUpdates().count());
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class CustomHistoryTest method testReceivesVariableUpdates.
@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testReceivesVariableUpdates() {
// given
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// when
String value = "a Variable Value";
runtimeService.setVariable(instance.getId(), "aStringVariable", value);
runtimeService.setVariable(instance.getId(), "aBytesVariable", value.getBytes());
// then the historic variable instances and their values exist
assertEquals(2, historyService.createHistoricVariableInstanceQuery().count());
HistoricVariableInstance historicStringVariable = historyService.createHistoricVariableInstanceQuery().variableName("aStringVariable").singleResult();
assertNotNull(historicStringVariable);
assertEquals(value, historicStringVariable.getValue());
HistoricVariableInstance historicBytesVariable = historyService.createHistoricVariableInstanceQuery().variableName("aBytesVariable").singleResult();
assertNotNull(historicBytesVariable);
assertTrue(Arrays.equals(value.getBytes(), (byte[]) historicBytesVariable.getValue()));
// then the historic variable updates and their values exist
assertEquals(2, historyService.createHistoricDetailQuery().variableUpdates().count());
HistoricVariableUpdate historicStringVariableUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(historicStringVariable.getId()).singleResult();
assertNotNull(historicStringVariableUpdate);
assertEquals(value, historicStringVariableUpdate.getValue());
HistoricVariableUpdate historicByteVariableUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(historicBytesVariable.getId()).singleResult();
assertNotNull(historicByteVariableUpdate);
assertTrue(Arrays.equals(value.getBytes(), (byte[]) historicByteVariableUpdate.getValue()));
}
Aggregations