use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricJPAVariableTest method testGetJPAEntityAsHistoricVariable.
@Deployment
public void testGetJPAEntityAsHistoricVariable() {
setupJPAEntities();
// -----------------------------------------------------------------------------
// Simple test, Start process with JPA entities as variables
// -----------------------------------------------------------------------------
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);
// Start the process with the JPA-entities as variables. They will be stored in the DB.
this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();
for (Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
taskService.complete(task.getId());
}
// Get JPAEntity Variable by HistoricVariableInstanceQuery
HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess").singleResult();
Object value = historicVariableInstance.getValue();
assertThat(value).isInstanceOf(FieldAccessJPAEntity.class);
assertThat(simpleEntityFieldAccess.getValue()).isEqualTo(((FieldAccessJPAEntity) value).getValue());
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class JsonTest method testJsonArrayAvailable.
@Deployment
public void testJsonArrayAvailable() {
Map<String, Object> vars = new HashMap<String, Object>();
ArrayNode varArray = objectMapper.createArrayNode();
ObjectNode varNode = objectMapper.createObjectNode();
varNode.put("var", "myValue");
varArray.add(varNode);
vars.put("myJsonArr", varArray);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJsonAvailableProcess", vars);
// Check JSON has been parsed as expected
ArrayNode value = (ArrayNode) runtimeService.getVariable(processInstance.getId(), "myJsonArr");
assertThat(value).isNotNull();
assertThat(value.get(0).get("var").asText()).isEqualTo("myValue");
ArrayNode varArray2 = objectMapper.createArrayNode();
varNode = objectMapper.createObjectNode();
varNode.put("var", "myValue");
varArray2.add(varNode);
varNode = objectMapper.createObjectNode();
varNode.put("var", "myOtherValue");
varArray2.add(varNode);
runtimeService.setVariable(processInstance.getId(), "myJsonArr", varArray2);
// Check JSON has been updated as expected
value = (ArrayNode) runtimeService.getVariable(processInstance.getId(), "myJsonArr");
assertThat(value).isNotNull();
assertThat(value.get(0).get("var").asText()).isEqualTo("myValue");
assertThat(value.get(1).get("var").asText()).isEqualTo("myOtherValue");
Task task = taskService.createTaskQuery().active().singleResult();
assertThat(task).isNotNull();
ArrayNode varArray3 = objectMapper.createArrayNode();
varNode = objectMapper.createObjectNode();
varNode.put("var", "myValue");
varArray3.add(varNode);
varNode = objectMapper.createObjectNode();
varNode.put("var", "myOtherValue");
varArray3.add(varNode);
varNode = objectMapper.createObjectNode();
varNode.put("var", "myThirdValue");
varArray3.add(varNode);
vars = new HashMap<String, Object>();
vars.put("myJsonArr", varArray3);
taskService.complete(task.getId(), vars);
value = (ArrayNode) runtimeService.getVariable(processInstance.getId(), "myJsonArr");
assertThat(value).isNotNull();
assertThat(value.get(0).get("var").asText()).isEqualTo("myValue");
assertThat(value.get(1).get("var").asText()).isEqualTo("myOtherValue");
assertThat(value.get(2).get("var").asText()).isEqualTo("myThirdValue");
task = taskService.createTaskQuery().active().singleResult();
assertThat(task).isNotNull();
assertThat(task.getTaskDefinitionKey()).isEqualTo("userTaskSuccess");
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
value = (ArrayNode) historicVariableInstance.getValue();
assertThat(value).isNotNull();
assertThat(value.get(0).get("var").asText()).isEqualTo("myValue");
assertThat(value.get(1).get("var").asText()).isEqualTo("myOtherValue");
assertThat(value.get(2).get("var").asText()).isEqualTo("myThirdValue");
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class JsonTest method testJsonObjectAvailable.
@Deployment
public void testJsonObjectAvailable() {
Map<String, Object> vars = new HashMap<String, Object>();
ObjectNode varNode = objectMapper.createObjectNode();
varNode.put("var", "myValue");
vars.put(MY_JSON_OBJ, varNode);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJsonAvailableProcess", vars);
// Check JSON has been parsed as expected
ObjectNode value = (ObjectNode) runtimeService.getVariable(processInstance.getId(), MY_JSON_OBJ);
assertThat(value).isNotNull();
assertThat(value.get("var").asText()).isEqualTo("myValue");
ObjectNode var2Node = objectMapper.createObjectNode();
var2Node.put("var", "myValue");
var2Node.put("var2", "myOtherValue");
runtimeService.setVariable(processInstance.getId(), MY_JSON_OBJ, var2Node);
// Check JSON has been updated as expected
value = (ObjectNode) runtimeService.getVariable(processInstance.getId(), MY_JSON_OBJ);
assertThat(value).isNotNull();
assertThat(value.get("var").asText()).isEqualTo("myValue");
assertThat(value.get("var2").asText()).isEqualTo("myOtherValue");
Task task = taskService.createTaskQuery().active().singleResult();
assertThat(task).isNotNull();
ObjectNode var3Node = objectMapper.createObjectNode();
var3Node.put("var", "myValue");
var3Node.put("var2", "myOtherValue");
var3Node.put("var3", "myThirdValue");
vars = new HashMap<String, Object>();
vars.put(MY_JSON_OBJ, var3Node);
vars.put(BIG_JSON_OBJ, createBigJsonObject());
taskService.complete(task.getId(), vars);
value = (ObjectNode) runtimeService.getVariable(processInstance.getId(), MY_JSON_OBJ);
assertThat(value).isNotNull();
assertThat(value.get("var").asText()).isEqualTo("myValue");
assertThat(value.get("var2").asText()).isEqualTo("myOtherValue");
assertThat(value.get("var3").asText()).isEqualTo("myThirdValue");
value = (ObjectNode) runtimeService.getVariable(processInstance.getId(), BIG_JSON_OBJ);
assertThat(value).isNotNull();
assertThat(value.toString()).isEqualTo(createBigJsonObject().toString());
task = taskService.createTaskQuery().active().singleResult();
assertThat(task).isNotNull();
assertThat(task.getTaskDefinitionKey()).isEqualTo("userTaskSuccess");
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).orderByVariableName().asc().list();
assertThat(historicVariableInstances).hasSize(2);
assertThat(historicVariableInstances.get(0).getVariableName()).isEqualTo(BIG_JSON_OBJ);
value = (ObjectNode) historicVariableInstances.get(0).getValue();
assertThat(value).isNotNull();
assertThat(value.toString()).isEqualTo(createBigJsonObject().toString());
assertThat(historicVariableInstances.get(1).getVariableName()).isEqualTo(MY_JSON_OBJ);
value = (ObjectNode) historicVariableInstances.get(1).getValue();
assertThat(value).isNotNull();
assertThat(value.get("var").asText()).isEqualTo("myValue");
assertThat(value.get("var2").asText()).isEqualTo("myOtherValue");
assertThat(value.get("var3").asText()).isEqualTo("myThirdValue");
}
// It should be possible do remove a json variable
runtimeService.removeVariable(processInstance.getId(), MY_JSON_OBJ);
assertThat(runtimeService.getVariable(processInstance.getId(), MY_JSON_OBJ)).isNull();
// It should be possible do remove a longJson variable
runtimeService.removeVariable(processInstance.getId(), BIG_JSON_OBJ);
assertThat(runtimeService.getVariable(processInstance.getId(), BIG_JSON_OBJ)).isNull();
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceTest method testRestrictByExecutionId.
@Deployment
public void testRestrictByExecutionId() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
TaskQuery taskQuery = taskService.createTaskQuery();
Task userTask = taskQuery.singleResult();
assertThat(userTask.getName()).isEqualTo("userTask1");
taskService.complete(userTask.getId(), singletonMap("myVar", "test789"));
assertProcessEnded(processInstance.getId());
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().executionId(processInstance.getId()).list();
assertThat(variables).hasSize(1);
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertThat(historicVariable.getTextValue()).isEqualTo("test456");
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(5);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(3);
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceTest method testTwoSubProcessInParallelWithinSubProcess.
@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
assertProcessEnded(processInstance.getId());
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
assertThat(variables).hasSize(2);
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertThat(historicVariable.getName()).isEqualTo("myVar");
assertThat(historicVariable.getTextValue()).isEqualTo("test101112");
HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
assertThat(historicVariable1.getName()).isEqualTo("myVar1");
assertThat(historicVariable1.getTextValue()).isEqualTo("test789");
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(18);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(7);
}
}
Aggregations