use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSetJavaObjectNullSerialized.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectNullSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// set null value as "serialized" object
runtimeService.setVariable(instance.getId(), "nullObject", serializedObjectValue().serializationDataFormat(JAVA_DATA_FORMAT).create());
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue deserializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertObjectValueDeserializedNull(deserializedTypedValue);
ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false);
assertObjectValueSerializedNull(serializedTypedValue);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSetTypedNullForExistingVariable.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetTypedNullForExistingVariable() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// initially the variable has a value
JavaSerializable javaSerializable = new JavaSerializable("foo");
runtimeService.setVariable(instance.getId(), "varName", objectValue(javaSerializable).serializationDataFormat(JAVA_DATA_FORMAT).create());
// get value via untyped api
assertEquals(javaSerializable, runtimeService.getVariable(instance.getId(), "varName"));
// set the variable to null via typed Api
runtimeService.setVariable(instance.getId(), "varName", objectValue(null));
// variable is still of type object
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "varName");
assertObjectValueDeserializedNull(typedValue);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSetJavaObjectNullDeserialized.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectNullDeserialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// set null value as "deserialized" object
runtimeService.setVariable(instance.getId(), "nullObject", objectValue(null).serializationDataFormat(JAVA_DATA_FORMAT).create());
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertObjectValueDeserializedNull(typedValue);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSerializationAsJava.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsJava() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable javaSerializable = new JavaSerializable("foo");
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(javaSerializable).serializationDataFormat(JAVA_DATA_FORMAT).create());
// validate untyped value
JavaSerializable value = (JavaSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(javaSerializable, value);
// validate typed value
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertObjectValueDeserialized(typedValue, javaSerializable);
assertObjectValueSerializedJava(typedValue, javaSerializable);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testMessageStartEventCorrelationSetSerializedVariableValues.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testMessageStartEventCorrelation.bpmn20.xml")
@Test
public void testMessageStartEventCorrelationSetSerializedVariableValues() 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:
runtimeService.createMessageCorrelation("newInvoiceMessage").setVariables(Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create())).correlate();
// 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());
}
Aggregations