use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class MockVariableInstanceBuilder method build.
protected <T extends VariableInstance> T build(T mockVariable) {
when(mockVariable.getId()).thenReturn(id);
when(mockVariable.getName()).thenReturn(name);
when(mockVariable.getTypeName()).thenReturn(typedValue.getType().getName());
if (ObjectValue.class.isAssignableFrom(typedValue.getClass())) {
ObjectValue objectValue = (ObjectValue) typedValue;
if (objectValue.isDeserialized()) {
when(mockVariable.getValue()).thenReturn(typedValue.getValue());
} else {
when(mockVariable.getValue()).thenReturn(null);
}
} else {
when(mockVariable.getValue()).thenReturn(typedValue.getValue());
}
when(mockVariable.getTypedValue()).thenReturn(typedValue);
when(mockVariable.getProcessInstanceId()).thenReturn(processInstanceId);
when(mockVariable.getExecutionId()).thenReturn(executionId);
when(mockVariable.getCaseInstanceId()).thenReturn(caseInstanceId);
when(mockVariable.getCaseExecutionId()).thenReturn(caseExecutionId);
when(mockVariable.getTaskId()).thenReturn(taskId);
when(mockVariable.getActivityInstanceId()).thenReturn(activityInstanceId);
when(mockVariable.getTenantId()).thenReturn(tenantId);
when(mockVariable.getErrorMessage()).thenReturn(errorMessage);
return mockVariable;
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class HistoricDecisionInstanceSerializationTest method testListJsonProperty.
@Deployment(resources = { "org/camunda/spin/plugin/DecisionSingleOutput.dmn11.xml" })
public void testListJsonProperty() {
JsonListSerializable<String> list = new JsonListSerializable<String>();
list.addElement("foo");
ObjectValue objectValue = Variables.objectValue(list).serializationDataFormat(DataFormats.JSON_DATAFORMAT_NAME).create();
VariableMap variables = Variables.createVariables().putValueTyped("input1", objectValue);
decisionService.evaluateDecisionTableByKey("testDecision", variables);
HistoricDecisionInstance testDecision = historyService.createHistoricDecisionInstanceQuery().decisionDefinitionKey("testDecision").includeInputs().includeOutputs().singleResult();
assertNotNull(testDecision);
List<HistoricDecisionInputInstance> inputs = testDecision.getInputs();
assertEquals(1, inputs.size());
HistoricDecisionInputInstance inputInstance = inputs.get(0);
assertEquals(list.getListProperty(), inputInstance.getValue());
List<HistoricDecisionOutputInstance> outputs = testDecision.getOutputs();
assertEquals(1, outputs.size());
HistoricDecisionOutputInstance outputInstance = outputs.get(0);
assertEquals(list.getListProperty(), outputInstance.getValue());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class HistoricVariableJsonSerializationTest method testSelectHistoricSerializedValuesUpdate.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricSerializedValuesUpdate() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, false);
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));
if (ProcessEngineConfiguration.HISTORY_FULL.equals(processEngineConfiguration.getHistory())) {
HistoricVariableUpdate historicUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().singleResult();
assertNotNull(historicUpdate.getValue());
assertNull(historicUpdate.getErrorMessage());
assertEquals(ValueType.OBJECT.getName(), historicUpdate.getTypeName());
assertEquals(ValueType.OBJECT.getName(), historicUpdate.getVariableTypeName());
JsonSerializable historyValue = (JsonSerializable) historicUpdate.getValue();
assertEquals(bean.getStringProperty(), historyValue.getStringProperty());
assertEquals(bean.getIntProperty(), historyValue.getIntProperty());
assertEquals(bean.getBooleanProperty(), historyValue.getBooleanProperty());
ObjectValue typedValue = (ObjectValue) historicUpdate.getTypedValue();
assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
JSONAssert.assertEquals(bean.toExpectedJsonString(), new String(typedValue.getValueSerialized()), true);
assertEquals(JsonSerializable.class.getName(), typedValue.getObjectTypeName());
}
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testSerializationAsJava.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationAsJava() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable bean = new JavaSerializable("a String", 42, true);
// request object to be serialized as Java
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
// validate untyped value
Object value = runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(bean, value);
// validate typed value
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertEquals(ValueType.OBJECT, typedValue.getType());
assertTrue(typedValue.isDeserialized());
assertEquals(bean, typedValue.getValue());
assertEquals(bean, typedValue.getValue(JavaSerializable.class));
assertEquals(JavaSerializable.class, typedValue.getObjectType());
assertEquals(Variables.SerializationDataFormats.JAVA.getName(), typedValue.getSerializationDataFormat());
assertEquals(JavaSerializable.class.getName(), typedValue.getObjectTypeName());
}
use of org.camunda.bpm.engine.variable.value.ObjectValue in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testImplicitlyUpdateEmptyList.
/**
* CAM-3222
*/
@Deployment(resources = SERVICE_TASK_PROCESS)
public void testImplicitlyUpdateEmptyList() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("serviceTaskProcess", Variables.createVariables().putValueTyped("listVar", Variables.objectValue(new ArrayList<JsonSerializable>()).serializationDataFormat("application/json").create()).putValue("delegate", new UpdateValueDelegate()));
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "listVar");
// this should match Jackson's format
String expectedTypeName = ArrayList.class.getName() + "<" + JsonSerializable.class.getName() + ">";
assertEquals(expectedTypeName, typedValue.getObjectTypeName());
List<JsonSerializable> list = (List<JsonSerializable>) typedValue.getValue();
assertEquals(1, list.size());
assertTrue(list.get(0) instanceof JsonSerializable);
assertEquals(UpdateValueDelegate.STRING_PROPERTY, list.get(0).getStringProperty());
}
Aggregations