use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JPAVariableTest method testFailSerializationForUnknownSerializedValueType.
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailSerializationForUnknownSerializedValueType() throws IOException {
// given
JavaSerializable pojo = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(pojo);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);
ObjectValue serializedObjectValue = Variables.serializedObjectValue(serializedObject).serializationDataFormat(SerializationDataFormats.JAVA).objectTypeName(pojo.getClass().getName()).create();
VariableMap variables = Variables.createVariables().putValueTyped("var", serializedObjectValue);
// when
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
// then
JavaSerializable returnedPojo = (JavaSerializable) runtimeService.getVariable(processInstance.getId(), "var");
assertEquals(pojo, returnedPojo);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class PaDataFormatConfiguratorJodaTest method testPaLocalJodaConfiguration.
@Test
public void testPaLocalJodaConfiguration() throws JsonProcessingException, IOException {
// given a process instance
final ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
// when setting a variable in the context of a process application
// 10th of January 1970
Date date = new Date(JodaJsonSerializable.ONE_DAY_IN_MILLIS * 10);
JodaJsonSerializable jsonSerializable = new JodaJsonSerializable(new DateTime(date.getTime()));
try {
ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
runtimeService.setVariable(pi.getId(), "jsonSerializable", Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
} finally {
ProcessApplicationContext.clear();
}
// then the process-application-local data format has been used to serialize the value
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "jsonSerializable", false);
String serializedValue = objectValue.getValueSerialized();
String expectedSerializedValue = jsonSerializable.toExpectedJsonString();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
// JsonNode#equals makes a deep comparison
Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class PaDataFormatProviderTest method customFormatCanBeUsedForVariableSerialization.
/**
* Tests that
* 1) a serialized value can be set OUT OF process application context
* even if the data format is not available (using the fallback serializer)
* 2) and that this value can be deserialized IN process application context
* by using the PA-local serializer
*/
@Test
public void customFormatCanBeUsedForVariableSerialization() {
final ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables().putValue("serializedObject", serializedObjectValue("foo").serializationDataFormat(FooDataFormat.NAME).objectTypeName(Foo.class.getName())));
ObjectValue objectValue = null;
try {
ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
objectValue = runtimeService.getVariableTyped(pi.getId(), "serializedObject", true);
} finally {
ProcessApplicationContext.clear();
}
Object value = objectValue.getValue();
Assert.assertNotNull(value);
Assert.assertTrue(value instanceof Foo);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class PaSpinSupportTest method testJacksonBug146AsVariable.
@Test
public void testJacksonBug146AsVariable() {
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/integrationtest/functional/spin/jackson146.json");
String jackson146 = SpinIoUtil.inputStreamAsString(resourceAsStream);
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables().putValue("jackson146", serializedObjectValue(jackson146).serializationDataFormat("application/json").objectTypeName(HashMap.class.getName())));
// file has 4000 characters in length a
// 20 characters per repeated JSON object
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "jackson146", true);
HashMap<String, List<Object>> map = (HashMap<String, List<Object>>) objectValue.getValue();
assertEquals(200, map.get("abcdef").size());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class FormServiceTest method testSubmitTaskFormDataTypedVariables.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml" })
@Test
public void testSubmitTaskFormDataTypedVariables() {
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
ProcessInstance processInstance = formService.submitStartForm(procDefId, createVariables());
Task task = taskService.createTaskQuery().singleResult();
String stringValue = "some string";
String serializedValue = "some value";
formService.submitTaskForm(task.getId(), 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());
}
Aggregations