use of org.camunda.bpm.engine.test.Deployment 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.test.Deployment 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.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonValueTest method testGetTypedJsonValue.
@Deployment(resources = ONE_TASK_PROCESS)
public void testGetTypedJsonValue() throws JSONException {
// given
JsonValue jsonValue = jsonValue(jsonString).create();
VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
// when
JsonValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);
// then
SpinJsonNode value = typedValue.getValue();
JSONAssert.assertEquals(jsonString, value.toString(), true);
assertTrue(typedValue.isDeserialized());
assertEquals(JSON, typedValue.getType());
assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
JSONAssert.assertEquals(jsonString, typedValue.getValueSerialized(), true);
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonValueTest method testTransientJsonValue.
@Deployment(resources = ONE_TASK_PROCESS)
public void testTransientJsonValue() throws JSONException {
// given
JsonValue jsonValue = jsonValue(jsonString).setTransient(true).create();
VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
// when
runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
// then
List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
assertEquals(0, variableInstances.size());
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonValueTest method testGetUntypedJsonValue.
@Deployment(resources = ONE_TASK_PROCESS)
public void testGetUntypedJsonValue() throws JSONException {
// given
JsonValue jsonValue = jsonValue(jsonString).create();
VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
// when
SpinJsonNode value = (SpinJsonNode) runtimeService.getVariable(processInstanceId, variableName);
// then
JSONAssert.assertEquals(jsonString, value.toString(), true);
assertEquals(json().getName(), value.getDataFormatName());
}
Aggregations