Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void testVariablesWithoutDeserialization(String processDefinitionKey) throws Exception
        private void testVariablesWithoutDeserialization(string processDefinitionKey)
        {
            //given serializable variable
            JavaSerializable javaSerializable = new JavaSerializable("foo");

            MemoryStream baos = new MemoryStream();

            (new ObjectOutputStream(baos)).writeObject(javaSerializable);
            string serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.ProcessEngine);

            //when execute process with serialized variable and wait state
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            ProcessInstanceWithVariables procInstance = engineRule.RuntimeService.createProcessInstanceByKey(processDefinitionKey).setVariable("serializedVar", serializedObjectValue(serializedObject).serializationDataFormat(Variables.SerializationDataFormats.JAVA).objectTypeName(typeof(JavaSerializable).FullName).create()).executeWithVariablesInReturn(false, false);

            //then returned instance contains serialized variable
            VariableMap map = procInstance.Variables;

            assertNotNull(map);

            ObjectValue serializedVar = (ObjectValue)map.getValueTyped("serializedVar");

            assertFalse(serializedVar.Deserialized);
            assertObjectValueSerializedJava(serializedVar, javaSerializable);

            //access on value should fail because variable is not deserialized
            try
            {
                serializedVar.Value;
                Assert.fail("Deserialization should fail!");
            }
            catch (System.InvalidOperationException ise)
            {
                assertTrue(ise.Message.Equals("Object is not deserialized."));
            }
        }
Пример #2
0
        public virtual void testFailSerializationForUnknownSerializedValueType()
        {
            // given
            JavaSerializable pojo = new JavaSerializable("foo");
            MemoryStream     baos = new MemoryStream();

            (new ObjectOutputStream(baos)).writeObject(pojo);
            string serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            ObjectValue serializedObjectValue = Variables.serializedObjectValue(serializedObject).serializationDataFormat(Variables.SerializationDataFormats.JAVA).objectTypeName(pojo.GetType().FullName).create();
            VariableMap variables             = Variables.createVariables().putValueTyped("var", serializedObjectValue);

            // when
            ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);

            // then
            JavaSerializable returnedPojo = (JavaSerializable)runtimeService.getVariable(processInstance.Id, "var");

            assertEquals(pojo, returnedPojo);
        }