use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testImplicitlyUpdateEmptyList.
/**
* CAM-3222
*/
@Deployment(resources = SERVICE_TASK_PROCESS)
public void testImplicitlyUpdateEmptyList() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("serviceTaskProcess", Variables.createVariables().putValueTyped("listVar", Variables.objectValue(new ArrayList<JsonSerializable>()).serializationDataFormat("application/json").create()).putValue("delegate", new UpdateValueDelegate()));
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "listVar");
// this should match Jackson's format
String expectedTypeName = ArrayList.class.getName() + "<" + JsonSerializable.class.getName() + ">";
assertEquals(expectedTypeName, typedValue.getObjectTypeName());
List<JsonSerializable> list = (List<JsonSerializable>) typedValue.getValue();
assertEquals(1, list.size());
assertTrue(list.get(0) instanceof JsonSerializable);
assertEquals(UpdateValueDelegate.STRING_PROPERTY, list.get(0).getStringProperty());
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetUntypedNullForExistingVariable.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetUntypedNullForExistingVariable() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// initially the variable has a value
JsonSerializable object = new JsonSerializable();
runtimeService.setVariable(instance.getId(), "varName", objectValue(object).serializationDataFormat(JSON_FORMAT_NAME).create());
// get value via untyped api
assertEquals(object, runtimeService.getVariable(instance.getId(), "varName"));
// set the variable to null via untyped Api
runtimeService.setVariable(instance.getId(), "varName", null);
// variable is now untyped null
TypedValue nullValue = runtimeService.getVariableTyped(instance.getId(), "varName");
assertUntypedNullValue(nullValue);
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetSerializedVariableValueNullNoTypeName.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNullNoTypeName() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(JSON_FORMAT_NAME);
// no objectTypeName specified
runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
// null can be retrieved
JsonSerializable returnedBean = (JsonSerializable) 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(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
assertNull(typedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest 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(JSON_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);
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetSerializedVariableValueMismatchingTypeName.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueMismatchingTypeName() 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(// < not a valid type name
"Insensible type name.");
runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
try {
runtimeService.getVariable(instance.getId(), "simpleBean");
fail("Exception expected.");
} catch (Exception e) {
// happy path
}
serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(// < not the right type name
JsonSerializationTest.class.getName());
runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
try {
runtimeService.getVariable(instance.getId(), "simpleBean");
fail("Exception expected.");
} catch (Exception e) {
// happy path
}
}
Aggregations