use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class SignalEventTest method testSetSerializedVariableValues.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/signal/SignalEventTest.signalStartEvent.bpmn20.xml")
@Test
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
// when
FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
// then it is not possible to deserialize the object
try {
new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
} catch (RuntimeException e) {
testRule.assertTextPresent("Exception while deserializing object.", e.getMessage());
}
// but it can be set as a variable when delivering a message:
runtimeService.signalEventReceived("alert", Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
// then
ProcessInstance startedInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertNotNull(startedInstance);
ObjectValue variableTyped = runtimeService.getVariableTyped(startedInstance.getId(), "var", false);
assertNotNull(variableTyped);
assertFalse(variableTyped.isDeserialized());
assertEquals(serializedObject, variableTyped.getValueSerialized());
assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class PaDataFormatConfiguratorTest method testExecutionVariableImplicitObjectValueUpdate.
/**
* Tests that an implicit object value update happens in the context of the
* process application.
*/
@Test
public void testExecutionVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
// given a process instance and a task
ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitProcessVariableUpdate");
// 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);
runtimeService.setVariable(pi.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
} finally {
ProcessApplicationContext.clear();
}
// and triggering an implicit update of the object value variable
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
taskService.complete(task.getId());
// then the process-application-local format was used for making the update
ObjectValue objectValue = runtimeService.getVariableTyped(pi.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.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class PaSpinSupportTest method spinCanBeUsedForVariableSerialization.
@Test
public void spinCanBeUsedForVariableSerialization() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables().putValue("serializedObject", serializedObjectValue("{\"foo\": \"bar\"}").serializationDataFormat("application/json").objectTypeName(HashMap.class.getName())));
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "serializedObject", true);
HashMap<String, String> expected = new HashMap<String, String>();
expected.put("foo", "bar");
Assert.assertEquals(expected, objectValue.getValue());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class RuntimeServiceDelegate method execute.
public void execute(DelegateExecution execution) throws Exception {
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
ObjectValue jsonSerializeable = Variables.objectValue(createJsonSerializable()).serializationDataFormat(SerializationDataFormats.JSON).create();
// this should be executed in the context of the current process application
runtimeService.setVariable(execution.getProcessInstanceId(), VARIABLE_NAME, jsonSerializeable);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testDisableCustomObjectDeserialization.
@Test
public void testDisableCustomObjectDeserialization() {
Task newTask = taskService.newTask();
taskService.saveTask(newTask);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("customSerializable", new CustomSerializable());
variables.put("failingSerializable", new FailingSerializable());
taskService.setVariables(newTask.getId(), variables);
List<HistoricDetail> results = historyService.createHistoricDetailQuery().disableBinaryFetching().disableCustomObjectDeserialization().variableUpdates().list();
// both variables are not deserialized, but their serialized values are available
assertEquals(2, results.size());
for (HistoricDetail update : results) {
HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) update;
assertNull(variableUpdate.getErrorMessage());
ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue();
assertNotNull(typedValue);
assertFalse(typedValue.isDeserialized());
// cannot access the deserialized value
try {
typedValue.getValue();
} catch (IllegalStateException e) {
Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Object is not deserialized"));
}
assertNotNull(typedValue.getValueSerialized());
}
taskService.deleteTask(newTask.getId(), true);
}
Aggregations