Search in sources :

Example 1 with JodaJsonSerializable

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);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) JodaJsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JodaJsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)1 JodaJsonSerializable (org.camunda.bpm.integrationtest.functional.spin.dataformat.JodaJsonSerializable)1 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1