Search in sources :

Example 6 with SerializedObjectValueBuilder

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

the class XmlSerializationTest method testSetSerializedVariableValueNoTypeName.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNoTypeName() {
    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);
    try {
        runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
        fail("Exception expected.");
    } catch (Exception e) {
        assertTextPresent("no 'objectTypeName' provided for non-null value", e.getMessage());
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with SerializedObjectValueBuilder

use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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 8 with SerializedObjectValueBuilder

use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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 9 with SerializedObjectValueBuilder

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

the class XmlSerializationTest method testSetSerializedVariableValueNull.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNull() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(XML_FORMAT_NAME).objectTypeName(XmlSerializable.class.getCanonicalName());
    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());
    assertEquals(XmlSerializable.class.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 10 with SerializedObjectValueBuilder

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

the class XmlSerializationTest method testSetSerializedVariableValueMismatchingTypeName.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueMismatchingTypeName() {
    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(// < not a valid type name
    "Insensible type name.");
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    try {
        runtimeService.getVariable(instance.getId(), "simpleBean");
        fail("Exception expected.");
    } catch (ProcessEngineException e) {
    // happy path
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 SerializedObjectValueBuilder (org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder)11 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)6 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 JSONException (org.json.JSONException)2