use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testFailingDeserialization.
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingDeserialization() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
FailingDeserializationBean failingBean = new FailingDeserializationBean("a String", 42, true);
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(failingBean).serializationDataFormat(JSON_FORMAT_NAME));
try {
runtimeService.getVariable(instance.getId(), "simpleBean");
fail("exception expected");
} catch (ProcessEngineException e) {
// happy path
}
try {
runtimeService.getVariableTyped(instance.getId(), "simpleBean");
fail("exception expected");
} catch (ProcessEngineException e) {
// happy path
}
// However, I can access the serialized value
ObjectValue objectValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
assertFalse(objectValue.isDeserialized());
assertNotNull(objectValue.getObjectTypeName());
assertNotNull(objectValue.getValueSerialized());
// but not the deserialized properties
try {
objectValue.getValue();
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
try {
objectValue.getValue(JsonSerializable.class);
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
try {
objectValue.getObjectType();
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetSerializedVariableValue.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValue() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, true);
String beanAsJson = bean.toExpectedJsonString();
SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
// java object can be retrieved
JsonSerializable returnedBean = (JsonSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(bean, returnedBean);
// validate typed value metadata
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertEquals(bean, typedValue.getValue());
assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
assertEquals(bean.getClass().getCanonicalName(), typedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testFailingDeserialization.
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingDeserialization() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
FailingXmlDeserializationBean failingBean = new FailingXmlDeserializationBean("a String", 42, true);
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(failingBean).serializationDataFormat(XML_FORMAT_NAME));
try {
runtimeService.getVariable(instance.getId(), "simpleBean");
fail("exception expected");
} catch (ProcessEngineException e) {
assertTextPresent("Cannot deserialize object in variable 'simpleBean'", e.getMessage());
}
try {
runtimeService.getVariableTyped(instance.getId(), "simpleBean");
fail("exception expected");
} catch (ProcessEngineException e) {
// happy path
}
// However, I can access the serialized value
ObjectValue objectValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
assertFalse(objectValue.isDeserialized());
assertNotNull(objectValue.getObjectTypeName());
assertNotNull(objectValue.getValueSerialized());
// but not the deserialized properties
try {
objectValue.getValue();
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
try {
objectValue.getValue(XmlSerializable.class);
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
try {
objectValue.getObjectType();
fail("exception expected");
} catch (IllegalStateException e) {
assertTextPresent("Object is not deserialized", e.getMessage());
}
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testSetJavaOjectNullSerializedObjectTypeName.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaOjectNullSerializedObjectTypeName() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String typeName = "some.type.Name";
// set null value as "serialized" object
runtimeService.setVariable(instance.getId(), "nullObject", serializedObjectValue().serializationDataFormat(XML_FORMAT_NAME).objectTypeName(// This time an objectTypeName is provided
typeName).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");
assertNotNull(deserializedTypedValue);
assertTrue(deserializedTypedValue.isDeserialized());
assertEquals(XML_FORMAT_NAME, deserializedTypedValue.getSerializationDataFormat());
assertNull(deserializedTypedValue.getValue());
assertNull(deserializedTypedValue.getValueSerialized());
assertNull(deserializedTypedValue.getObjectType());
assertEquals(typeName, deserializedTypedValue.getObjectTypeName());
ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false);
assertNotNull(serializedTypedValue);
assertFalse(serializedTypedValue.isDeserialized());
assertEquals(XML_FORMAT_NAME, serializedTypedValue.getSerializationDataFormat());
assertNull(serializedTypedValue.getValueSerialized());
assertEquals(typeName, serializedTypedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testSetJavaOjectNullDeserialized.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaOjectNullDeserialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// set null value as "deserialized" object
runtimeService.setVariable(instance.getId(), "nullObject", objectValue(null).serializationDataFormat(XML_FORMAT_NAME).create());
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertObjectValueDeserializedNull(typedValue);
}
Aggregations