use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetTypedNullForExistingVariable.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetTypedNullForExistingVariable() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// initially the variable has a value
JsonSerializable javaSerializable = new JsonSerializable();
runtimeService.setVariable(instance.getId(), "varName", objectValue(javaSerializable).serializationDataFormat(JSON_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 JsonSerializationTest 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(JSON_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(JSON_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(JSON_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 JsonSerializationTest method testSerializationAsJson.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsJson() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, true);
// request object to be serialized as JSON
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_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(JsonSerializable.class));
assertEquals(JsonSerializable.class, typedValue.getObjectType());
assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
assertEquals(JsonSerializable.class.getName(), typedValue.getObjectTypeName());
JSONAssert.assertEquals(bean.toExpectedJsonString(), new String(typedValue.getValueSerialized()), true);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JsonSerializationTest 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(JSON_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 TaskVariableRestResourceInteractionTest method testGetSingleObjectVariableSerialized.
@Test
public void testGetSingleObjectVariableSerialized() {
// given
String variableKey = "aVariableId";
ObjectValue variableValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("application/json").objectTypeName(ArrayList.class.getName()).create();
when(taskServiceMock.getVariableTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
// when
given().pathParam("id", EXAMPLE_TASK_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_TASK_SINGLE_VARIABLE_URL);
// then
verify(taskServiceMock).getVariableTyped(EXAMPLE_TASK_ID, variableKey, false);
}
Aggregations