Search in sources :

Example 1 with JavaSerializable

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);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JavaSerializable(org.camunda.bpm.engine.test.api.variables.JavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with JavaSerializable

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."));
    }
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JavaSerializable(org.camunda.bpm.engine.test.api.variables.JavaSerializable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 JavaSerializable (org.camunda.bpm.engine.test.api.variables.JavaSerializable)2 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)1 Deployment (org.camunda.bpm.engine.test.Deployment)1 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)1