Search in sources :

Example 1 with CustomSerializable

use of org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testDisableCustomObjectDeserialization.

@Test
public void testDisableCustomObjectDeserialization() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customSerializable", new CustomSerializable());
    variables.put("failingSerializable", new FailingSerializable());
    Task task = taskService.newTask();
    taskService.saveTask(task);
    taskService.setVariablesLocal(task.getId(), variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().disableCustomObjectDeserialization();
    // then
    List<VariableInstance> results = query.list();
    // both variables are not deserialized, but their serialized values are available
    assertEquals(2, results.size());
    for (VariableInstance variableInstance : results) {
        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());
    }
    // delete task
    taskService.deleteTask(task.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) HashMap(java.util.HashMap) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 2 with CustomSerializable

use of org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable in project camunda-bpm-platform by camunda.

the class FullHistoryTest method testDisableCustomObjectDeserialization.

@Test
public void testDisableCustomObjectDeserialization() {
    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);
    List<HistoricDetail> results = historyService.createHistoricDetailQuery().disableBinaryFetching().disableCustomObjectDeserialization().variableUpdates().list();
    // both variables are not deserialized, but their serialized values are available
    assertEquals(2, results.size());
    for (HistoricDetail update : results) {
        HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) update;
        assertNull(variableUpdate.getErrorMessage());
        ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue();
        assertNotNull(typedValue);
        assertFalse(typedValue.isDeserialized());
        // cannot access the deserialized value
        try {
            typedValue.getValue();
        } catch (IllegalStateException e) {
            Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Object is not deserialized"));
        }
        assertNotNull(typedValue.getValueSerialized());
    }
    taskService.deleteTask(newTask.getId(), true);
}
Also used : FailingSerializable(org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) HashMap(java.util.HashMap) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable) Test(org.junit.Test)

Example 3 with CustomSerializable

use of org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryTest method testSerializableErrorMessage.

@Test
public void testSerializableErrorMessage() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customSerializable", new CustomSerializable());
    variables.put("failingSerializable", new FailingSerializable());
    Task task = taskService.newTask();
    taskService.saveTask(task);
    taskService.setVariablesLocal(task.getId(), variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    // then
    List<VariableInstance> results = query.list();
    // both variables are fetched
    assertEquals(2, results.size());
    for (VariableInstance variableInstance : results) {
        if (variableInstance.getName().equals("customSerializable")) {
            assertNotNull(variableInstance.getValue());
            assertTrue(variableInstance.getValue() instanceof CustomSerializable);
        }
        if (variableInstance.getName().equals("failingSerializable")) {
            // no value was fetched
            assertNull(variableInstance.getValue());
            // error message is present
            assertNotNull(variableInstance.getErrorMessage());
        }
    }
    // delete task
    taskService.deleteTask(task.getId(), true);
}
Also used : FailingSerializable(org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable) Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) CustomSerializable(org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 4 with CustomSerializable

use of org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable 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 5 with CustomSerializable

use of org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable 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)

Aggregations

Task (org.camunda.bpm.engine.task.Task)5 CustomSerializable (org.camunda.bpm.engine.test.api.runtime.util.CustomSerializable)5 FailingSerializable (org.camunda.bpm.engine.test.api.runtime.util.FailingSerializable)5 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)2 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)2 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)1 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)1