use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JodaJsonSerializable in project camunda-bpm-platform by camunda.
the class PaDataFormatConfiguratorJodaTest method testPaLocalJodaConfiguration.
@Test
public void testPaLocalJodaConfiguration() throws JsonProcessingException, IOException {
// given a process instance
final ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
// when setting a variable in the context of a process application
// 10th of January 1970
Date date = new Date(JodaJsonSerializable.ONE_DAY_IN_MILLIS * 10);
JodaJsonSerializable jsonSerializable = new JodaJsonSerializable(new DateTime(date.getTime()));
try {
ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
runtimeService.setVariable(pi.getId(), "jsonSerializable", Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
} finally {
ProcessApplicationContext.clear();
}
// then the process-application-local data format has been used to serialize the value
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "jsonSerializable", false);
String serializedValue = objectValue.getValueSerialized();
String expectedSerializedValue = jsonSerializable.toExpectedJsonString();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
// JsonNode#equals makes a deep comparison
Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
Aggregations