use of org.camunda.bpm.engine.variable.value.ObjectValue 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());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testSetJavaOjectNullSerialized.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaOjectNullSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// set null value as "serialized" object
runtimeService.setVariable(instance.getId(), "nullObject", serializedObjectValue().serializationDataFormat(XML_FORMAT_NAME).create());
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue deserializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertObjectValueDeserializedNull(deserializedTypedValue);
ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false);
assertObjectValueSerializedNull(serializedTypedValue);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testSerializationAsXml.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsXml() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
XmlSerializable bean = new XmlSerializable("a String", 42, true);
// request object to be serialized as XML
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());
// validate untyped value
Object value = runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(bean, value);
// validate typed value
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertEquals(ValueType.OBJECT, typedValue.getType());
assertTrue(typedValue.isDeserialized());
assertEquals(bean, typedValue.getValue());
assertEquals(bean, typedValue.getValue(XmlSerializable.class));
assertEquals(XmlSerializable.class, typedValue.getObjectType());
assertEquals(XML_FORMAT_NAME, typedValue.getSerializationDataFormat());
assertEquals(XmlSerializable.class.getName(), typedValue.getObjectTypeName());
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()));
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testSetTypedNullForExistingVariable.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetTypedNullForExistingVariable() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// initially the variable has a value
XmlSerializable javaSerializable = new XmlSerializable();
runtimeService.setVariable(instance.getId(), "varName", objectValue(javaSerializable).serializationDataFormat(XML_FORMAT_NAME).create());
// get value via untyped api
assertEquals(javaSerializable, runtimeService.getVariable(instance.getId(), "varName"));
// set the variable to null via typed Api
runtimeService.setVariable(instance.getId(), "varName", objectValue(null));
// variable is still of type object
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "varName");
assertObjectValueDeserializedNull(typedValue);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class HistoricVariableJsonSerializationTest method testSelectHistoricSerializedValues.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricSerializedValues() throws JSONException {
if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, false);
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
assertNotNull(historicVariable.getValue());
assertNull(historicVariable.getErrorMessage());
ObjectValue typedValue = (ObjectValue) historicVariable.getTypedValue();
assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
JSONAssert.assertEquals(bean.toExpectedJsonString(), new String(typedValue.getValueSerialized()), true);
assertEquals(JsonSerializable.class.getName(), typedValue.getObjectTypeName());
}
}
Aggregations