Search in sources :

Example 11 with ProcessInstance

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

Example 12 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance 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 13 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance 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 14 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance 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 15 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance 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)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2392 Deployment (org.camunda.bpm.engine.test.Deployment)1325 Test (org.junit.Test)1168 Task (org.camunda.bpm.engine.task.Task)660 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)415 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)372 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)272 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)258 HashMap (java.util.HashMap)235 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)230 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)203 Job (org.camunda.bpm.engine.runtime.Job)189 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)184 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)149 Execution (org.camunda.bpm.engine.runtime.Execution)144 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)130 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)129 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)122 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)86 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)84