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); }
public virtual void testSerializationAsXml() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); XmlSerializable bean = new XmlSerializable("a String", 42, true); // request object to be serialized as XML runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(XML_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(XmlSerializable))); assertEquals(typeof(XmlSerializable), typedValue.ObjectType); assertEquals(XML_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(XmlSerializable).FullName, typedValue.ObjectTypeName); SpinXmlElement serializedValue = Spin.XML(typedValue.ValueSerialized); assertEquals(bean.StringProperty, serializedValue.childElement("stringProperty").textContent()); assertEquals(bean.BooleanProperty, bool.Parse(serializedValue.childElement("booleanProperty").textContent())); assertEquals(bean.IntProperty, int.Parse(serializedValue.childElement("intProperty").textContent())); }
public static void assertObjectValueDeserialized(ObjectValue typedValue, object value) { Type expectedObjectType = value.GetType(); assertTrue(typedValue.Deserialized); assertEquals(ValueType.OBJECT, typedValue.Type); assertEquals(value, typedValue.Value); assertEquals(value, typedValue.getValue(expectedObjectType)); assertEquals(expectedObjectType, typedValue.ObjectType); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: assertEquals(expectedObjectType.FullName, typedValue.ObjectTypeName); }
public virtual void testFailingDeserialization() { ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); FailingDeserializationBean failingBean = new FailingDeserializationBean("a String", 42, true); runtimeService.setVariable(instance.Id, "simpleBean", objectValue(failingBean).serializationDataFormat(JSON_FORMAT_NAME)); try { runtimeService.getVariable(instance.Id, "simpleBean"); fail("exception expected"); } catch (ProcessEngineException) { // happy path } try { runtimeService.getVariableTyped(instance.Id, "simpleBean"); fail("exception expected"); } catch (ProcessEngineException) { // happy path } // However, I can access the serialized value ObjectValue objectValue = runtimeService.getVariableTyped(instance.Id, "simpleBean", false); assertFalse(objectValue.Deserialized); assertNotNull(objectValue.ObjectTypeName); assertNotNull(objectValue.ValueSerialized); // but not the deserialized properties try { objectValue.Value; fail("exception expected"); } catch (System.InvalidOperationException e) { assertTextPresent("Object is not deserialized", e.Message); } try { objectValue.getValue(typeof(JsonSerializable)); fail("exception expected"); } catch (System.InvalidOperationException e) { assertTextPresent("Object is not deserialized", e.Message); } try { objectValue.ObjectType; fail("exception expected"); } catch (System.InvalidOperationException e) { assertTextPresent("Object is not deserialized", e.Message); } }