Search in sources :

Example 1 with JsonValue

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);
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with JsonValue

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());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with JsonValue

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());
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with JsonValue

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");
    }
}
Also used : JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) SpinRuntimeException(org.camunda.spin.SpinRuntimeException) JSONException(org.json.JSONException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with JsonValue

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) {
    }
}
Also used : SpinRuntimeException(org.camunda.spin.SpinRuntimeException) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Deployment (org.camunda.bpm.engine.test.Deployment)6 JsonValue (org.camunda.spin.plugin.variable.value.JsonValue)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 SpinRuntimeException (org.camunda.spin.SpinRuntimeException)2 SpinJsonNode (org.camunda.spin.json.SpinJsonNode)2 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)1 Task (org.camunda.bpm.engine.task.Task)1 JSONException (org.json.JSONException)1