Search in sources :

Example 16 with ProcessInstanceWithVariables

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."));
    }
}
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

ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)16 VariableMap (org.camunda.bpm.engine.variable.VariableMap)10 Test (org.junit.Test)10 Deployment (org.camunda.bpm.engine.test.Deployment)7 ProcessInstantiationBuilder (org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Response (com.jayway.restassured.response.Response)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 StartProcessInstanceAtActivitiesCmd (org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd)1 StartProcessInstanceCmd (org.camunda.bpm.engine.impl.cmd.StartProcessInstanceCmd)1 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)1