use of org.camunda.bpm.engine.history.HistoricVariableInstanceQuery 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.HistoricVariableInstanceQuery in project camunda-bpm-platform by camunda.
the class HistoricVariableInstanceAuthorizationTest method testMixedQueryWithoutAuthorization.
// historic variable instance query (mixed variables) ////////////////////////////////////
public void testMixedQueryWithoutAuthorization() {
// given
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
createTask("one");
createTask("two");
createTask("three");
createTask("four");
createTask("five");
disableAuthorization();
taskService.setVariables("one", getVariables());
taskService.setVariables("two", getVariables());
taskService.setVariables("three", getVariables());
taskService.setVariables("four", getVariables());
taskService.setVariables("five", getVariables());
enableAuthorization();
createCaseInstanceByKey(CASE_KEY, getVariables());
createCaseInstanceByKey(CASE_KEY, getVariables());
// when
HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
// then
verifyQueryResults(query, 7);
deleteTask("one", true);
deleteTask("two", true);
deleteTask("three", true);
deleteTask("four", true);
deleteTask("five", true);
}
use of org.camunda.bpm.engine.history.HistoricVariableInstanceQuery in project camunda-bpm-platform by camunda.
the class HistoricVariableInstanceAuthorizationTest method testQueryAfterDeletingDeployment.
// delete deployment (cascade = false)
public void testQueryAfterDeletingDeployment() {
// given
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);
disableAuthorization();
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.complete(task.getId());
}
enableAuthorization();
disableAuthorization();
repositoryService.deleteDeployment(deploymentId);
enableAuthorization();
// when
HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
// then
verifyQueryResults(query, 3);
disableAuthorization();
List<HistoricProcessInstance> instances = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance instance : instances) {
historyService.deleteHistoricProcessInstance(instance.getId());
}
enableAuthorization();
}
use of org.camunda.bpm.engine.history.HistoricVariableInstanceQuery in project camunda-bpm-platform by camunda.
the class HistoricVariableInstanceAuthorizationTest method testSimpleQueryWithReadHistoryPermissionOnProcessDefinition.
public void testSimpleQueryWithReadHistoryPermissionOnProcessDefinition() {
// given
startProcessInstanceByKey(PROCESS_KEY, getVariables());
createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);
// when
HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
// then
verifyQueryResults(query, 1);
}
use of org.camunda.bpm.engine.history.HistoricVariableInstanceQuery in project camunda-bpm-platform by camunda.
the class HistoricVariableInstanceAuthorizationTest method testMixedQueryWithReadHistoryPermissionOnAnyProcessDefinition.
public void testMixedQueryWithReadHistoryPermissionOnAnyProcessDefinition() {
// given
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY, getVariables());
createTask("one");
createTask("two");
createTask("three");
createTask("four");
createTask("five");
disableAuthorization();
taskService.setVariables("one", getVariables());
taskService.setVariables("two", getVariables());
taskService.setVariables("three", getVariables());
taskService.setVariables("four", getVariables());
taskService.setVariables("five", getVariables());
enableAuthorization();
createCaseInstanceByKey(CASE_KEY, getVariables());
createCaseInstanceByKey(CASE_KEY, getVariables());
createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY);
// when
HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
// then
verifyQueryResults(query, 14);
deleteTask("one", true);
deleteTask("two", true);
deleteTask("three", true);
deleteTask("four", true);
deleteTask("five", true);
}
Aggregations