Search in sources :

Example 31 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class XmlSerializationTest method testSetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValue() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    XmlSerializable bean = new XmlSerializable("a String", 42, true);
    String beanAsXml = bean.toExpectedXmlString();
    SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsXml).serializationDataFormat(XML_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // java object can be retrieved
    XmlSerializable returnedBean = (XmlSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertEquals(bean, returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertEquals(bean, typedValue.getValue());
    assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(bean.getClass().getCanonicalName(), typedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 32 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class XmlSerializationTest method testGetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetSerializedVariableValue() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    XmlSerializable bean = new XmlSerializable("a String", 42, true);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
    SpinXmlElement serializedValue = Spin.XML(typedValue.getValueSerialized());
    assertEquals(bean.getStringProperty(), serializedValue.childElement("stringProperty").textContent());
    assertEquals(bean.getBooleanProperty(), Boolean.parseBoolean(serializedValue.childElement("booleanProperty").textContent()));
    assertEquals(bean.getIntProperty(), Integer.parseInt(serializedValue.childElement("intProperty").textContent()));
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SpinXmlElement(org.camunda.spin.xml.SpinXmlElement) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 33 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class XmlSerializationTest method testSetSerializedVariableValueNullNoTypeName.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNullNoTypeName() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(XML_FORMAT_NAME);
    // no objectTypeName specified
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // null can be retrieved
    XmlSerializable returnedBean = (XmlSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertNull(returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertNull(typedValue.getValue());
    assertNull(typedValue.getValueSerialized());
    assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertNull(typedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 34 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class FallbackSerializationTest method testSerializationOfUnknownFormat.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationOfUnknownFormat() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // when
    ObjectValue objectValue = Variables.serializedObjectValue("foo").serializationDataFormat("application/foo").objectTypeName("org.camunda.Foo").create();
    runtimeService.setVariable(instance.getId(), "var", objectValue);
    // then
    try {
        runtimeService.getVariable(instance.getId(), "var");
        fail();
    } catch (ProcessEngineException e) {
        assertTextPresent("Fallback serializer cannot handle deserialized objects", e.getMessage());
    }
    ObjectValue returnedValue = runtimeService.getVariableTyped(instance.getId(), "var", false);
    assertFalse(returnedValue.isDeserialized());
    assertEquals("application/foo", returnedValue.getSerializationDataFormat());
    assertEquals("foo", returnedValue.getValueSerialized());
    assertEquals("org.camunda.Foo", returnedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 35 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class ExecutionRestServiceInteractionTest method testGetSingleLocalObjectVariableSerialized.

@Test
public void testGetSingleLocalObjectVariableSerialized() {
    // given
    String variableKey = "aVariableId";
    ObjectValue variableValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("application/json").objectTypeName(ArrayList.class.getName()).create();
    when(runtimeServiceMock.getVariableLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    // when
    given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey).queryParam("deserializeValue", false).then().expect().statusCode(Status.OK.getStatusCode()).body("value", equalTo("a serialized value")).body("type", equalTo("Object")).body("valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")).body("valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())).when().get(SINGLE_EXECUTION_LOCAL_VARIABLE_URL);
    // then
    verify(runtimeServiceMock).getVariableLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, variableKey, false);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) EqualsObjectValue(org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)99 Test (org.junit.Test)58 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)53 Deployment (org.camunda.bpm.engine.test.Deployment)46 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)36 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)29 EqualsObjectValue (org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 Matchers.anyString (org.mockito.Matchers.anyString)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectOutputStream (java.io.ObjectOutputStream)9 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)8 Task (org.camunda.bpm.engine.task.Task)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 HashMap (java.util.HashMap)6 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)6 FailingJavaSerializable (org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 SerializedObjectValueBuilder (org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder)6