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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations