use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class HistoricVariableJsonSerializationTest method testSelectHistoricVariableInstances.
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricVariableInstances() throws JSONException {
if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, false);
runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
assertNotNull(historicVariable.getValue());
assertNull(historicVariable.getErrorMessage());
assertEquals(ValueType.OBJECT.getName(), historicVariable.getTypeName());
assertEquals(ValueType.OBJECT.getName(), historicVariable.getVariableTypeName());
JsonSerializable historyValue = (JsonSerializable) historicVariable.getValue();
assertEquals(bean.getStringProperty(), historyValue.getStringProperty());
assertEquals(bean.getIntProperty(), historyValue.getIntProperty());
assertEquals(bean.getBooleanProperty(), historyValue.getBooleanProperty());
}
}
use of org.camunda.bpm.engine.test.Deployment 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.test.Deployment in project camunda-bpm-platform by camunda.
the class JavaSerializationTest method testJavaSerializedValuesAreProhibitedForTransient.
@Deployment(resources = ONE_TASK_PROCESS)
public void testJavaSerializedValuesAreProhibitedForTransient() throws JSONException {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
try {
// request object to be serialized as Java
runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue("").serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
fail("Exception is expected.");
} catch (ProcessEngineException ex) {
assertEquals("ENGINE-17007 Cannot set variable with name simpleBean. Java serialization format is prohibited", ex.getMessage());
}
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testVariableValueCaching.
@Deployment(resources = ONE_TASK_PROCESS)
public void testVariableValueCaching() {
final ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
JsonSerializable bean = new JsonSerializable("a String", 42, true);
runtimeService.setVariable(instance.getId(), "simpleBean", bean);
Object returnedBean = runtimeService.getVariable(instance.getId(), "simpleBean");
assertSame(bean, returnedBean);
return null;
}
});
VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
Object returnedBean = variableInstance.getValue();
Object theSameReturnedBean = variableInstance.getValue();
assertSame(returnedBean, theSameReturnedBean);
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class JsonSerializationTest method testRemoveVariable.
@Deployment(resources = ONE_TASK_PROCESS)
public void testRemoveVariable() throws JSONException {
// given a serialized json variable
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JsonSerializable bean = new JsonSerializable("a String", 42, true);
String beanAsJson = bean.toExpectedJsonString();
SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
// when
runtimeService.removeVariable(instance.getId(), "simpleBean");
// then
assertNull(runtimeService.getVariable(instance.getId(), "simpleBean"));
assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean"));
assertNull(runtimeService.getVariableTyped(instance.getId(), "simpleBean", false));
}
Aggregations