use of org.camunda.spin.plugin.variable.value.JsonValue 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.spin.plugin.variable.value.JsonValue 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.spin.plugin.variable.value.JsonValue 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());
}
use of org.camunda.spin.plugin.variable.value.JsonValue in project camunda-bpm-platform by camunda.
the class JsonValueTest method testBrokenJsonSerialization.
@Deployment(resources = ONE_TASK_PROCESS)
public void testBrokenJsonSerialization() {
// given
JsonValue value = jsonValue(brokenJsonString).create();
String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
try {
// when
runtimeService.setVariable(processInstanceId, variableName, value);
} catch (Exception e) {
fail("no exception expected");
}
}
use of org.camunda.spin.plugin.variable.value.JsonValue in project camunda-bpm-platform by camunda.
the class JsonValueTest method testFailingDeserialization.
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingDeserialization() {
// given
JsonValue value = jsonValue(brokenJsonString).create();
String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
runtimeService.setVariable(processInstanceId, variableName, value);
try {
// when
runtimeService.getVariable(processInstanceId, variableName);
fail("exception expected");
} catch (ProcessEngineException e) {
// happy path
}
try {
runtimeService.getVariableTyped(processInstanceId, variableName);
fail("exception expected");
} catch (ProcessEngineException e) {
// happy path
}
// However, I can access the serialized value
JsonValue jsonValue = runtimeService.getVariableTyped(processInstanceId, variableName, false);
assertFalse(jsonValue.isDeserialized());
assertEquals(brokenJsonString, jsonValue.getValueSerialized());
// but not the deserialized properties
try {
jsonValue.getValue();
fail("exception expected");
} catch (SpinRuntimeException e) {
}
}
Aggregations