use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceTest method testHistoricVariableInstanceQuery.
@Deployment(resources = { "org/activiti/engine/test/history/HistoricVariableInstanceTest.testCallSimpleSubProcess.bpmn20.xml", "org/activiti/engine/test/history/simpleSubProcess.bpmn20.xml" })
public void testHistoricVariableInstanceQuery() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
assertProcessEnded(processInstance.getId());
assertThat(historyService.createHistoricVariableInstanceQuery().count()).isEqualTo(4);
assertThat(historyService.createHistoricVariableInstanceQuery().list()).hasSize(4);
assertThat(historyService.createHistoricVariableInstanceQuery().orderByProcessInstanceId().asc().count()).isEqualTo(4);
assertThat(historyService.createHistoricVariableInstanceQuery().orderByProcessInstanceId().asc().list()).hasSize(4);
assertThat(historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().count()).isEqualTo(4);
assertThat(historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list()).hasSize(4);
assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(2);
assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list()).hasSize(2);
assertThat(historyService.createHistoricVariableInstanceQuery().variableName("myVar").count()).isEqualTo(2);
assertThat(historyService.createHistoricVariableInstanceQuery().variableName("myVar").list()).hasSize(2);
assertThat(historyService.createHistoricVariableInstanceQuery().variableNameLike("myVar1").count()).isEqualTo(2);
assertThat(historyService.createHistoricVariableInstanceQuery().variableNameLike("myVar1").list()).hasSize(2);
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
assertThat(variables).hasSize(4);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test123").count()).isEqualTo(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test123").list()).hasSize(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test456").count()).isEqualTo(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test456").list()).hasSize(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test666").count()).isEqualTo(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar", "test666").list()).hasSize(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test666").count()).isEqualTo(1);
assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("myVar1", "test666").list()).hasSize(1);
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(8);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(5);
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class ProcessInstanceLogQueryAndByteArrayTypeVariableTest method testIncludeVariableUpdates.
public void testIncludeVariableUpdates() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("var").singleResult();
assertThat(LARGE_STRING_VALUE).isEqualTo(historicVariableInstance.getValue());
ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeVariableUpdates().singleResult();
List<HistoricData> events = log.getHistoricData();
assertThat(events).hasSize(1);
for (HistoricData event : events) {
assertThat(event).isInstanceOf(HistoricVariableUpdate.class);
assertThat(LARGE_STRING_VALUE).isEqualTo(((HistoricDetailVariableInstanceUpdateEntity) event).getValue());
}
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.
@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");
processEngineConfiguration.getClock().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
assertThat(details).hasSize(9);
// Since we order by varName, first entry should be aVariable update from startTask
HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
assertThat(startVarUpdate.getVariableName()).isEqualTo("aVariable");
assertThat(startVarUpdate.getValue()).isEqualTo("initial value");
assertThat(startVarUpdate.getRevision()).isEqualTo(0);
assertThat(startVarUpdate.getProcessInstanceId()).isEqualTo(processInstance.getId());
// Date should the the one set when starting
assertThat(startVarUpdate.getTime()).isEqualTo(startedDate);
HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
assertThat(updatedStringVariable.getVariableName()).isEqualTo("aVariable");
assertThat(updatedStringVariable.getValue()).isEqualTo("updated value");
assertThat(updatedStringVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
// Date should be the updated date
assertThat(updatedStringVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
assertThat(intVariable.getVariableName()).isEqualTo("bVariable");
assertThat(intVariable.getValue()).isEqualTo(123);
assertThat(intVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(intVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
assertThat(longVariable.getVariableName()).isEqualTo("cVariable");
assertThat(longVariable.getValue()).isEqualTo(12345L);
assertThat(longVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(longVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
assertThat(doubleVariable.getVariableName()).isEqualTo("dVariable");
assertThat(doubleVariable.getValue()).isEqualTo(1234.567);
assertThat(doubleVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(doubleVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
assertThat(shortVariable.getVariableName()).isEqualTo("eVariable");
assertThat(shortVariable.getValue()).isEqualTo((short) 12);
assertThat(shortVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(shortVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
assertThat(dateVariable.getVariableName()).isEqualTo("fVariable");
assertThat(dateVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
assertThat(dateVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(dateVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
assertThat(serializableVariable.getVariableName()).isEqualTo("gVariable");
assertThat(serializableVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
assertThat(serializableVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(serializableVariable.getTime()).isEqualTo(updatedDate);
HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
assertThat(byteArrayVariable.getVariableName()).isEqualTo("hVariable");
assertThat(new String((byte[]) byteArrayVariable.getValue())).isEqualTo(";-)");
assertThat(byteArrayVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(byteArrayVariable.getTime()).isEqualTo(updatedDate);
// end process instance
List<Task> tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(1);
taskService.complete(tasks.get(0).getId());
assertProcessEnded(processInstance.getId());
// check for historic process variables set
HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
assertThat(historicProcessVariableQuery.count()).isEqualTo(8);
List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
// Variable status when process is finished
HistoricVariableInstance historicVariable = historicVariables.get(0);
assertThat(historicVariable.getVariableName()).isEqualTo("aVariable");
assertThat(historicVariable.getValue()).isEqualTo("updated value");
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(1);
assertThat(historicVariable.getVariableName()).isEqualTo("bVariable");
assertThat(historicVariable.getValue()).isEqualTo(123);
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(2);
assertThat(historicVariable.getVariableName()).isEqualTo("cVariable");
assertThat(historicVariable.getValue()).isEqualTo(12345L);
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(3);
assertThat(historicVariable.getVariableName()).isEqualTo("dVariable");
assertThat(historicVariable.getValue()).isEqualTo(1234.567);
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(4);
assertThat(historicVariable.getVariableName()).isEqualTo("eVariable");
assertThat(historicVariable.getValue()).isEqualTo((short) 12);
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(5);
assertThat(historicVariable.getVariableName()).isEqualTo("fVariable");
assertThat(historicVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(6);
assertThat(historicVariable.getVariableName()).isEqualTo("gVariable");
assertThat(historicVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
historicVariable = historicVariables.get(7);
assertThat(historicVariable.getVariableName()).isEqualTo("hVariable");
assertThat(new String((byte[]) historicVariable.getValue())).isEqualTo(";-)");
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceEscapeClauseTest method testQueryByVariableNameLike.
@Test
public void testQueryByVariableNameLike() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%\\%%").singleResult();
assertThat(historicVariable).isNotNull();
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
assertThat(historicVariable.getValue()).isEqualTo("One%");
historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%\\_%").singleResult();
assertThat(historicVariable).isNotNull();
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
assertThat(historicVariable.getValue()).isEqualTo("Two_");
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceEscapeClauseTest method testQueryLikeByQueryVariableValueIgnoreCase.
@Test
public void testQueryLikeByQueryVariableValueIgnoreCase() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var%", "%\\%%").singleResult();
assertThat(historicVariable).isNotNull();
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var_", "%\\_%").singleResult();
assertThat(historicVariable).isNotNull();
assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
}
}
Aggregations