Search in sources :

Example 21 with ObjectValue

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

the class JsonSerializationTest method testSetSerializedVariableValueNullNoTypeName.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNullNoTypeName() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(JSON_FORMAT_NAME);
    // no objectTypeName specified
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // null can be retrieved
    JsonSerializable returnedBean = (JsonSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertNull(returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertNull(typedValue.getValue());
    assertNull(typedValue.getValueSerialized());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertNull(typedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 22 with ObjectValue

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

the class JsonSerializationTest method testSetJavaOjectNullDeserialized.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaOjectNullDeserialized() throws Exception {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // set null value as "deserialized" object
    runtimeService.setVariable(instance.getId(), "nullObject", objectValue(null).serializationDataFormat(JSON_FORMAT_NAME).create());
    // get null value via untyped api
    assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
    // get null via typed api
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
    assertObjectValueDeserializedNull(typedValue);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 23 with ObjectValue

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

the class JsonSerializationTest method testSetSerializedVariableValueNull.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueNull() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    SerializedObjectValueBuilder serializedValue = serializedObjectValue().serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(JsonSerializable.class.getCanonicalName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // null can be retrieved
    JsonSerializable returnedBean = (JsonSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertNull(returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertNull(typedValue.getValue());
    assertNull(typedValue.getValueSerialized());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(JsonSerializable.class.getCanonicalName(), typedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 24 with ObjectValue

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

the class JsonSerializationTest method testListSerializationAsJson.

@Deployment(resources = ONE_TASK_PROCESS)
public void testListSerializationAsJson() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    List<JsonSerializable> beans = new ArrayList<JsonSerializable>();
    for (int i = 0; i < 20; i++) {
        beans.add(new JsonSerializable("a String" + i, 42 + i, true));
    }
    runtimeService.setVariable(instance.getId(), "simpleBeans", objectValue(beans).serializationDataFormat(JSON_FORMAT_NAME).create());
    // validate untyped value
    Object value = runtimeService.getVariable(instance.getId(), "simpleBeans");
    assertEquals(beans, value);
    // validate typed value
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBeans");
    assertEquals(ValueType.OBJECT, typedValue.getType());
    assertEquals(beans, typedValue.getValue());
    assertTrue(typedValue.isDeserialized());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertNotNull(typedValue.getObjectTypeName());
    JSONAssert.assertEquals(toExpectedJsonArray(beans), new String(typedValue.getValueSerialized()), true);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ArrayList(java.util.ArrayList) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 25 with ObjectValue

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

the class JsonSerializationTest method testGetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetSerializedVariableValue() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, true);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
    String serializedValue = typedValue.getValueSerialized();
    JSONAssert.assertEquals(bean.toExpectedJsonString(), serializedValue, true);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) 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