Search in sources :

Example 91 with ObjectValue

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

the class HistoricVariableInstanceTest method testDisableCustomObjectDeserializationNativeQuery.

public void testDisableCustomObjectDeserializationNativeQuery() {
    // given
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customSerializable", new CustomSerializable());
    variables.put("failingSerializable", new FailingSerializable());
    taskService.setVariables(newTask.getId(), variables);
    // when
    List<HistoricVariableInstance> variableInstances = historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * from " + managementService.getTableName(HistoricVariableInstance.class)).disableCustomObjectDeserialization().list();
    // then
    assertEquals(2, variableInstances.size());
    for (HistoricVariableInstance variableInstance : variableInstances) {
        assertNull(variableInstance.getErrorMessage());
        ObjectValue typedValue = (ObjectValue) variableInstance.getTypedValue();
        assertNotNull(typedValue);
        assertFalse(typedValue.isDeserialized());
        // cannot access the deserialized value
        try {
            typedValue.getValue();
        } catch (IllegalStateException e) {
            assertTextPresent("Object is not deserialized", e.getMessage());
        }
        assertNotNull(typedValue.getValueSerialized());
    }
    taskService.deleteTask(newTask.getId(), true);
}
Also used : FailingSerializable(org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable) Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable)

Example 92 with ObjectValue

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

the class HistoricVariableInstanceTest method testDisableCustomObjectDeserialization.

public void testDisableCustomObjectDeserialization() {
    // given
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customSerializable", new CustomSerializable());
    variables.put("failingSerializable", new FailingSerializable());
    taskService.setVariables(newTask.getId(), variables);
    // when
    List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery().disableCustomObjectDeserialization().list();
    // then
    assertEquals(2, variableInstances.size());
    for (HistoricVariableInstance variableInstance : variableInstances) {
        assertNull(variableInstance.getErrorMessage());
        ObjectValue typedValue = (ObjectValue) variableInstance.getTypedValue();
        assertNotNull(typedValue);
        assertFalse(typedValue.isDeserialized());
        // cannot access the deserialized value
        try {
            typedValue.getValue();
        } catch (IllegalStateException e) {
            assertTextPresent("Object is not deserialized", e.getMessage());
        }
        assertNotNull(typedValue.getValueSerialized());
    }
    taskService.deleteTask(newTask.getId(), true);
}
Also used : FailingSerializable(org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable) Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable)

Example 93 with ObjectValue

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

the class ProcessInstanceRestServiceInteractionTest method testGetObjectVariablesSerialized.

@Test
public void testGetObjectVariablesSerialized() {
    // given
    String variableKey = "aVariableId";
    ObjectValue variableValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("application/json").objectTypeName(ArrayList.class.getName()).create();
    when(runtimeServiceMock.getVariablesTyped(eq(EXAMPLE_PROCESS_INSTANCE_ID), anyBoolean())).thenReturn(Variables.createVariables().putValueTyped(variableKey, variableValue));
    // when
    given().pathParam("id", EXAMPLE_PROCESS_INSTANCE_ID).queryParam("deserializeValues", false).then().expect().statusCode(Status.OK.getStatusCode()).body(variableKey + ".value", equalTo("a serialized value")).body(variableKey + ".type", equalTo("Object")).body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")).body(variableKey + ".valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())).when().get(PROCESS_INSTANCE_VARIABLES_URL);
    // then
    verify(runtimeServiceMock).getVariablesTyped(EXAMPLE_PROCESS_INSTANCE_ID, false);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) EqualsObjectValue(org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue) Test(org.junit.Test)

Example 94 with ObjectValue

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

the class ProcessInstanceRestServiceInteractionTest method testGetSingleLocalObjectVariableSerialized.

@Test
public void testGetSingleLocalObjectVariableSerialized() {
    // given
    String variableKey = "aVariableId";
    ObjectValue variableValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("application/json").objectTypeName(ArrayList.class.getName()).create();
    when(runtimeServiceMock.getVariableTyped(eq(EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    // when
    given().pathParam("id", EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey).queryParam("deserializeValue", false).then().expect().statusCode(Status.OK.getStatusCode()).body("value", equalTo("a serialized value")).body("type", equalTo("Object")).body("valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")).body("valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())).when().get(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
    // then
    verify(runtimeServiceMock).getVariableTyped(EXAMPLE_PROCESS_INSTANCE_ID, variableKey, false);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) EqualsObjectValue(org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue) Test(org.junit.Test)

Example 95 with ObjectValue

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

the class TaskVariableLocalRestResourceInteractionTest method testGetSingleLocalObjectVariable.

@Test
public void testGetSingleLocalObjectVariable() {
    // given
    String variableKey = "aVariableId";
    List<String> payload = Arrays.asList("a", "b");
    ObjectValue variableValue = MockObjectValue.fromObjectValue(Variables.objectValue(payload).serializationDataFormat("application/json").create()).objectTypeName(ArrayList.class.getName()).serializedValue(// this should differ from the serialized json
    "a serialized value");
    when(taskServiceMock.getVariableLocalTyped(eq(EXAMPLE_TASK_ID), eq(variableKey), anyBoolean())).thenReturn(variableValue);
    // when
    given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey).then().expect().statusCode(Status.OK.getStatusCode()).body("value", equalTo(payload)).body("type", equalTo("Object")).body("valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json")).body("valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ArrayList.class.getName())).when().get(SINGLE_TASK_SINGLE_VARIABLE_URL);
    // then
    verify(taskServiceMock).getVariableLocalTyped(EXAMPLE_TASK_ID, variableKey, true);
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) EqualsObjectValue(org.camunda.bpm.engine.rest.helper.variable.EqualsObjectValue) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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