Search in sources :

Example 1 with SerializedObjectValueBuilder

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

the class JsonSerializationTest method testRemoveVariable.

@Deployment(resources = ONE_TASK_PROCESS)
public void testRemoveVariable() throws JSONException {
    // given a serialized json variable
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, true);
    String beanAsJson = bean.toExpectedJsonString();
    SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // when
    runtimeService.removeVariable(instance.getId(), "simpleBean");
    // then
    assertNull(runtimeService.getVariable(instance.getId(), "simpleBean"));
    assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean"));
    assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean", false));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with SerializedObjectValueBuilder

use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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 3 with SerializedObjectValueBuilder

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

the class JsonSerializationTest method testSetSerializedVariableValueMismatchingTypeName.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValueMismatchingTypeName() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, true);
    String beanAsJson = bean.toExpectedJsonString();
    SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(// < not a valid type name
    "Insensible type name.");
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    try {
        runtimeService.getVariable(instance.getId(), "simpleBean");
        fail("Exception expected.");
    } catch (Exception e) {
    // happy path
    }
    serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(// < not the right type name
    JsonSerializationTest.class.getName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    try {
        runtimeService.getVariable(instance.getId(), "simpleBean");
        fail("Exception expected.");
    } catch (Exception e) {
    // happy path
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) JSONException(org.json.JSONException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with SerializedObjectValueBuilder

use of org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder 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 5 with SerializedObjectValueBuilder

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

the class JsonSerializationTest method testSetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValue() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, true);
    String beanAsJson = bean.toExpectedJsonString();
    SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // java object can be retrieved
    JsonSerializable returnedBean = (JsonSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertEquals(bean, returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertEquals(bean, typedValue.getValue());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(bean.getClass().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)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 SerializedObjectValueBuilder (org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder)11 Variables.serializedObjectValue (org.camunda.bpm.engine.variable.Variables.serializedObjectValue)6 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 JSONException (org.json.JSONException)2