Search in sources :

Example 1 with FailingJavaSerializable

use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.

the class MessageCorrelationTest method testMessageStartEventCorrelationSetSerializedVariableValues.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testMessageStartEventCorrelation.bpmn20.xml")
@Test
public void testMessageStartEventCorrelationSetSerializedVariableValues() throws IOException, ClassNotFoundException {
    // 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
    ProcessInstance startedInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(startedInstance);
    ObjectValue variableTyped = runtimeService.getVariableTyped(startedInstance.getId(), "var", false);
    assertNotNull(variableTyped);
    assertFalse(variableTyped.isDeserialized());
    assertEquals(serializedObject, variableTyped.getValueSerialized());
    assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
    assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with FailingJavaSerializable

use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.

the class MessageCorrelationTest method testMessageStartEventCorrelationSetSerializedVariableValue.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testMessageStartEventCorrelation.bpmn20.xml")
@Test
public void testMessageStartEventCorrelationSetSerializedVariableValue() throws IOException, ClassNotFoundException {
    // 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").setVariable("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()).correlate();
    // then
    ProcessInstance startedInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(startedInstance);
    ObjectValue variableTyped = runtimeService.getVariableTyped(startedInstance.getId(), "var", false);
    assertNotNull(variableTyped);
    assertFalse(variableTyped.isDeserialized());
    assertEquals(serializedObject, variableTyped.getValueSerialized());
    assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
    assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with FailingJavaSerializable

use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.

the class MessageCorrelationTest method testExecutionCorrelationSetSerializedVariableValue.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testExecutionCorrelationSetSerializedVariableValue() 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").setVariable("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());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with FailingJavaSerializable

use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.

the class MessageIntermediateEventTest method testSetSerializedVariableValues.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/message/MessageIntermediateEventTest.testSingleIntermediateMessageEvent.bpmn20.xml")
@Test
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    EventSubscription messageEventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    // 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 when delivering a message:
    runtimeService.messageEventReceived("newInvoiceMessage", messageEventSubscription.getExecutionId(), Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
    // 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());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with FailingJavaSerializable

use of org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable in project camunda-bpm-platform by camunda.

the class SignalEventTest method testSetSerializedVariableValues.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/signal/SignalEventTest.signalStartEvent.bpmn20.xml")
@Test
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
    // 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 when delivering a message:
    runtimeService.signalEventReceived("alert", Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
    // then
    ProcessInstance startedInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(startedInstance);
    ObjectValue variableTyped = runtimeService.getVariableTyped(startedInstance.getId(), "var", false);
    assertNotNull(variableTyped);
    assertFalse(variableTyped.isDeserialized());
    assertEquals(serializedObject, variableTyped.getValueSerialized());
    assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
    assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)6 Deployment (org.camunda.bpm.engine.test.Deployment)6 FailingJavaSerializable (org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable)6 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)6 Test (org.junit.Test)6 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)1