예제 #1
0
        public virtual void testTransientJsonValue()
        {
            // given
            BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo").startEvent().exclusiveGateway("gtw").sequenceFlowId("flow1").condition("cond", "${x.stringProperty == \"bar\"}").userTask("userTask1").endEvent().moveToLastGateway().sequenceFlowId("flow2").userTask("userTask2").endEvent().done();

            deployment(modelInstance);

            JsonSerializable bean = new JsonSerializable("bar", 42, true);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            ObjectValue jsonValue = serializedObjectValue(bean.toExpectedJsonString(), true).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(typeof(JsonSerializable).FullName).create();
            VariableMap variables = Variables.createVariables().putValueTyped("x", jsonValue);

            // when
            runtimeService.startProcessInstanceByKey("foo", variables);

            // then
            IList <VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();

            assertEquals(0, variableInstances.Count);

            Task task = taskService.createTaskQuery().singleResult();

            assertNotNull(task);
            assertEquals("userTask1", task.TaskDefinitionKey);
        }
예제 #2
0
        public virtual void testSelectHistoricSerializedValuesUpdate()
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

            JsonSerializable bean = new JsonSerializable("a String", 42, false);

            runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));

            if (ProcessEngineConfiguration.HISTORY_FULL.Equals(processEngineConfiguration.History))
            {
                HistoricVariableUpdate historicUpdate = (HistoricVariableUpdate)historyService.createHistoricDetailQuery().variableUpdates().singleResult();

                assertNotNull(historicUpdate.Value);
                assertNull(historicUpdate.ErrorMessage);

                assertEquals(ValueType.OBJECT.Name, historicUpdate.TypeName);
                assertEquals(ValueType.OBJECT.Name, historicUpdate.VariableTypeName);

                JsonSerializable historyValue = (JsonSerializable)historicUpdate.Value;
                assertEquals(bean.StringProperty, historyValue.StringProperty);
                assertEquals(bean.IntProperty, historyValue.IntProperty);
                assertEquals(bean.BooleanProperty, historyValue.BooleanProperty);

                ObjectValue typedValue = (ObjectValue)historicUpdate.TypedValue;
                assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
                JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName);
            }
        }
예제 #3
0
        public virtual void testSerializationAsJson()
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

            JsonSerializable bean = new JsonSerializable("a String", 42, true);

            // request object to be serialized as JSON
            runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());

            // validate untyped value
            object value = runtimeService.getVariable(instance.Id, "simpleBean");

            assertEquals(bean, value);

            // validate typed value
            ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean");

            assertEquals(ValueType.OBJECT, typedValue.Type);

            assertTrue(typedValue.Deserialized);

            assertEquals(bean, typedValue.Value);
            assertEquals(bean, typedValue.getValue(typeof(JsonSerializable)));
            assertEquals(typeof(JsonSerializable), typedValue.ObjectType);

            assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName);
            JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true);
        }
예제 #4
0
        public virtual void testSetSerializedVariableValueMismatchingTypeName()
        {
            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("Insensible type name.");     // < not a valid type name

            runtimeService.setVariable(instance.Id, "simpleBean", serializedValue);

            try
            {
                runtimeService.getVariable(instance.Id, "simpleBean");
                fail("Exception expected.");
            }
            catch (Exception)
            {
                // happy path
            }

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(typeof(JsonSerializationTest).FullName);     // < not the right type name

            runtimeService.setVariable(instance.Id, "simpleBean", serializedValue);

            try
            {
                runtimeService.getVariable(instance.Id, "simpleBean");
                fail("Exception expected.");
            }
            catch (Exception)
            {
                // happy path
            }
        }
예제 #5
0
        public virtual void testGetSerializedVariableValue()
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

            JsonSerializable bean = new JsonSerializable("a String", 42, true);

            runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());

            ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean", false);

            string serializedValue = typedValue.ValueSerialized;

            JSONAssert.assertEquals(bean.toExpectedJsonString(), serializedValue, true);
        }
예제 #6
0
        public virtual void testSelectHistoricSerializedValues()
        {
            if (processEngineConfiguration.HistoryLevel.Id >= org.camunda.bpm.engine.impl.history.HistoryLevel_Fields.HISTORY_LEVEL_AUDIT.Id)
            {
                ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

                JsonSerializable bean = new JsonSerializable("a String", 42, false);
                runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));

                HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
                assertNotNull(historicVariable.Value);
                assertNull(historicVariable.ErrorMessage);

                ObjectValue typedValue = (ObjectValue)historicVariable.TypedValue;
                assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
                JSONAssert.assertEquals(bean.toExpectedJsonString(), new string(typedValue.ValueSerialized), true);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                assertEquals(typeof(JsonSerializable).FullName, typedValue.ObjectTypeName);
            }
        }
예제 #7
0
        public virtual void testRemoveVariable()
        {
            // given a serialized json variable
            ProcessInstance  instance   = runtimeService.startProcessInstanceByKey("oneTaskProcess");
            JsonSerializable bean       = new JsonSerializable("a String", 42, true);
            string           beanAsJson = bean.toExpectedJsonString();

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method:
            SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.GetType().FullName);

            runtimeService.setVariable(instance.Id, "simpleBean", serializedValue);

            // when
            runtimeService.removeVariable(instance.Id, "simpleBean");

            // then
            assertNull(runtimeService.getVariable(instance.Id, "simpleBean"));
            assertNull(runtimeService.getVariableTyped(instance.Id, "simpleBean"));
            assertNull(runtimeService.getVariableTyped(instance.Id, "simpleBean", false));
        }
예제 #8
0
        public virtual void testSetSerializedVariableValueNoTypeName()
        {
            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);

            // no type name

            try
            {
                runtimeService.setVariable(instance.Id, "simpleBean", serializedValue);
                fail("Exception expected.");
            }
            catch (Exception e)
            {
                assertTextPresent("no 'objectTypeName' provided for non-null value", e.Message);
            }
        }
예제 #9
0
        public virtual void testSetSerializedVariableValue()
        {
            ProcessInstance  instance   = runtimeService.startProcessInstanceByKey("oneTaskProcess");
            JsonSerializable bean       = new JsonSerializable("a String", 42, true);
            string           beanAsJson = bean.toExpectedJsonString();

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method:
            SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.GetType().FullName);

            runtimeService.setVariable(instance.Id, "simpleBean", serializedValue);

            // java object can be retrieved
            JsonSerializable returnedBean = (JsonSerializable)runtimeService.getVariable(instance.Id, "simpleBean");

            assertEquals(bean, returnedBean);

            // validate typed value metadata
            ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean");

            assertEquals(bean, typedValue.Value);
            assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method:
            assertEquals(bean.GetType().FullName, typedValue.ObjectTypeName);
        }