use of org.camunda.bpm.engine.test.api.variables.JavaSerializable in project camunda-bpm-platform by camunda.
the class JPAVariableTest method testFailSerializationForUnknownSerializedValueType.
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailSerializationForUnknownSerializedValueType() throws IOException {
// given
JavaSerializable pojo = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(pojo);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);
ObjectValue serializedObjectValue = Variables.serializedObjectValue(serializedObject).serializationDataFormat(SerializationDataFormats.JAVA).objectTypeName(pojo.getClass().getName()).create();
VariableMap variables = Variables.createVariables().putValueTyped("var", serializedObjectValue);
// when
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
// then
JavaSerializable returnedPojo = (JavaSerializable) runtimeService.getVariable(processInstance.getId(), "var");
assertEquals(pojo, returnedPojo);
}
use of org.camunda.bpm.engine.test.api.variables.JavaSerializable 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