use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testExecutionCorrelationSetSerializedVariableValues.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testExecutionCorrelationSetSerializedVariableValues() throws IOException, ClassNotFoundException {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
// 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
ObjectValue variableTyped = runtimeService.getVariableTyped(processInstance.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