use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteWithLocalVariables.
public void testCompleteWithLocalVariables() {
// given
BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask").camundaType("external").camundaTopic("foo").camundaTaskPriority("100").camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class).userTask("user").endEvent().done();
deployment(instance);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();
// when
externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, null, Variables.createVariables().putValue("abc", "bar"));
// then
VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).singleResult();
assertNull(variableInstance);
if (processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_AUDIT || processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_FULL) {
HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().activityInstanceIdIn(lockedTasks.get(0).getActivityInstanceId()).singleResult();
assertNotNull(historicVariableInstance);
assertEquals("abc", historicVariableInstance.getName());
assertEquals("bar", historicVariableInstance.getValue());
}
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class ModifyVariableInSameTransactionTest method testDeleteAndInsertTheSameVariableByteArray.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testDeleteAndInsertTheSameVariableByteArray() {
BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("serviceTaskProcess").startEvent().userTask("userTask").serviceTask("service").camundaClass(DeleteAndInsertVariableDelegate.class).userTask("userTask1").endEvent().done();
ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
VariableMap variables = Variables.createVariables().putValue("listVar", Arrays.asList(new int[] { 1, 2, 3 }));
ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
Task task = engineRule.getTaskService().createTaskQuery().singleResult();
engineRule.getTaskService().complete(task.getId());
VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("listVar").singleResult();
assertNotNull(variable);
assertEquals("stringValue", variable.getValue());
HistoricVariableInstance historicVariable = engineRule.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 ModifyVariableInSameTransactionTest method testDeleteAndInsertTheSameVariable.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testDeleteAndInsertTheSameVariable() {
BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("serviceTaskProcess").startEvent().userTask("userTask").serviceTask("service").camundaClass(DeleteAndInsertVariableDelegate.class).userTask("userTask1").endEvent().done();
ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
VariableMap variables = Variables.createVariables().putValue("foo", "firstValue");
ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
Task task = engineRule.getTaskService().createTaskQuery().singleResult();
engineRule.getTaskService().complete(task.getId());
VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("foo").singleResult();
assertNotNull(variable);
assertEquals("secondValue", variable.getValue());
HistoricVariableInstance historicVariable = engineRule.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 PaDataFormatConfiguratorTest method testTaskVariableImplicitObjectValueUpdate.
@Test
public void testTaskVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
// given a process instance
ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitTaskVariableUpdate");
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
// when setting a variable such that the process-application-local dataformat applies
// 10th of January 1970
Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
JsonSerializable jsonSerializable = new JsonSerializable(date);
try {
ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
taskService.setVariableLocal(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
} finally {
ProcessApplicationContext.clear();
}
// and triggering an implicit update of the object value variable
taskService.setAssignee(task.getId(), "foo");
// then the process-application-local format was used for making the update
ObjectValue objectValue = taskService.getVariableTyped(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, false);
ImplicitObjectValueUpdateHandler.addADay(jsonSerializable);
String serializedValue = objectValue.getValueSerialized();
String expectedSerializedValue = jsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
// JsonNode#equals makes a deep comparison
Assert.assertEquals(expectedJsonTree, actualJsonTree);
// and it is also correct in the history
HistoricVariableInstance historicObjectValue = historyService.createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName(ImplicitObjectValueUpdateHandler.VARIABLE_NAME).disableCustomObjectDeserialization().singleResult();
serializedValue = ((ObjectValue) historicObjectValue.getTypedValue()).getValueSerialized();
actualJsonTree = objectMapper.readTree(serializedValue);
Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.
the class TaskAuthorizationTest method testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask.
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask() {
// given
String taskId = "myTask";
createTask(taskId);
createGrantAuthorization(TASK, taskId, userId, UPDATE);
VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
// when (1)
((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), null);
// then (1)
disableAuthorization();
verifyQueryResults(query, 1);
enableAuthorization();
// when (2)
((TaskServiceImpl) taskService).updateVariablesLocal(taskId, null, Arrays.asList(VARIABLE_NAME));
// then (2)
disableAuthorization();
verifyQueryResults(query, 0);
enableAuthorization();
// when (3)
((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), Arrays.asList(VARIABLE_NAME));
// then (3)
disableAuthorization();
verifyQueryResults(query, 0);
enableAuthorization();
deleteTask(taskId, true);
List<HistoricVariableInstance> deletedVariables = historyService.createHistoricVariableInstanceQuery().includeDeleted().list();
Assert.assertEquals("DELETED", deletedVariables.get(0).getState());
Assert.assertEquals("DELETED", deletedVariables.get(1).getState());
}
Aggregations