Search in sources :

Example 31 with Deployment

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());
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 32 with Deployment

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());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 33 with Deployment

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());
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 34 with Deployment

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);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 35 with Deployment

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));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Deployment (org.camunda.bpm.engine.test.Deployment)3376 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1325 Task (org.camunda.bpm.engine.task.Task)788 Test (org.junit.Test)635 HashMap (java.util.HashMap)441 Job (org.camunda.bpm.engine.runtime.Job)310 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)277 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)265 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)256 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)251 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)230 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)206 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)195 Execution (org.camunda.bpm.engine.runtime.Execution)189 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)175 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)161 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)149 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)143 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)134 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)134