Java Code Examples for org.camunda.spin.Spin#JSON

The following examples show how to use org.camunda.spin.Spin#JSON . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonTreeReadPropertyScriptTest.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@Test
@Script
@ScriptVariable(name = "input", file = EXAMPLE_JSON_FILE_NAME)
public void shouldBeSameAsJavaValue() {

  SpinJsonNode node = Spin.JSON(EXAMPLE_JSON);
  SpinJsonNode childNode = node.prop("orderDetails");

  SpinJsonNode property1 = node.prop("order");
  SpinJsonNode property2 = childNode.prop("price");
  SpinJsonNode property3 = node.prop("active");

  String javaVariable1 = property1.stringValue();
  Number javaVariable2 = property2.numberValue();
  Boolean javaVariable3 = property3.boolValue();

  String scriptVariable1 = script.getVariable("stringValue");
  Number scriptVariable2 = script.getVariable("numberValue");
  Boolean scriptVariable3 = script.getVariable("boolValue");

  assertThat(javaVariable1).isEqualTo(scriptVariable1);
  assertThat(javaVariable2).isEqualTo(scriptVariable2);
  assertThat(javaVariable3).isEqualTo(scriptVariable3);
}
 
Example 2
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapNestedCamundaSpinJSONObjectAsContext() {

  // given
  Map<String, Val> nestedMap = new HashMap<>();
  nestedMap.put("city", new ValString("Berlin"));
  nestedMap.put("zipCode", valueMapper.toVal(10961));

  Map<String, Val> contextMap = new HashMap<>();
  contextMap.put("customer", new ValString("Kermit"));
  contextMap.put("address", valueMapper.toVal(nestedMap));

  ValContext context = (ValContext) valueMapper.toVal(contextMap);
  SpinJsonNode json = Spin.JSON("{" +
                                    "\"customer\": \"Kermit\", " +
                                    "\"address\": {\"" +
                                      "city\": \"Berlin\", " +
                                    "\"zipCode\": 10961}}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example 3
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinJSONObjectAsContext() {
  // given
  Map<String, Val> map = new HashMap<>();
  map.put("customer", new ValString("Kermit"));
  map.put("language", new ValString("en"));
  ValContext context = (ValContext) valueMapper.toVal(map);
  SpinJsonNode json = Spin.JSON("{\"customer\": \"Kermit\", \"language\": \"en\"}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}
 
Example 4
Source File: SpinValueMapperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMapCamundaSpinJSONarrayAsList() {
  // given
  List<Val> list = Arrays.asList(new ValString("Kermit"), new ValString("Waldo"));
  ValList feelList = (ValList) valueMapper.toVal(list);
  ValContext context = (ValContext) valueMapper.toVal(Collections.singletonMap("customer", feelList));
  SpinJsonNode json = Spin.JSON("{\"customer\": [\"Kermit\", \"Waldo\"]}");

  // when
  Val value = valueMapper.toVal(json);

  // then
  assertThat(value).isEqualTo(context);
}