Search in sources :

Example 1 with JsonSerializable

use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable in project camunda-bpm-platform by camunda.

the class PaDataFormatConfiguratorTest method testExecutionVariableImplicitObjectValueUpdate.

/**
 * Tests that an implicit object value update happens in the context of the
 * process application.
 */
@Test
public void testExecutionVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
    // given a process instance and a task
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitProcessVariableUpdate");
    // when setting a variable such that the process-application-local dataformat applies
    // 10th of January 1970
    Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
    JsonSerializable jsonSerializable = new JsonSerializable(date);
    try {
        ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
        runtimeService.setVariable(pi.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
    } finally {
        ProcessApplicationContext.clear();
    }
    // and triggering an implicit update of the object value variable
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    taskService.complete(task.getId());
    // then the process-application-local format was used for making the update
    ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, false);
    ImplicitObjectValueUpdateHandler.addADay(jsonSerializable);
    String serializedValue = objectValue.getValueSerialized();
    String expectedSerializedValue = jsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
    JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
    // JsonNode#equals makes a deep comparison
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
    // and it is also correct in the history
    HistoricVariableInstance historicObjectValue = historyService.createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName(ImplicitObjectValueUpdateHandler.VARIABLE_NAME).disableCustomObjectDeserialization().singleResult();
    serializedValue = ((ObjectValue) historicObjectValue.getTypedValue()).getValueSerialized();
    actualJsonTree = objectMapper.readTree(serializedValue);
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 2 with JsonSerializable

use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable in project camunda-bpm-platform by camunda.

the class PaContextSwitchTest method testNoContextSwitchOnInnerCommand.

/**
 * This test ensures that when the {@link ProcessApplicationContext} API is used,
 * the context switch is only performed for outer-most command and not if a second, nested
 * command is executed; => in nested commands, the engine is already in the correct context
 */
@Test
@OperateOnDeployment("pa1")
public void testNoContextSwitchOnInnerCommand() throws Exception {
    ProcessInstance pi = withProcessApplicationContext(new Callable<ProcessInstance>() {

        @Override
        public ProcessInstance call() throws Exception {
            return runtimeService.startProcessInstanceByKey("process");
        }
    }, "pa2");
    JsonSerializable expectedJsonSerializable = RuntimeServiceDelegate.createJsonSerializable();
    String expectedJsonString = expectedJsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
    SerializableValue serializedValue = runtimeService.getVariableTyped(pi.getId(), RuntimeServiceDelegate.VARIABLE_NAME, false);
    String actualJsonString = serializedValue.getValueSerialized();
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode actualJsonTree = objectMapper.readTree(actualJsonString);
    JsonNode expectedJsonTree = objectMapper.readTree(expectedJsonString);
    // JsonNode#equals makes a deep comparison
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
Also used : SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 3 with JsonSerializable

use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable in project camunda-bpm-platform by camunda.

the class PaDataFormatConfiguratorTest method testPaLocalFormatDoesNotApply.

/**
 * Tests that the PA-local format does not apply if the value is set outside of the context
 * of the process application
 */
@Test
public void testPaLocalFormatDoesNotApply() throws JsonProcessingException, IOException {
    // given a process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
    // when setting a variable without a process-application cotnext
    // 10th of January 1970
    Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
    JsonSerializable jsonSerializable = new JsonSerializable(date);
    runtimeService.setVariable(pi.getId(), "jsonSerializable", Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
    // then the global data format is applied
    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) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 4 with JsonSerializable

use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable in project camunda-bpm-platform by camunda.

the class PaDataFormatConfiguratorTest method testPaLocalFormatApplies.

/**
 * Tests that the PA-local data format applies when a variable is set in
 * the context of it
 */
@Test
public void testPaLocalFormatApplies() 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(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
    JsonSerializable jsonSerializable = new JsonSerializable(date);
    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(JsonDataFormatConfigurator.DATE_FORMAT);
    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) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 5 with JsonSerializable

use of org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable in project camunda-bpm-platform by camunda.

the class PaDataFormatConfiguratorTest method testTaskVariableImplicitObjectValueUpdate.

@Test
public void testTaskVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
    // given a process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitTaskVariableUpdate");
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    // when setting a variable such that the process-application-local dataformat applies
    // 10th of January 1970
    Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
    JsonSerializable jsonSerializable = new JsonSerializable(date);
    try {
        ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
        taskService.setVariableLocal(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
    } finally {
        ProcessApplicationContext.clear();
    }
    // and triggering an implicit update of the object value variable
    taskService.setAssignee(task.getId(), "foo");
    // then the process-application-local format was used for making the update
    ObjectValue objectValue = taskService.getVariableTyped(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, false);
    ImplicitObjectValueUpdateHandler.addADay(jsonSerializable);
    String serializedValue = objectValue.getValueSerialized();
    String expectedSerializedValue = jsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
    JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
    // JsonNode#equals makes a deep comparison
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
    // and it is also correct in the history
    HistoricVariableInstance historicObjectValue = historyService.createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName(ImplicitObjectValueUpdateHandler.VARIABLE_NAME).disableCustomObjectDeserialization().singleResult();
    serializedValue = ((ObjectValue) historicObjectValue.getTypedValue()).getValueSerialized();
    actualJsonTree = objectMapper.readTree(serializedValue);
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 JsonSerializable (org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable)5 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)5 Test (org.junit.Test)5 Date (java.util.Date)4 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)4 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)2 Task (org.camunda.bpm.engine.task.Task)2 SerializableValue (org.camunda.bpm.engine.variable.value.SerializableValue)1 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)1