use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testGetVariableTypedLocal.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testGetVariableTypedLocal() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
// an active case instance
caseService.withCaseDefinition(caseDefinitionId).create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
caseService.withCaseExecution(caseExecutionId).setVariableLocal("aVariableName", "abc").setVariableLocal("anotherVariableName", 999).setVariableLocal("aSerializedObject", Variables.objectValue(Arrays.asList("1", "2")).create()).execute();
// when
StringValue stringValue = caseService.getVariableLocalTyped(caseExecutionId, "aVariableName");
ObjectValue objectValue = caseService.getVariableLocalTyped(caseExecutionId, "aSerializedObject");
ObjectValue serializedObjectValue = caseService.getVariableLocalTyped(caseExecutionId, "aSerializedObject", false);
// then
assertNotNull(stringValue.getValue());
assertNotNull(objectValue.getValue());
assertTrue(objectValue.isDeserialized());
assertEquals(Arrays.asList("1", "2"), objectValue.getValue());
assertFalse(serializedObjectValue.isDeserialized());
assertNotNull(serializedObjectValue.getValueSerialized());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testGetVariableTyped.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testGetVariableTyped() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
// an active case instance
caseService.withCaseDefinition(caseDefinitionId).setVariable("aVariableName", "abc").setVariable("anotherVariableName", 999).setVariable("aSerializedObject", Variables.objectValue(Arrays.asList("1", "2")).create()).create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
// when
StringValue stringValue = caseService.getVariableTyped(caseExecutionId, "aVariableName");
ObjectValue objectValue = caseService.getVariableTyped(caseExecutionId, "aSerializedObject");
ObjectValue serializedObjectValue = caseService.getVariableTyped(caseExecutionId, "aSerializedObject", false);
// then
assertNotNull(stringValue.getValue());
assertNotNull(objectValue.getValue());
assertTrue(objectValue.isDeserialized());
assertEquals(Arrays.asList("1", "2"), objectValue.getValue());
assertFalse(serializedObjectValue.isDeserialized());
assertNotNull(serializedObjectValue.getValueSerialized());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSetJavaObjectNullSerializedObjectTypeName.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectNullSerializedObjectTypeName() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String typeName = "some.type.Name";
// set null value as "serialized" object
runtimeService.setVariable(instance.getId(), "nullObject", serializedObjectValue().serializationDataFormat(JAVA_DATA_FORMAT).objectTypeName(// This time an objectTypeName is provided
typeName).create());
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue deserializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertNotNull(deserializedTypedValue);
assertTrue(deserializedTypedValue.isDeserialized());
assertEquals(JAVA_DATA_FORMAT, deserializedTypedValue.getSerializationDataFormat());
assertNull(deserializedTypedValue.getValue());
assertNull(deserializedTypedValue.getValueSerialized());
assertNull(deserializedTypedValue.getObjectType());
assertEquals(typeName, deserializedTypedValue.getObjectTypeName());
ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false);
assertNotNull(serializedTypedValue);
assertFalse(serializedTypedValue.isDeserialized());
assertEquals(JAVA_DATA_FORMAT, serializedTypedValue.getSerializationDataFormat());
assertNull(serializedTypedValue.getValueSerialized());
assertEquals(typeName, serializedTypedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSetJavaObjectSerialized.
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue(serializedObject).serializationDataFormat(JAVA_DATA_FORMAT).objectTypeName(JavaSerializable.class.getName()).create());
// validate untyped value
JavaSerializable value = (JavaSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(javaSerializable, value);
// validate typed value
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertObjectValueDeserialized(typedValue, javaSerializable);
assertObjectValueSerializedJava(typedValue, javaSerializable);
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class AssertVariableInstancesDelegate method execute.
public void execute(DelegateExecution execution) throws Exception {
// validate integer variable
Integer expectedIntValue = 1234;
assertEquals(expectedIntValue, execution.getVariable("anIntegerVariable"));
assertEquals(expectedIntValue, execution.getVariableTyped("anIntegerVariable").getValue());
assertEquals(ValueType.INTEGER, execution.getVariableTyped("anIntegerVariable").getType());
assertNull(execution.getVariableLocal("anIntegerVariable"));
assertNull(execution.getVariableLocalTyped("anIntegerVariable"));
// set an additional local variable
execution.setVariableLocal("aStringVariable", "aStringValue");
String expectedStringValue = "aStringValue";
assertEquals(expectedStringValue, execution.getVariable("aStringVariable"));
assertEquals(expectedStringValue, execution.getVariableTyped("aStringVariable").getValue());
assertEquals(ValueType.STRING, execution.getVariableTyped("aStringVariable").getType());
assertEquals(expectedStringValue, execution.getVariableLocal("aStringVariable"));
assertEquals(expectedStringValue, execution.getVariableLocalTyped("aStringVariable").getValue());
assertEquals(ValueType.STRING, execution.getVariableLocalTyped("aStringVariable").getType());
SimpleSerializableBean objectValue = (SimpleSerializableBean) execution.getVariable("anObjectValue");
assertNotNull(objectValue);
assertEquals(10, objectValue.getIntProperty());
ObjectValue variableTyped = execution.getVariableTyped("anObjectValue");
assertEquals(10, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
assertEquals(Variables.SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
objectValue = (SimpleSerializableBean) execution.getVariable("anUntypedObjectValue");
assertNotNull(objectValue);
assertEquals(30, objectValue.getIntProperty());
variableTyped = execution.getVariableTyped("anUntypedObjectValue");
assertEquals(30, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
assertEquals(Context.getProcessEngineConfiguration().getDefaultSerializationFormat(), variableTyped.getSerializationDataFormat());
}
Aggregations