use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testRemoveVariable.
@Deployment(resources = ONE_TASK_PROCESS)
public void testRemoveVariable() throws JSONException {
// given a serialized json variable
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);
// when
runtimeService.removeVariable(instance.getId(), "simpleBean");
// then
assertNull(runtimeService.getVariable(instance.getId(), "simpleBean"));
assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean"));
assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean", false));
}
use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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.variable.value.builder.SerializedObjectValueBuilder 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
}
}
use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testSetSerializedVariableValueNull.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNull() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(JsonSerializable.class.getCanonicalName());
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());
assertEquals(JsonSerializable.class.getCanonicalName(), typedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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());
}
Aggregations