Search in sources :

Example 1 with SpinJsonNode

use of org.camunda.spin.json.SpinJsonNode 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 SpinJsonNode

use of org.camunda.spin.json.SpinJsonNode 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 3 with SpinJsonNode

use of org.camunda.spin.json.SpinJsonNode in project camunda-bpm-platform by camunda.

the class SpinFunctionMapperTest method testSpin_JSON_Available.

public void testSpin_JSON_Available() {
    SpinJsonNode spinJsonEl = executeExpression("${ JSON('" + jsonString + "') }");
    assertNotNull(spinJsonEl);
    assertEquals("bar", spinJsonEl.prop("foo").stringValue());
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode)

Example 4 with SpinJsonNode

use of org.camunda.spin.json.SpinJsonNode in project camunda-bpm-platform by camunda.

the class PaSpinSupportTest method testJacksonBug146.

@Test
public void testJacksonBug146() {
    InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/integrationtest/functional/spin/jackson146.json");
    String jackson146 = SpinIoUtil.inputStreamAsString(resourceAsStream);
    // this should not fail
    SpinJsonNode node = JSON(jackson146);
    // file has 4000 characters in length a
    // 20 characters per repeated JSON object
    assertEquals(200, node.prop("abcdef").elements().size());
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode) InputStream(java.io.InputStream) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 5 with SpinJsonNode

use of org.camunda.spin.json.SpinJsonNode in project camunda-bpm-platform by camunda.

the class SpinJsonPathDelegate method execute.

@Override
public void execute(DelegateExecution execution) throws Exception {
    String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
    SpinJsonNode spinJsonNode = JSON(json).jsonPath("$.child[0]").element();
    if (spinJsonNode == null) {
        throw new RuntimeException("Unable to evalute jsonpath");
    }
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode)

Aggregations

SpinJsonNode (org.camunda.spin.json.SpinJsonNode)5 Deployment (org.camunda.bpm.engine.test.Deployment)2 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 JsonValue (org.camunda.spin.plugin.variable.value.JsonValue)2 InputStream (java.io.InputStream)1 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)1 Test (org.junit.Test)1