public void Long_EightOctet(long expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadLong());
        }
Exemple #2
0
        public void Map_SparseArray()
        {
            var value = new Dictionary <object, object>
            {
                { 1, "fee" },
                { 16, "fie" },
                { 256, "foe" }
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           .WriteChar('H')                    // untyped map

                           .WriteBytes(0x91)                  // 1
                           .WriteBytes(0x03).WriteUtf8("fee") // "fee"

                           .WriteBytes(0xa0)                  // 16
                           .WriteBytes(0x03).WriteUtf8("fie") // "fie"

                           .WriteBytes(0xc9, 0x00)            // 256
                           .WriteBytes(0x03).WriteUtf8("foe") // foe

                           .WriteChar('Z')                    // map end
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void Map_Object()
        {
            var value = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           // map
                           .WriteChar('M')
                           // type (from the website example)
                           .WriteChar('t').WriteBytes(0, 0x13).WriteUtf8("com.caucho.test.Car")
                           // model field
                           .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("model")
                           .WriteChar('S').WriteBytes(0, 0x06).WriteUtf8("Beetle")
                           // color field
                           .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("color")
                           .WriteChar('S').WriteBytes(0, 0x0A).WriteUtf8("aquamarine")
                           // mileage field
                           .WriteChar('S').WriteBytes(0, 0x07).WriteUtf8("mileage")
                           .WriteChar('I').WriteBytes(0, 0x01, 0, 0)
                           // map end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void List_Compact_Fixed_UsingTypeRef()
        {
            var first  = new int[] { 0, 1 };
            var second = new int[] { 2, 3, 4 };

            var expected = new HessianDataBuilder()
                                                               // first list
                           .WriteBytes(0x72)                   // list tag
                           .WriteBytes(0x04).WriteUtf8("[int") // type
                           .WriteBytes(0x90)                   // int 0
                           .WriteBytes(0x91)                   // int 1
                                                               // second list
                           .WriteBytes(0x73)                   // list tag
                           .WriteBytes(0x90)                   // type ref 0 (above [int)
                           .WriteBytes(0x92)                   // int 2
                           .WriteBytes(0x93)                   // int 3
                           .WriteBytes(0x94)                   // int 4
                           .ToArray();

            byte[] actual;
            using (var ms = new MemoryStream())
                using (var writer = new HessianStreamWriter(ms))
                {
                    var output = new HessianOutputV2(writer, TypeBindings.Java);
                    output.WriteObject(first);
                    output.WriteObject(second);
                    actual = ms.ToArray();
                }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void Map_CompactObject()
        {
            var value = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 268435456
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           .WriteChar('C')   // definition
                           .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car")
                           .WriteBytes(0x93) // 3 fields
                           .WriteBytes(0x05).WriteUtf8("model")
                           .WriteBytes(0x05).WriteUtf8("color")
                           .WriteBytes(0x07).WriteUtf8("mileage")

                           .WriteBytes(0x60) // instance
                           .WriteBytes(0x06).WriteUtf8("Beetle")
                           .WriteBytes(0x0a).WriteUtf8("aquamarine")
                           .WriteChar('I').WriteBytes(0x10, 0, 0, 0)

                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #6
0
        public void Ref_CircularList()
        {
            var value = new com.caucho.test.LinkedList {
                head = 1
            };

            value.tail = value;

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           // map
                           .WriteChar('M')
                           // type
                           .WriteChar('t').WriteBytes(0, 0x1A).WriteUtf8("com.caucho.test.LinkedList")
                           // head field
                           .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("head")
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                           // tail field
                           .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("tail")
                           .WriteChar('R').WriteBytes(0, 0, 0, 0)
                           // map end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
        public void Double_Short(double expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
Exemple #8
0
        public void Ref_CircularList()
        {
            var reader = new HessianDataBuilder()
                         // map
                         .WriteChar('M')
                         // type
                         .WriteChar('t').WriteBytes(0, 0x1A).WriteUtf8("com.caucho.test.LinkedList")
                         // head field
                         .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("head")
                         .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                         // tail field
                         .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("tail")
                         .WriteChar('R').WriteBytes(0, 0, 0, 0)
                         // map end
                         .WriteChar('z')
                         .ToReader();

            // expectation:
            //   head is an integer
            //   tail is object itself (circular ref)
            var expected = new com.caucho.test.LinkedList {
                head = 1
            };

            expected.tail = expected;

            var actual = (com.caucho.test.LinkedList) new HessianInputV1(reader).ReadObject();

            Assert.AreEqual(expected.head, actual.head);
            // check that ref was restored correctly
            Assert.AreSame(expected, expected.tail);
        }
        public void List_Compact_Fixed_UsingTypeRef()
        {
            var first  = new int[] { 0, 1 };
            var second = new int[] { 2, 3, 4 };

            var data = new HessianDataBuilder()
                                                           // first list
                       .WriteBytes(0x72)                   // list tag
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91)                   // int 1
                                                           // second list
                       .WriteBytes(0x73)                   // list tag
                       .WriteBytes(0x90)                   // type ref 0 (above [int)
                       .WriteBytes(0x92)                   // int 2
                       .WriteBytes(0x93)                   // int 3
                       .WriteBytes(0x94);                  // int 4

            var input = new HessianInputV2(data.ToReader());

            CollectionAssert.AreEqual(
                first,
                (IEnumerable)input.ReadObject());

            CollectionAssert.AreEqual(
                second,
                (IEnumerable)input.ReadObject());
        }
        public void Int_ThreeOctet(int expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadInt());
        }
Exemple #11
0
        public void Call_WithHeader()
        {
            var header = new Tuple <string, object>("transaction", 0);

            byte[] actual;
            using (var ms = new MemoryStream())
                using (var writer = new HessianStreamWriter(ms))
                {
                    new HessianOutputV1(writer).WriteCall("debug", new object[] { 197067 }, new[] { header });
                    actual = ms.ToArray();
                }

            var expected = new HessianDataBuilder()
                           // call
                           .WriteChar('c')
                           // version (major version 1, minor 0)
                           .WriteBytes(1, 0)
                           // header(s)
                           .WriteChar('H')
                           .WriteBytes(0, 0x0B).WriteUtf8("transaction")
                           .WriteChar('I').WriteBytes(0, 0, 0, 0)
                           // method name
                           .WriteChar('m').WriteBytes(0, 0x05).WriteUtf8("debug")
                           // arg1
                           .WriteChar('I').WriteBytes(0, 0x03, 0x01, 0xCB)
                           // call end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
        public void Map_CompactEnum()
        {
            var first  = Color.RED;
            var second = Color.GREEN;
            var third  = Color.BLUE;
            var fourth = Color.GREEN;

            var reader = new HessianDataBuilder()
                         .WriteChar('C')
                         .WriteBytes(0x0d).WriteUtf8("example.Color")
                         .WriteBytes(0x91) // one field
                         .WriteBytes(0x04).WriteUtf8("name")

                         .WriteBytes(0x60) // reference definition
                         .WriteBytes(0x03).WriteUtf8("RED")

                         .WriteBytes(0x60)
                         .WriteBytes(0x05).WriteUtf8("GREEN")

                         .WriteBytes(0x60)
                         .WriteBytes(0x04).WriteUtf8("BLUE")

                         .WriteChar('Q').WriteBytes(0x91) //  GREEN

                         .ToReader();

            var input = new HessianInputV2(reader);

            Assert.AreEqual(first, input.ReadObject());
            Assert.AreEqual(second, input.ReadObject());
            Assert.AreEqual(third, input.ReadObject());
            Assert.AreEqual(fourth, input.ReadObject());
        }
        public void Reply_Fault()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('H')
                         .WriteBytes(2, 0) // version

                         .WriteChar('F')   // fault

                         .WriteChar('H')   // map
                         .WriteBytes(0x04).WriteUtf8("code")
                         .WriteBytes(0x10).WriteUtf8("ServiceException")

                         .WriteBytes(0x07).WriteUtf8("message")
                         .WriteBytes(0x0e).WriteUtf8("File Not Found")

                         .WriteBytes(0x06).WriteUtf8("detail")
                         .WriteChar('M')
                         .WriteBytes(0x1d).WriteUtf8("java.io.FileNotFoundException")
                         .WriteChar('Z')

                         .WriteChar('Z')
                         .ToReader();

            var actual = (HessianRemoteException) new HessianInputV2(reader).ReadReply();

            Assert.AreEqual(FaultCode.ServiceException, actual.Code);
            Assert.AreEqual("File Not Found", actual.OriginalMessage);
            Assert.AreEqual("The hessian server reponded with 'File Not Found' (code: 'ServiceException')", actual.Message);
            Assert.IsInstanceOf <java.io.FileNotFoundException>(actual.InnerException);
        }
        public void Map_CompactObject()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('C')   // definition
                         .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car")
                         .WriteBytes(0x93) // 3 fields
                         .WriteBytes(0x05).WriteUtf8("model")
                         .WriteBytes(0x05).WriteUtf8("color")
                         .WriteBytes(0x07).WriteUtf8("mileage")

                         .WriteBytes(0x60) // instance
                         .WriteBytes(0x06).WriteUtf8("Beetle")
                         .WriteBytes(0x0a).WriteUtf8("aquamarine")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)

                         .ToReader();

            var expected = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV2(reader).ReadObject());
        }
        public void Map_Object()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('M')                                    // map

                         .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car") // type

                         .WriteBytes(0x05).WriteUtf8("model")
                         .WriteBytes(0x06).WriteUtf8("Beetle")

                         .WriteBytes(0x05).WriteUtf8("color")
                         .WriteBytes(0x0a).WriteUtf8("aquamarine")

                         .WriteBytes(0x07).WriteUtf8("mileage")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)

                         .WriteChar('Z') // map end
                         .ToReader();

            var expected = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV2(reader).ReadObject());
        }
        public void Map_SparseArray()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('H')                    // untyped map

                         .WriteBytes(0x91)                  // 1
                         .WriteBytes(0x03).WriteUtf8("fee") // "fee"

                         .WriteBytes(0xa0)                  // 16
                         .WriteBytes(0x03).WriteUtf8("fie") // "fie"

                         .WriteBytes(0xc9, 0x00)            // 256
                         .WriteBytes(0x03).WriteUtf8("foe") // foe

                         .WriteChar('Z')                    // map end
                         .ToReader();                       // map end

            var actual = (IDictionary <object, object>) new HessianInputV2(reader).ReadObject();

            var expected = new Dictionary <object, object>
            {
                { 1, "fee" },
                { 16, "fie" },
                { 256, "foe" }
            };

            Assert.AreEqual(expected.Count, actual.Count);
            foreach (var key in expected.Keys)
            {
                Assert.AreEqual(expected[key], actual[key]);
            }
        }
Exemple #17
0
        public void Call()
        {
            byte[] actual;
            using (var ms = new MemoryStream())
                using (var writer = new HessianStreamWriter(ms))
                {
                    new HessianOutputV1(writer).WriteCall("add2", new object[] { 2, 3 });

                    actual = ms.ToArray();
                }

            var expected = new HessianDataBuilder()
                           // call
                           .WriteChar('c')
                           // version (major version 1, minor 0)
                           .WriteBytes(1, 0)
                           // method name
                           .WriteChar('m').WriteBytes(0, 0x04).WriteUtf8("add2")
                           // arg1
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x02)
                           // arg2
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x03)
                           // call end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #18
0
        public void Reply_Fault()
        {
            var reader = new HessianDataBuilder()
                         // reply
                         .WriteChar('r')
                         // version (major version 1, minor 0)
                         .WriteBytes(1, 0)
                         // fault
                         .WriteChar('f')
                         // code field
                         .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("code")
                         .WriteChar('S').WriteBytes(0, 0x10).WriteUtf8("ServiceException")
                         // message field
                         .WriteChar('S').WriteBytes(0, 0x07).WriteUtf8("message")
                         .WriteChar('S').WriteBytes(0, 0x0E).WriteUtf8("File Not Found")
                         // detail field
                         .WriteChar('S').WriteBytes(0, 0x06).WriteUtf8("detail")
                         .WriteChar('M')
                         // type
                         .WriteChar('t').WriteBytes(0, 0x1D).WriteUtf8("java.io.FileNotFoundException")
                         // map end
                         .WriteChar('z')
                         // reply end
                         .WriteChar('z')
                         .ToReader();

            var actual = (HessianRemoteException) new HessianInputV1(reader).ReadReply();

            Assert.AreEqual(FaultCode.ServiceException, actual.Code);
            Assert.AreEqual("File Not Found", actual.OriginalMessage);
            Assert.AreEqual("The hessian server reponded with 'File Not Found' (code: 'ServiceException')", actual.Message);
            Assert.IsInstanceOf <java.io.FileNotFoundException>(actual.InnerException);
        }
Exemple #19
0
        public void Map_SparseArray()
        {
            var reader = new HessianDataBuilder()
                         // map
                         .WriteChar('M')
                         // key/value 1
                         .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                         .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("fee")
                         // key/value 2
                         .WriteChar('I').WriteBytes(0, 0, 0, 0x10)
                         .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("fie")
                         // key/value 3
                         .WriteChar('I').WriteBytes(0, 0, 0x01, 0)
                         .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("foe")
                         // map end
                         .WriteChar('z')
                         .ToReader();

            var actual = (IDictionary <object, object>) new HessianInputV1(reader).ReadObject();

            var expected = new Dictionary <object, object>
            {
                { 1, "fee" },
                { 16, "fie" },
                { 256, "foe" }
            };

            Assert.AreEqual(expected.Count, actual.Count);
            foreach (var key in expected.Keys)
            {
                Assert.AreEqual(expected[key], actual[key]);
            }
        }
Exemple #20
0
        public void Map_SparseArray()
        {
            var value = new Dictionary <object, object>
            {
                { 1, "fee" },
                { 16, "fie" },
                { 256, "foe" }
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           // map
                           .WriteChar('M')
                           // key/value 1
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                           .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("fee")
                           // key/value 2
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x10)
                           .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("fie")
                           // key/value 3
                           .WriteChar('I').WriteBytes(0, 0, 0x01, 0)
                           .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("foe")
                           // map end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #21
0
        public void Map_Object()
        {
            var reader = new HessianDataBuilder()
                         // map
                         .WriteChar('M')
                         // type (from the website example)
                         .WriteChar('t').WriteBytes(0, 0x13).WriteUtf8("com.caucho.test.Car")
                         // model field
                         .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("model")
                         .WriteChar('S').WriteBytes(0, 0x06).WriteUtf8("Beetle")
                         // color field
                         .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("color")
                         .WriteChar('S').WriteBytes(0, 0x0A).WriteUtf8("aquamarine")
                         // mileage field
                         .WriteChar('S').WriteBytes(0, 0x07).WriteUtf8("mileage")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)
                         // map end
                         .WriteChar('z')
                         .ToReader();

            var expected = new com.caucho.test.Car {
                model = "Beetle", color = "aquamarine", mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV1(reader).ReadObject());
        }
Exemple #22
0
        public void Null()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('N')
                         .ToReader();

            Assert.Null(new HessianInputV1(reader).ReadObject());
        }
Exemple #23
0
        public void Long300()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('L').WriteBytes(0, 0, 0, 0, 0, 0, 0x01, 0x2C);

            Assert.AreEqual(300, new HessianInputV1(data.ToReader()).ReadObject());
            Assert.AreEqual(300, new HessianInputV1(data.ToReader()).ReadLong());
        }
Exemple #24
0
        public void Double12_25()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('D').WriteBytes(0x40, 0x28, 0x80, 0, 0, 0, 0, 0);

            Assert.AreEqual(12.25, new HessianInputV1(data.ToReader()).ReadObject());
            Assert.AreEqual(12.25, new HessianInputV1(data.ToReader()).ReadDouble());
        }
Exemple #25
0
        public void BooleanFalse()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('F');

            Assert.False((bool)new HessianInputV1(data.ToReader()).ReadObject());
            Assert.False(new HessianInputV1(data.ToReader()).ReadBool());
        }
        public void String_Short(string expected, byte[] bytes)
        {
            // can be up to 31 chars
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadString());
        }
Exemple #27
0
        public void String_MultiByteUnicode()
        {
            var str    = "세미";
            var reader = new HessianDataBuilder()
                         .WriteChar('S').WriteBytes(0, 0x02).WriteUtf8(str)
                         .ToReader();

            Assert.AreEqual(str, new HessianInputV1(reader).ReadObject());
        }
        public void Double_One()
        {
            var expected = 1.0;

            var data = new HessianDataBuilder().WriteBytes(0x5c);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
Exemple #29
0
        public void Xml()
        {
            var str    = "<top>hello</top>";
            var reader = new HessianDataBuilder()
                         // xml
                         .WriteChar('X').WriteBytes(0, 0x10).WriteUtf8(str)
                         .ToReader();

            Assert.AreEqual(str, new HessianInputV1(reader).ReadObject());
        }
Exemple #30
0
        public void Binary_SingleChunk()
        {
            var byteArr = new byte[] { 0x28 };
            var reader  = new HessianDataBuilder()
                          // byte array
                          .WriteChar('B').WriteBytes(0, 0x01).WriteBytes(byteArr)
                          .ToReader();

            CollectionAssert.AreEqual(byteArr, (IEnumerable) new HessianInputV1(reader).ReadObject());
        }