Search in sources :

Example 36 with ObjectValue

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

the class ExecutionRestServiceInteractionTest method testGetLocalObjectVariables.

@Test
public void testGetLocalObjectVariables() {
    // 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(runtimeServiceMock.getVariablesLocalTyped(eq(MockProvider.EXAMPLE_EXECUTION_ID), anyBoolean())).thenReturn(Variables.createVariables().putValueTyped(variableKey, variableValue));
    // when
    given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).then().expect().statusCode(Status.OK.getStatusCode()).body(variableKey + ".value", equalTo(payload)).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(EXECUTION_LOCAL_VARIABLES_URL);
    // then
    verify(runtimeServiceMock).getVariablesLocalTyped(MockProvider.EXAMPLE_EXECUTION_ID, 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)

Example 37 with ObjectValue

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

the class FormServiceTest method testSubmitStartFormDataTypedVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml" })
@Test
public void testSubmitStartFormDataTypedVariables() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    String stringValue = "some string";
    String serializedValue = "some value";
    ProcessInstance processInstance = formService.submitStartForm(procDefId, 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 : 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)

Example 38 with ObjectValue

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

the class FallbackSerializerFactoryTest method testFallbackSerializerDoesNotOverrideRegularSerializer.

@Test
public void testFallbackSerializerDoesNotOverrideRegularSerializer() {
    // given
    // that the process engine is configured with a serializer for a certain format
    // and a fallback serializer factory for the same format
    ProcessEngineConfigurationImpl engineConfiguration = new StandaloneInMemProcessEngineConfiguration().setJdbcUrl("jdbc:h2:mem:camunda-forceclose").setProcessEngineName("engine-forceclose");
    engineConfiguration.setCustomPreVariableSerializers(Arrays.<TypedValueSerializer>asList(new ExampleConstantSerializer()));
    engineConfiguration.setFallbackSerializerFactory(new ExampleSerializerFactory());
    processEngine = engineConfiguration.buildProcessEngine();
    deployOneTaskProcess(processEngine);
    // when setting a variable that no regular serializer can handle
    ObjectValue objectValue = Variables.objectValue("foo").serializationDataFormat(ExampleSerializer.FORMAT).create();
    ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("var", objectValue));
    ObjectValue fetchedValue = processEngine.getRuntimeService().getVariableTyped(pi.getId(), "var", true);
    // then the fallback serializer is used
    Assert.assertNotNull(fetchedValue);
    Assert.assertEquals(ExampleSerializer.FORMAT, fetchedValue.getSerializationDataFormat());
    Assert.assertEquals(ExampleConstantSerializer.DESERIALIZED_VALUE, fetchedValue.getValue());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) Test(org.junit.Test)

Example 39 with ObjectValue

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

the class FallbackSerializerFactoryTest method testFallbackSerializer.

@Test
public void testFallbackSerializer() {
    // given
    // that the process engine is configured with a fallback serializer factory
    ProcessEngineConfigurationImpl engineConfiguration = new StandaloneInMemProcessEngineConfiguration().setJdbcUrl("jdbc:h2:mem:camunda-forceclose").setProcessEngineName("engine-forceclose");
    engineConfiguration.setFallbackSerializerFactory(new ExampleSerializerFactory());
    processEngine = engineConfiguration.buildProcessEngine();
    deployOneTaskProcess(processEngine);
    // when setting a variable that no regular serializer can handle
    ObjectValue objectValue = Variables.objectValue("foo").serializationDataFormat(ExampleSerializer.FORMAT).create();
    ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValueTyped("var", objectValue));
    ObjectValue fetchedValue = processEngine.getRuntimeService().getVariableTyped(pi.getId(), "var", true);
    // then the fallback serializer is used
    Assert.assertNotNull(fetchedValue);
    Assert.assertEquals(ExampleSerializer.FORMAT, fetchedValue.getSerializationDataFormat());
    Assert.assertEquals("foo", fetchedValue.getValue());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) Test(org.junit.Test)

Example 40 with ObjectValue

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

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