use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables in project camunda-bpm-platform by camunda.
the class ProcessInstantiationWithVariablesInReturnTest method testVariablesWithoutDeserialization.
private void testVariablesWithoutDeserialization(String processDefinitionKey) throws Exception {
// given serializable variable
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
// when execute process with serialized variable and wait state
ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService().createProcessInstanceByKey(processDefinitionKey).setVariable("serializedVar", serializedObjectValue(serializedObject).serializationDataFormat(Variables.SerializationDataFormats.JAVA).objectTypeName(JavaSerializable.class.getName()).create()).executeWithVariablesInReturn(false, false);
// then returned instance contains serialized variable
VariableMap map = procInstance.getVariables();
assertNotNull(map);
ObjectValue serializedVar = (ObjectValue) map.getValueTyped("serializedVar");
assertFalse(serializedVar.isDeserialized());
assertObjectValueSerializedJava(serializedVar, javaSerializable);
// access on value should fail because variable is not deserialized
try {
serializedVar.getValue();
Assert.fail("Deserialization should fail!");
} catch (IllegalStateException ise) {
assertTrue(ise.getMessage().equals("Object is not deserialized."));
}
}
Aggregations