示例#1
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);
        }
示例#2
0
        public virtual void testListSerializationAsJson()
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

            IList <JsonSerializable> beans = new List <JsonSerializable>();

            for (int i = 0; i < 20; i++)
            {
                beans.Add(new JsonSerializable("a String" + i, 42 + i, true));
            }

            runtimeService.setVariable(instance.Id, "simpleBeans", objectValue(beans).serializationDataFormat(JSON_FORMAT_NAME).create());

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

            assertEquals(beans, value);

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

            assertEquals(ValueType.OBJECT, typedValue.Type);
            assertEquals(beans, typedValue.Value);
            assertTrue(typedValue.Deserialized);
            assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
            assertNotNull(typedValue.ObjectTypeName);
            JSONAssert.assertEquals(toExpectedJsonArray(beans), new string(typedValue.ValueSerialized), true);
        }
示例#3
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);
        }
示例#4
0
        public virtual void testGetUntypedJsonValue()
        {
            // given
            JsonValue   jsonValue = jsonValue(jsonString).create();
            VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);

            string processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).Id;

            // when
            SpinJsonNode value = (SpinJsonNode)runtimeService.getVariable(processInstanceId, variableName);

            // then
            JSONAssert.assertEquals(jsonString, value.ToString(), true);
            assertEquals(json().Name, value.DataFormatName);
        }
示例#5
0
        public virtual void testGetTypedJsonValue()
        {
            // given
            JsonValue   jsonValue = jsonValue(jsonString).create();
            VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);

            string processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).Id;

            // when
            JsonValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);

            // then
            SpinJsonNode value = typedValue.Value;

            JSONAssert.assertEquals(jsonString, value.ToString(), true);

            assertTrue(typedValue.Deserialized);
            assertEquals(JSON, typedValue.Type);
            assertEquals(JSON_FORMAT_NAME, typedValue.SerializationDataFormat);
            JSONAssert.assertEquals(jsonString, typedValue.ValueSerialized, true);
        }