Search in sources :

Example 76 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class JPAVariableTest method testFailSerializationForUnknownSerializedValueType.

@Deployment(resources = ONE_TASK_PROCESS)
public void testFailSerializationForUnknownSerializedValueType() throws IOException {
    // given
    JavaSerializable pojo = new JavaSerializable("foo");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(pojo);
    String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);
    ObjectValue serializedObjectValue = Variables.serializedObjectValue(serializedObject).serializationDataFormat(SerializationDataFormats.JAVA).objectTypeName(pojo.getClass().getName()).create();
    VariableMap variables = Variables.createVariables().putValueTyped("var", serializedObjectValue);
    // when
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // then
    JavaSerializable returnedPojo = (JavaSerializable) runtimeService.getVariable(processInstance.getId(), "var");
    assertEquals(pojo, returnedPojo);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JavaSerializable(org.camunda.bpm.engine.test.api.variables.JavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 77 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue 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)

Example 78 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class PaDataFormatProviderTest method customFormatCanBeUsedForVariableSerialization.

/**
 * Tests that
 * 1) a serialized value can be set OUT OF process application context
 *   even if the data format is not available (using the fallback serializer)
 * 2) and that this value can be deserialized IN process application context
 *   by using the PA-local serializer
 */
@Test
public void customFormatCanBeUsedForVariableSerialization() {
    final ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables().putValue("serializedObject", serializedObjectValue("foo").serializationDataFormat(FooDataFormat.NAME).objectTypeName(Foo.class.getName())));
    ObjectValue objectValue = null;
    try {
        ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
        objectValue = runtimeService.getVariableTyped(pi.getId(), "serializedObject", true);
    } finally {
        ProcessApplicationContext.clear();
    }
    Object value = objectValue.getValue();
    Assert.assertNotNull(value);
    Assert.assertTrue(value instanceof Foo);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) Foo(org.camunda.bpm.integrationtest.functional.spin.dataformat.Foo) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 79 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class PaSpinSupportTest method testJacksonBug146AsVariable.

@Test
public void testJacksonBug146AsVariable() {
    InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/integrationtest/functional/spin/jackson146.json");
    String jackson146 = SpinIoUtil.inputStreamAsString(resourceAsStream);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables().putValue("jackson146", serializedObjectValue(jackson146).serializationDataFormat("application/json").objectTypeName(HashMap.class.getName())));
    // file has 4000 characters in length a
    // 20 characters per repeated JSON object
    ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "jackson146", true);
    HashMap<String, List<Object>> map = (HashMap<String, List<Object>>) objectValue.getValue();
    assertEquals(200, map.get("abcdef").size());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) List(java.util.List) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 80 with ObjectValue

use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.

the class FormServiceTest method testSubmitTaskFormDataTypedVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml" })
@Test
public void testSubmitTaskFormDataTypedVariables() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessInstance processInstance = formService.submitStartForm(procDefId, createVariables());
    Task task = taskService.createTaskQuery().singleResult();
    String stringValue = "some string";
    String serializedValue = "some value";
    formService.submitTaskForm(task.getId(), createVariables().putValueTyped("boolean", booleanValue(null)).putValueTyped("string", stringValue(stringValue)).putValueTyped("serializedObject", serializedObjectValue(serializedValue).objectTypeName(String.class.getName()).serializationDataFormat(Variables.SerializationDataFormats.JAVA).create()).putValueTyped("object", objectValue(serializedValue).create()));
    VariableMap variables = runtimeService.getVariablesTyped(processInstance.getId(), false);
    assertEquals(booleanValue(null), variables.getValueTyped("boolean"));
    assertEquals(stringValue(stringValue), variables.getValueTyped("string"));
    assertNotNull(variables.<ObjectValue>getValueTyped("serializedObject").getValueSerialized());
    assertNotNull(variables.<ObjectValue>getValueTyped("object").getValueSerialized());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)99 Test (org.junit.Test)58 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)53 Deployment (org.camunda.bpm.engine.test.Deployment)46 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)36 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)29 EqualsObjectValue (org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 Matchers.anyString (org.mockito.Matchers.anyString)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectOutputStream (java.io.ObjectOutputStream)9 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)8 Task (org.camunda.bpm.engine.task.Task)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 HashMap (java.util.HashMap)6 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)6 FailingJavaSerializable (org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 SerializedObjectValueBuilder (org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder)6