http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/CT_MsgPackSerialzier.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/CT_MsgPackSerialzier.java b/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/CT_MsgPackSerialzier.java deleted file mode 100755 index 0ee57f0..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/CT_MsgPackSerialzier.java +++ /dev/null @@ -1,220 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.msgpack; - -import static org.junit.Assert.*; - -import java.io.*; - -import org.apache.juneau.*; -import org.junit.*; - -@SuppressWarnings("serial") -public class CT_MsgPackSerialzier { - - //==================================================================================================== - // testBasic - //==================================================================================================== - @Test - public void testBasic() throws Exception { - - test(null, "C0"); - - test(false, "C2"); - test(true, "C3"); - - // positive fixnum stores 7-bit positive integer - // +--------+ - // |0XXXXXXX| - // +--------+ - // - // int 8 stores a 8-bit signed integer - // +--------+--------+ - // | 0xd0 |ZZZZZZZZ| - // +--------+--------+ - // - // int 16 stores a 16-bit big-endian signed integer - // +--------+--------+--------+ - // | 0xd1 |ZZZZZZZZ|ZZZZZZZZ| - // +--------+--------+--------+ - // - // int 32 stores a 32-bit big-endian signed integer - // +--------+--------+--------+--------+--------+ - // | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| - // +--------+--------+--------+--------+--------+ - // - // int 64 stores a 64-bit big-endian signed integer - // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ - // | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| - // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ - // - // negative fixnum stores 5-bit negative integer - // +--------+ - // |111YYYYY| - // +--------+ - // - // * 0XXXXXXX is 8-bit unsigned integer - // * 111YYYYY is 8-bit signed integer - // - - test(0, "00"); - test(0x7F, "7F"); - - test(0x80, "D1 00 80"); - test(0x0100, "D1 01 00"); - test(0x7FFF, "D1 7F FF"); - test(0x8000, "D2 00 00 80 00"); - test(0xFFFF, "D2 00 00 FF FF"); - test(0x00010000, "D2 00 01 00 00"); - test(Long.decode("0x000000007FFFFFFF").longValue(), "D2 7F FF FF FF"); - test(Long.decode("0x0000000080000000").longValue(), "D3 00 00 00 00 80 00 00 00"); - test(Long.decode("0x0000000100000000").longValue(), "D3 00 00 00 01 00 00 00 00"); - test(Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 7F FF FF FF FF FF FF FF"); - test(-Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 80 00 00 00 00 00 00 01"); - test(-1, "E1"); - test(-63, "FF"); - test(-64, "D0 C0"); - - test(-0x7F, "D0 81"); - test(-0x80, "D1 FF 80"); - test(-0x0100, "D1 FF 00"); - test(-0x7FFF, "D1 80 01"); - test(-0x8000, "D2 FF FF 80 00"); - test(-0xFFFF, "D2 FF FF 00 01"); - test(-0x00010000, "D2 FF FF 00 00"); - test(-Long.decode("0x000000007FFFFFFF").longValue(), "D2 80 00 00 01"); - test(-Long.decode("0x0000000080000000").longValue(), "D3 FF FF FF FF 80 00 00 00"); - test(-Long.decode("0x0000000100000000").longValue(), "D3 FF FF FF FF 00 00 00 00"); - test(-Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 80 00 00 00 00 00 00 01"); - - // float 32 stores a floating point number in IEEE 754 single precision floating point number format: - // +--------+--------+--------+--------+--------+ - // | 0xca |XXXXXXXX|XXXXXXXX|XXXXXXXX|XXXXXXXX| - // +--------+--------+--------+--------+--------+ - // - // float 64 stores a floating point number in IEEE 754 double precision floating point number format: - // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ - // | 0xcb |YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY| - // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ - // - // where - // * XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX is a big-endian IEEE 754 single precision floating point number. - // Extension of precision from single-precision to double-precision does not lose precision. - // * YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY is a big-endian - // IEEE 754 double precision floating point number - - test(0f, "CA 00 00 00 00"); - test(1f, "CA 3F 80 00 00"); - test(-1f, "CA BF 80 00 00"); - test(1d, "CB 3F F0 00 00 00 00 00 00"); - test(-1d, "CB BF F0 00 00 00 00 00 00"); - - // fixstr stores a byte array whose length is upto 31 bytes: - // +--------+========+ - // |101XXXXX| data | - // +--------+========+ - // - // str 8 stores a byte array whose length is upto (2^8)-1 bytes: - // +--------+--------+========+ - // | 0xd9 |YYYYYYYY| data | - // +--------+--------+========+ - // - // str 16 stores a byte array whose length is upto (2^16)-1 bytes: - // +--------+--------+--------+========+ - // | 0xda |ZZZZZZZZ|ZZZZZZZZ| data | - // +--------+--------+--------+========+ - // - // str 32 stores a byte array whose length is upto (2^32)-1 bytes: - // +--------+--------+--------+--------+--------+========+ - // | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data | - // +--------+--------+--------+--------+--------+========+ - // - // where - // * XXXXX is a 5-bit unsigned integer which represents N - // * YYYYYYYY is a 8-bit unsigned integer which represents N - // * ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N - // * AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N - // * N is the length of data - - test("", "A0"); - test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "BF 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61"); - test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "D9 20 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61"); - - // fixarray stores an array whose length is upto 15 elements: - // +--------+~~~~~~~~~~~~~~~~~+ - // |1001XXXX| N objects | - // +--------+~~~~~~~~~~~~~~~~~+ - // - // array 16 stores an array whose length is upto (2^16)-1 elements: - // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // | 0xdc |YYYYYYYY|YYYYYYYY| N objects | - // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // - // array 32 stores an array whose length is upto (2^32)-1 elements: - // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects | - // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // - // where - // * XXXX is a 4-bit unsigned integer which represents N - // * YYYYYYYY_YYYYYYYY is a 16-bit big-endian unsigned integer which represents N - // * ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ is a 32-bit big-endian unsigned integer which represents N - // N is the size of a array - - test(new int[0], "90"); - test(new int[]{1}, "91 01"); - test(new int[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, "9F 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01"); - test(new int[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, "DC 00 10 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01"); - - // fixmap stores a map whose length is upto 15 elements - // +--------+~~~~~~~~~~~~~~~~~+ - // |1000XXXX| N*2 objects | - // +--------+~~~~~~~~~~~~~~~~~+ - // - // map 16 stores a map whose length is upto (2^16)-1 elements - // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects | - // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // - // map 32 stores a map whose length is upto (2^32)-1 elements - // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects | - // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ - // - // where - // * XXXX is a 4-bit unsigned integer which represents N - // * YYYYYYYY_YYYYYYYY is a 16-bit big-endian unsigned integer which represents N - // * ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ is a 32-bit big-endian unsigned integer which represents N - // * N is the size of a map - // * odd elements in objects are keys of a map - // * the next element of a key is its associated value - - test(new ObjectMap("{}"), "80"); - test(new ObjectMap("{1:1}"), "81 A1 31 01"); - test(new ObjectMap("{1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1,a:1,b:1,c:1,d:1,e:1,f:1}"), "8F A1 31 01 A1 32 01 A1 33 01 A1 34 01 A1 35 01 A1 36 01 A1 37 01 A1 38 01 A1 39 01 A1 61 01 A1 62 01 A1 63 01 A1 64 01 A1 65 01 A1 66 01"); - test(new ObjectMap("{1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1,a:1,b:1,c:1,d:1,e:1,f:1,g:1}"), "DE 00 10 A1 31 01 A1 32 01 A1 33 01 A1 34 01 A1 35 01 A1 36 01 A1 37 01 A1 38 01 A1 39 01 A1 61 01 A1 62 01 A1 63 01 A1 64 01 A1 65 01 A1 66 01 A1 67 01"); - - byte[] b = MsgPackSerializer.DEFAULT.serialize(new Person()); - System.err.println(TestUtils.toReadableBytes2(b)); - } - - public static class Person { - public String name = "John Smith"; - public int age = 21; - } - - private void test(Object input, String expected) throws Exception { - byte[] b = MsgPackSerializer.DEFAULT.serialize(input); - assertEquals(expected, TestUtils.toReadableBytes2(b)); - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/MsgPackSerialzierTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/MsgPackSerialzierTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/MsgPackSerialzierTest.java new file mode 100755 index 0000000..1e49f63 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/msgpack/MsgPackSerialzierTest.java @@ -0,0 +1,220 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.msgpack; + +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.*; +import org.junit.*; + +@SuppressWarnings("serial") +public class MsgPackSerialzierTest { + + //==================================================================================================== + // testBasic + //==================================================================================================== + @Test + public void testBasic() throws Exception { + + test(null, "C0"); + + test(false, "C2"); + test(true, "C3"); + + // positive fixnum stores 7-bit positive integer + // +--------+ + // |0XXXXXXX| + // +--------+ + // + // int 8 stores a 8-bit signed integer + // +--------+--------+ + // | 0xd0 |ZZZZZZZZ| + // +--------+--------+ + // + // int 16 stores a 16-bit big-endian signed integer + // +--------+--------+--------+ + // | 0xd1 |ZZZZZZZZ|ZZZZZZZZ| + // +--------+--------+--------+ + // + // int 32 stores a 32-bit big-endian signed integer + // +--------+--------+--------+--------+--------+ + // | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| + // +--------+--------+--------+--------+--------+ + // + // int 64 stores a 64-bit big-endian signed integer + // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ + // | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| + // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ + // + // negative fixnum stores 5-bit negative integer + // +--------+ + // |111YYYYY| + // +--------+ + // + // * 0XXXXXXX is 8-bit unsigned integer + // * 111YYYYY is 8-bit signed integer + // + + test(0, "00"); + test(0x7F, "7F"); + + test(0x80, "D1 00 80"); + test(0x0100, "D1 01 00"); + test(0x7FFF, "D1 7F FF"); + test(0x8000, "D2 00 00 80 00"); + test(0xFFFF, "D2 00 00 FF FF"); + test(0x00010000, "D2 00 01 00 00"); + test(Long.decode("0x000000007FFFFFFF").longValue(), "D2 7F FF FF FF"); + test(Long.decode("0x0000000080000000").longValue(), "D3 00 00 00 00 80 00 00 00"); + test(Long.decode("0x0000000100000000").longValue(), "D3 00 00 00 01 00 00 00 00"); + test(Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 7F FF FF FF FF FF FF FF"); + test(-Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 80 00 00 00 00 00 00 01"); + test(-1, "E1"); + test(-63, "FF"); + test(-64, "D0 C0"); + + test(-0x7F, "D0 81"); + test(-0x80, "D1 FF 80"); + test(-0x0100, "D1 FF 00"); + test(-0x7FFF, "D1 80 01"); + test(-0x8000, "D2 FF FF 80 00"); + test(-0xFFFF, "D2 FF FF 00 01"); + test(-0x00010000, "D2 FF FF 00 00"); + test(-Long.decode("0x000000007FFFFFFF").longValue(), "D2 80 00 00 01"); + test(-Long.decode("0x0000000080000000").longValue(), "D3 FF FF FF FF 80 00 00 00"); + test(-Long.decode("0x0000000100000000").longValue(), "D3 FF FF FF FF 00 00 00 00"); + test(-Long.decode("0x7FFFFFFFFFFFFFFF").longValue(), "D3 80 00 00 00 00 00 00 01"); + + // float 32 stores a floating point number in IEEE 754 single precision floating point number format: + // +--------+--------+--------+--------+--------+ + // | 0xca |XXXXXXXX|XXXXXXXX|XXXXXXXX|XXXXXXXX| + // +--------+--------+--------+--------+--------+ + // + // float 64 stores a floating point number in IEEE 754 double precision floating point number format: + // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ + // | 0xcb |YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY|YYYYYYYY| + // +--------+--------+--------+--------+--------+--------+--------+--------+--------+ + // + // where + // * XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX is a big-endian IEEE 754 single precision floating point number. + // Extension of precision from single-precision to double-precision does not lose precision. + // * YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY_YYYYYYYY is a big-endian + // IEEE 754 double precision floating point number + + test(0f, "CA 00 00 00 00"); + test(1f, "CA 3F 80 00 00"); + test(-1f, "CA BF 80 00 00"); + test(1d, "CB 3F F0 00 00 00 00 00 00"); + test(-1d, "CB BF F0 00 00 00 00 00 00"); + + // fixstr stores a byte array whose length is upto 31 bytes: + // +--------+========+ + // |101XXXXX| data | + // +--------+========+ + // + // str 8 stores a byte array whose length is upto (2^8)-1 bytes: + // +--------+--------+========+ + // | 0xd9 |YYYYYYYY| data | + // +--------+--------+========+ + // + // str 16 stores a byte array whose length is upto (2^16)-1 bytes: + // +--------+--------+--------+========+ + // | 0xda |ZZZZZZZZ|ZZZZZZZZ| data | + // +--------+--------+--------+========+ + // + // str 32 stores a byte array whose length is upto (2^32)-1 bytes: + // +--------+--------+--------+--------+--------+========+ + // | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data | + // +--------+--------+--------+--------+--------+========+ + // + // where + // * XXXXX is a 5-bit unsigned integer which represents N + // * YYYYYYYY is a 8-bit unsigned integer which represents N + // * ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N + // * AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N + // * N is the length of data + + test("", "A0"); + test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "BF 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61"); + test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "D9 20 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61"); + + // fixarray stores an array whose length is upto 15 elements: + // +--------+~~~~~~~~~~~~~~~~~+ + // |1001XXXX| N objects | + // +--------+~~~~~~~~~~~~~~~~~+ + // + // array 16 stores an array whose length is upto (2^16)-1 elements: + // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // | 0xdc |YYYYYYYY|YYYYYYYY| N objects | + // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // + // array 32 stores an array whose length is upto (2^32)-1 elements: + // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects | + // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // + // where + // * XXXX is a 4-bit unsigned integer which represents N + // * YYYYYYYY_YYYYYYYY is a 16-bit big-endian unsigned integer which represents N + // * ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ is a 32-bit big-endian unsigned integer which represents N + // N is the size of a array + + test(new int[0], "90"); + test(new int[]{1}, "91 01"); + test(new int[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, "9F 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01"); + test(new int[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, "DC 00 10 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01"); + + // fixmap stores a map whose length is upto 15 elements + // +--------+~~~~~~~~~~~~~~~~~+ + // |1000XXXX| N*2 objects | + // +--------+~~~~~~~~~~~~~~~~~+ + // + // map 16 stores a map whose length is upto (2^16)-1 elements + // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects | + // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // + // map 32 stores a map whose length is upto (2^32)-1 elements + // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects | + // +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+ + // + // where + // * XXXX is a 4-bit unsigned integer which represents N + // * YYYYYYYY_YYYYYYYY is a 16-bit big-endian unsigned integer which represents N + // * ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ_ZZZZZZZZ is a 32-bit big-endian unsigned integer which represents N + // * N is the size of a map + // * odd elements in objects are keys of a map + // * the next element of a key is its associated value + + test(new ObjectMap("{}"), "80"); + test(new ObjectMap("{1:1}"), "81 A1 31 01"); + test(new ObjectMap("{1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1,a:1,b:1,c:1,d:1,e:1,f:1}"), "8F A1 31 01 A1 32 01 A1 33 01 A1 34 01 A1 35 01 A1 36 01 A1 37 01 A1 38 01 A1 39 01 A1 61 01 A1 62 01 A1 63 01 A1 64 01 A1 65 01 A1 66 01"); + test(new ObjectMap("{1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1,a:1,b:1,c:1,d:1,e:1,f:1,g:1}"), "DE 00 10 A1 31 01 A1 32 01 A1 33 01 A1 34 01 A1 35 01 A1 36 01 A1 37 01 A1 38 01 A1 39 01 A1 61 01 A1 62 01 A1 63 01 A1 64 01 A1 65 01 A1 66 01 A1 67 01"); + + byte[] b = MsgPackSerializer.DEFAULT.serialize(new Person()); + System.err.println(TestUtils.toReadableBytes2(b)); + } + + public static class Person { + public String name = "John Smith"; + public int age = 21; + } + + private void test(Object input, String expected) throws Exception { + byte[] b = MsgPackSerializer.DEFAULT.serialize(input); + assertEquals(expected, TestUtils.toReadableBytes2(b)); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanMapTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanMapTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanMapTest.java new file mode 100755 index 0000000..7ed0919 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanMapTest.java @@ -0,0 +1,96 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.transforms; + +import static org.junit.Assert.*; + +import org.apache.juneau.*; +import org.apache.juneau.transform.*; +import org.junit.*; + +public class BeanMapTest { + + //==================================================================================================== + // testFilteredEntry + //==================================================================================================== + @Test + public void testFilteredEntry() throws Exception { + BeanContext bc = ContextFactory.create().addTransforms(ByteArrayBase64Transform.class).getBeanContext(); + BeanMap<A> m = bc.forBean(new A()); + + assertEquals("AQID", m.get("f1")); + m.put("f1", "BAUG"); + assertEquals("BAUG", m.get("f1")); + assertEquals(4, m.getBean().f1[0]); + + assertNull(m.get("f3")); + } + + public static class A { + public byte[] f1 = new byte[]{1,2,3}; + public byte[] f3 = null; + } + + //==================================================================================================== + // testFilteredEntryWithMultipleMatchingFilters + // When bean properties can have multiple filters applied to them, pick the first match. + //==================================================================================================== + @Test + public void testFilteredEntryWithMultipleMatchingFilters() throws Exception { + BeanContext bc = ContextFactory.create().addTransforms(B2Filter.class,B1Filter.class).getBeanContext(); + BeanMap<B> bm = bc.forBean(B.create()); + ObjectMap om = (ObjectMap)bm.get("b1"); + assertEquals("b2", om.getString("type")); + + bc = ContextFactory.create().addTransforms(B1Filter.class,B2Filter.class).getBeanContext(); + bm = bc.forBean(B.create()); + om = (ObjectMap)bm.get("b1"); + assertEquals("b1", om.getString("type")); + } + + + public static class B { + public B1 b1; + + static B create() { + B b = new B(); + B2 b2 = new B2(); + b2.f1 = "f1"; + b2.f2 = "f2"; + b.b1 = b2; + return b; + } + } + + public static class B1 { + public String f1; + } + + public static class B2 extends B1 { + public String f2; + } + + public static class B1Filter extends PojoTransform<B1,ObjectMap> { + @Override /* PojoTransform */ + public ObjectMap transform(B1 b1) { + return new ObjectMap().append("type", "b1").append("f1", b1.f1); + } + } + + public static class B2Filter extends PojoTransform<B2,ObjectMap> { + @Override /* PojoTransform */ + public ObjectMap transform(B2 b2) { + return new ObjectMap().append("type", "b2").append("f1", b2.f1); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanTransformTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanTransformTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanTransformTest.java new file mode 100755 index 0000000..a0b7843 --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/BeanTransformTest.java @@ -0,0 +1,204 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.transforms; + +import static org.apache.juneau.TestUtils.*; +import static org.junit.Assert.*; + +import org.apache.juneau.*; +import org.apache.juneau.annotation.*; +import org.junit.*; + +public class BeanTransformTest { + + //==================================================================================================== + // Transformed interfaces + //==================================================================================================== + @Test + public void testTransformedInterfaces() throws Exception { + BeanContext bc; + BeanMap<A3> bm; + + bc = ContextFactory.create().addTransforms(A1.class).getBeanContext(); + bm = bc.newBeanMap(A3.class); + assertEquals("f1", bm.get("f1")); + assertNull(bm.get("f2")); + assertNull(bm.get("f3")); + + bc = ContextFactory.create().addTransforms(A2.class).getBeanContext(); + bm = bc.newBeanMap(A3.class); + assertEquals("f1", bm.get("f1")); + assertEquals("f2", bm.get("f2")); + assertNull(bm.get("f3")); + } + + public static interface A1 { + public String getF1(); + } + + public static interface A2 extends A1 { + public String getF2(); + } + + public static class A3 implements A2 { + @Override /* A1 */ + public String getF1() { + return "f1"; + } + @Override /* A2 */ + public String getF2() { + return "f2"; + } + public String getF3() { + return "f3"; + } + } + + //==================================================================================================== + // Transformed abstract classes + //==================================================================================================== + @Test + public void testTransformedAbstractClasses() throws Exception { + BeanContext bc; + BeanMap<Test2> bm; + + bc = ContextFactory.create().addTransforms(B1.class).getBeanContext(); + bm = bc.newBeanMap(Test2.class); + assertEquals("f1", bm.get("f1")); + assertNull(bm.get("f2")); + assertNull(bm.get("f3")); + + bc = ContextFactory.create().addTransforms(B2.class).getBeanContext(); + bm = bc.newBeanMap(Test2.class); + assertEquals("f1", bm.get("f1")); + assertEquals("f2", bm.get("f2")); + assertNull(bm.get("f3")); + } + + public abstract static class B1 { + public abstract String getF1(); + } + + public abstract static class B2 extends B1 { + @Override /* B1 */ + public abstract String getF1(); + public abstract String getF2(); + } + + public static class Test2 extends B2 { + @Override /* B1 */ + public String getF1() { + return "f1"; + } + @Override /* B2 */ + public String getF2() { + return "f2"; + } + public String getF3() { + return "f3"; + } + } + + //==================================================================================================== + // Transformed with stop classes + //==================================================================================================== + @Test + public void testTransformedWithStopClass() throws Exception { + C3 c3 = new C3(); + assertObjectEquals("{f3:3,p3:3}", c3); + } + + public class C1 { + public int f1 = 1; + public int getP1() { return 1; } + } + + public class C2 extends C1 { + public int f2 = 2; + public int getP2() { return 2; } + } + + @Bean(stopClass=C2.class) + public class C3 extends C2 { + public int f3 = 3; + public int getP3() { return 3; } + } + + @Test + public void testTransformedWithStopClassOnParentClass() throws Exception { + D3 d3 = new D3(); + assertObjectEquals("{f3:3,p3:3}", d3); + } + + public class D1 { + public int f1 = 1; + public int getP1() { return 1; } + } + + @Bean(stopClass=D2.class) + public class D2 extends D1 { + public int f2 = 2; + public int getP2() { return 2; } + } + + public class D3 extends D2 { + public int f3 = 3; + public int getP3() { return 3; } + } + + @Test + public void testTransformedWithStopClassOnParentClassWithOverriddenAnnotation() throws Exception { + E3 e3 = new E3(); + assertObjectEquals("{f3:3,p3:3}", e3); + } + + public class E1 { + public int f1 = 1; + public int getP1() { return 1; } + } + + @Bean(stopClass=E2.class) + public class E2 extends E1 { + public int f2 = 2; + public int getP2() { return 2; } + } + + @Bean(excludeProperties={"foo"}) + public class E3 extends E2 { + public int f3 = 3; + public int getP3() { return 3; } + } + + @Test + public void testTransformedWithStopClassesAtMulitpleLevels() throws Exception { + F3 e3 = new F3(); + assertObjectEquals("{f3:3,p3:3}", e3); + } + + @Bean(stopClass=F1.class) + public class F1 { + public int f1 = 1; + public int getP1() { return 1; } + } + + public class F2 extends F1 { + public int f2 = 2; + public int getP2() { return 2; } + } + + @Bean(stopClass=F2.class) + public class F3 extends F2 { + public int f3 = 3; + public int getP3() { return 3; } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/ByteArrayBase64TransformTest.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/ByteArrayBase64TransformTest.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/ByteArrayBase64TransformTest.java new file mode 100755 index 0000000..174a98e --- /dev/null +++ b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/ByteArrayBase64TransformTest.java @@ -0,0 +1,172 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.transforms; + +import static org.apache.juneau.serializer.SerializerContext.*; +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.a.rttests.*; +import org.apache.juneau.json.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.junit.*; + +@SuppressWarnings({"unchecked","hiding","serial"}) +public class ByteArrayBase64TransformTest extends RoundTripTest { + + public ByteArrayBase64TransformTest(String label, Serializer s, Parser p, int flags) throws Exception { + super(label, s, p, flags); + } + + @Override /* RoundTripTest */ + public Class<?>[] getTransforms() { + return new Class<?>[] { + ByteArrayBase64Transform.class + }; + } + + //==================================================================================================== + // testPrimitiveArrays + //==================================================================================================== + @Test + public void testPrimitiveArrays() throws Exception { + WriterSerializer s = new JsonSerializer.Simple().addTransforms(ByteArrayBase64Transform.class).setProperty(SERIALIZER_trimNullProperties, false); + + byte[] a1 = {1,2,3}; + assertEquals("'AQID'", s.serialize(a1)); + a1 = roundTrip(a1, byte[].class); + assertEquals(1, a1[0]); + + byte[][] a2 = {{1,2,3},{4,5,6},null}; + assertEquals("['AQID','BAUG',null]", s.serialize(a2)); + a2 = roundTrip(a2, byte[][].class); + assertEquals(1, a2[0][0]); + assertNull(a2[2]); + + byte[] a3 = null; + assertEquals("null", s.serialize(a3)); + a3 = roundTrip(a3, byte[].class); + assertNull(a3); + + if (p == null) + return; + + List<byte[]> fl = new ArrayList<byte[]>() {{ + add(new byte[]{1,2,3}); + add(new byte[]{4,5,6}); + add(null); + }}; + assertEquals("['AQID','BAUG',null]", s.serialize(fl)); + fl = roundTrip(fl, p.getBeanContext().getCollectionClassMeta(List.class, byte[].class)); + assertEquals(1, fl.get(0)[0]); + assertEquals(5, fl.get(1)[1]); + assertNull(fl.get(2)); + + Map<String,byte[]> fm = new LinkedHashMap<String,byte[]>() {{ + put("foo", new byte[]{1,2,3}); + put("bar", null); + put(null, new byte[]{4,5,6}); + put("null", new byte[]{7,8,9}); + }}; + fm = roundTrip(fm, p.getBeanContext().getMapClassMeta(Map.class, String.class, byte[].class)); + assertEquals(1, fm.get("foo")[0]); + assertNull(fm.get(1)); + assertEquals(5, fm.get(null)[1]); + assertEquals(8, fm.get("null")[1]); + } + + //==================================================================================================== + // testBean + //==================================================================================================== + @Test + public void testBean() throws Exception { + A t = new A().init(); + t = roundTrip(t, A.class); + assertEquals(1, t.f1[0]); + assertEquals(4, t.f2[1][0]); + assertNull(t.f2[2]); + assertNull(t.f3); + assertEquals(1, t.fl.get(0)[0]); + assertNull(t.fl.get(2)); + assertEquals(1, t.fm.get("foo")[0]); + assertNull(t.fm.get("bar")); + assertEquals(4, t.fm.get(null)[0]); + assertEquals(1, t.flb.get(0).fl.get(0)[0]); + assertNull(t.flb.get(1)); + assertEquals(1, t.fmb.get("foo").fl.get(0)[0]); + assertNull(t.fmb.get("bar")); + } + + public static class A { + public byte[] f1; + public byte[][] f2; + public byte[] f3; + public List<byte[]> fl; + public Map<String,byte[]> fm; + public List<B> flb; + public Map<String,B> fmb; + + public A init() { + f1 = new byte[]{1,2,3}; + f2 = new byte[][]{{1,2,3},{4,5,6},null}; + f3 = null; + fl = new ArrayList<byte[]>() {{ + add(new byte[]{1,2,3}); + add(new byte[]{4,5,6}); + add(null); + }}; + fm = new LinkedHashMap<String,byte[]>() {{ + put("foo", new byte[]{1,2,3}); + put("bar", null); + put(null, new byte[]{4,5,6}); + }}; + flb = new ArrayList<B>() {{ + add(new B().init()); + add(null); + }}; + fmb = new LinkedHashMap<String,B>() {{ + put("foo", new B().init()); + put("bar", null); + put(null, new B().init()); + }}; + return this; + } + } + + public static class B { + public byte[] f1; + public byte[][] f2; + public byte[] f3; + public List<byte[]> fl; + public Map<String,byte[]> fm; + + public B init() { + f1 = new byte[]{1,2,3}; + f2 = new byte[][]{{1,2,3},{4,5,6},null}; + f3 = null; + fl = new ArrayList<byte[]>() {{ + add(new byte[]{1,2,3}); + add(new byte[]{4,5,6}); + add(null); + }}; + fm = new LinkedHashMap<String,byte[]>() {{ + put("foo", new byte[]{1,2,3}); + put("bar", null); + put(null, new byte[]{4,5,6}); + }}; + return this; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanMap.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanMap.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanMap.java deleted file mode 100755 index edb671b..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanMap.java +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.transforms; - -import static org.junit.Assert.*; - -import org.apache.juneau.*; -import org.apache.juneau.transform.*; -import org.junit.*; - -public class CT_BeanMap { - - //==================================================================================================== - // testFilteredEntry - //==================================================================================================== - @Test - public void testFilteredEntry() throws Exception { - BeanContext bc = ContextFactory.create().addTransforms(ByteArrayBase64Transform.class).getBeanContext(); - BeanMap<A> m = bc.forBean(new A()); - - assertEquals("AQID", m.get("f1")); - m.put("f1", "BAUG"); - assertEquals("BAUG", m.get("f1")); - assertEquals(4, m.getBean().f1[0]); - - assertNull(m.get("f3")); - } - - public static class A { - public byte[] f1 = new byte[]{1,2,3}; - public byte[] f3 = null; - } - - //==================================================================================================== - // testFilteredEntryWithMultipleMatchingFilters - // When bean properties can have multiple filters applied to them, pick the first match. - //==================================================================================================== - @Test - public void testFilteredEntryWithMultipleMatchingFilters() throws Exception { - BeanContext bc = ContextFactory.create().addTransforms(B2Filter.class,B1Filter.class).getBeanContext(); - BeanMap<B> bm = bc.forBean(B.create()); - ObjectMap om = (ObjectMap)bm.get("b1"); - assertEquals("b2", om.getString("type")); - - bc = ContextFactory.create().addTransforms(B1Filter.class,B2Filter.class).getBeanContext(); - bm = bc.forBean(B.create()); - om = (ObjectMap)bm.get("b1"); - assertEquals("b1", om.getString("type")); - } - - - public static class B { - public B1 b1; - - static B create() { - B b = new B(); - B2 b2 = new B2(); - b2.f1 = "f1"; - b2.f2 = "f2"; - b.b1 = b2; - return b; - } - } - - public static class B1 { - public String f1; - } - - public static class B2 extends B1 { - public String f2; - } - - public static class B1Filter extends PojoTransform<B1,ObjectMap> { - @Override /* PojoTransform */ - public ObjectMap transform(B1 b1) { - return new ObjectMap().append("type", "b1").append("f1", b1.f1); - } - } - - public static class B2Filter extends PojoTransform<B2,ObjectMap> { - @Override /* PojoTransform */ - public ObjectMap transform(B2 b2) { - return new ObjectMap().append("type", "b2").append("f1", b2.f1); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanTransform.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanTransform.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanTransform.java deleted file mode 100755 index fa1135d..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_BeanTransform.java +++ /dev/null @@ -1,204 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.transforms; - -import static org.apache.juneau.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.junit.*; - -public class CT_BeanTransform { - - //==================================================================================================== - // Transformed interfaces - //==================================================================================================== - @Test - public void testTransformedInterfaces() throws Exception { - BeanContext bc; - BeanMap<A3> bm; - - bc = ContextFactory.create().addTransforms(A1.class).getBeanContext(); - bm = bc.newBeanMap(A3.class); - assertEquals("f1", bm.get("f1")); - assertNull(bm.get("f2")); - assertNull(bm.get("f3")); - - bc = ContextFactory.create().addTransforms(A2.class).getBeanContext(); - bm = bc.newBeanMap(A3.class); - assertEquals("f1", bm.get("f1")); - assertEquals("f2", bm.get("f2")); - assertNull(bm.get("f3")); - } - - public static interface A1 { - public String getF1(); - } - - public static interface A2 extends A1 { - public String getF2(); - } - - public static class A3 implements A2 { - @Override /* A1 */ - public String getF1() { - return "f1"; - } - @Override /* A2 */ - public String getF2() { - return "f2"; - } - public String getF3() { - return "f3"; - } - } - - //==================================================================================================== - // Transformed abstract classes - //==================================================================================================== - @Test - public void testTransformedAbstractClasses() throws Exception { - BeanContext bc; - BeanMap<Test2> bm; - - bc = ContextFactory.create().addTransforms(B1.class).getBeanContext(); - bm = bc.newBeanMap(Test2.class); - assertEquals("f1", bm.get("f1")); - assertNull(bm.get("f2")); - assertNull(bm.get("f3")); - - bc = ContextFactory.create().addTransforms(B2.class).getBeanContext(); - bm = bc.newBeanMap(Test2.class); - assertEquals("f1", bm.get("f1")); - assertEquals("f2", bm.get("f2")); - assertNull(bm.get("f3")); - } - - public abstract static class B1 { - public abstract String getF1(); - } - - public abstract static class B2 extends B1 { - @Override /* B1 */ - public abstract String getF1(); - public abstract String getF2(); - } - - public static class Test2 extends B2 { - @Override /* B1 */ - public String getF1() { - return "f1"; - } - @Override /* B2 */ - public String getF2() { - return "f2"; - } - public String getF3() { - return "f3"; - } - } - - //==================================================================================================== - // Transformed with stop classes - //==================================================================================================== - @Test - public void testTransformedWithStopClass() throws Exception { - C3 c3 = new C3(); - assertObjectEquals("{f3:3,p3:3}", c3); - } - - public class C1 { - public int f1 = 1; - public int getP1() { return 1; } - } - - public class C2 extends C1 { - public int f2 = 2; - public int getP2() { return 2; } - } - - @Bean(stopClass=C2.class) - public class C3 extends C2 { - public int f3 = 3; - public int getP3() { return 3; } - } - - @Test - public void testTransformedWithStopClassOnParentClass() throws Exception { - D3 d3 = new D3(); - assertObjectEquals("{f3:3,p3:3}", d3); - } - - public class D1 { - public int f1 = 1; - public int getP1() { return 1; } - } - - @Bean(stopClass=D2.class) - public class D2 extends D1 { - public int f2 = 2; - public int getP2() { return 2; } - } - - public class D3 extends D2 { - public int f3 = 3; - public int getP3() { return 3; } - } - - @Test - public void testTransformedWithStopClassOnParentClassWithOverriddenAnnotation() throws Exception { - E3 e3 = new E3(); - assertObjectEquals("{f3:3,p3:3}", e3); - } - - public class E1 { - public int f1 = 1; - public int getP1() { return 1; } - } - - @Bean(stopClass=E2.class) - public class E2 extends E1 { - public int f2 = 2; - public int getP2() { return 2; } - } - - @Bean(excludeProperties={"foo"}) - public class E3 extends E2 { - public int f3 = 3; - public int getP3() { return 3; } - } - - @Test - public void testTransformedWithStopClassesAtMulitpleLevels() throws Exception { - F3 e3 = new F3(); - assertObjectEquals("{f3:3,p3:3}", e3); - } - - @Bean(stopClass=F1.class) - public class F1 { - public int f1 = 1; - public int getP1() { return 1; } - } - - public class F2 extends F1 { - public int f2 = 2; - public int getP2() { return 2; } - } - - @Bean(stopClass=F2.class) - public class F3 extends F2 { - public int f3 = 3; - public int getP3() { return 3; } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/df0f8689/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_ByteArrayBase64Transform.java ---------------------------------------------------------------------- diff --git a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_ByteArrayBase64Transform.java b/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_ByteArrayBase64Transform.java deleted file mode 100755 index f616902..0000000 --- a/org.apache.juneau/src/test/java/org/apache/juneau/transforms/CT_ByteArrayBase64Transform.java +++ /dev/null @@ -1,172 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.transforms; - -import static org.apache.juneau.serializer.SerializerContext.*; -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.a.rttests.*; -import org.apache.juneau.json.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.serializer.*; -import org.junit.*; - -@SuppressWarnings({"unchecked","hiding","serial"}) -public class CT_ByteArrayBase64Transform extends RoundTripTest { - - public CT_ByteArrayBase64Transform(String label, Serializer s, Parser p, int flags) throws Exception { - super(label, s, p, flags); - } - - @Override /* RoundTripTest */ - public Class<?>[] getTransforms() { - return new Class<?>[] { - ByteArrayBase64Transform.class - }; - } - - //==================================================================================================== - // testPrimitiveArrays - //==================================================================================================== - @Test - public void testPrimitiveArrays() throws Exception { - WriterSerializer s = new JsonSerializer.Simple().addTransforms(ByteArrayBase64Transform.class).setProperty(SERIALIZER_trimNullProperties, false); - - byte[] a1 = {1,2,3}; - assertEquals("'AQID'", s.serialize(a1)); - a1 = roundTrip(a1, byte[].class); - assertEquals(1, a1[0]); - - byte[][] a2 = {{1,2,3},{4,5,6},null}; - assertEquals("['AQID','BAUG',null]", s.serialize(a2)); - a2 = roundTrip(a2, byte[][].class); - assertEquals(1, a2[0][0]); - assertNull(a2[2]); - - byte[] a3 = null; - assertEquals("null", s.serialize(a3)); - a3 = roundTrip(a3, byte[].class); - assertNull(a3); - - if (p == null) - return; - - List<byte[]> fl = new ArrayList<byte[]>() {{ - add(new byte[]{1,2,3}); - add(new byte[]{4,5,6}); - add(null); - }}; - assertEquals("['AQID','BAUG',null]", s.serialize(fl)); - fl = roundTrip(fl, p.getBeanContext().getCollectionClassMeta(List.class, byte[].class)); - assertEquals(1, fl.get(0)[0]); - assertEquals(5, fl.get(1)[1]); - assertNull(fl.get(2)); - - Map<String,byte[]> fm = new LinkedHashMap<String,byte[]>() {{ - put("foo", new byte[]{1,2,3}); - put("bar", null); - put(null, new byte[]{4,5,6}); - put("null", new byte[]{7,8,9}); - }}; - fm = roundTrip(fm, p.getBeanContext().getMapClassMeta(Map.class, String.class, byte[].class)); - assertEquals(1, fm.get("foo")[0]); - assertNull(fm.get(1)); - assertEquals(5, fm.get(null)[1]); - assertEquals(8, fm.get("null")[1]); - } - - //==================================================================================================== - // testBean - //==================================================================================================== - @Test - public void testBean() throws Exception { - A t = new A().init(); - t = roundTrip(t, A.class); - assertEquals(1, t.f1[0]); - assertEquals(4, t.f2[1][0]); - assertNull(t.f2[2]); - assertNull(t.f3); - assertEquals(1, t.fl.get(0)[0]); - assertNull(t.fl.get(2)); - assertEquals(1, t.fm.get("foo")[0]); - assertNull(t.fm.get("bar")); - assertEquals(4, t.fm.get(null)[0]); - assertEquals(1, t.flb.get(0).fl.get(0)[0]); - assertNull(t.flb.get(1)); - assertEquals(1, t.fmb.get("foo").fl.get(0)[0]); - assertNull(t.fmb.get("bar")); - } - - public static class A { - public byte[] f1; - public byte[][] f2; - public byte[] f3; - public List<byte[]> fl; - public Map<String,byte[]> fm; - public List<B> flb; - public Map<String,B> fmb; - - public A init() { - f1 = new byte[]{1,2,3}; - f2 = new byte[][]{{1,2,3},{4,5,6},null}; - f3 = null; - fl = new ArrayList<byte[]>() {{ - add(new byte[]{1,2,3}); - add(new byte[]{4,5,6}); - add(null); - }}; - fm = new LinkedHashMap<String,byte[]>() {{ - put("foo", new byte[]{1,2,3}); - put("bar", null); - put(null, new byte[]{4,5,6}); - }}; - flb = new ArrayList<B>() {{ - add(new B().init()); - add(null); - }}; - fmb = new LinkedHashMap<String,B>() {{ - put("foo", new B().init()); - put("bar", null); - put(null, new B().init()); - }}; - return this; - } - } - - public static class B { - public byte[] f1; - public byte[][] f2; - public byte[] f3; - public List<byte[]> fl; - public Map<String,byte[]> fm; - - public B init() { - f1 = new byte[]{1,2,3}; - f2 = new byte[][]{{1,2,3},{4,5,6},null}; - f3 = null; - fl = new ArrayList<byte[]>() {{ - add(new byte[]{1,2,3}); - add(new byte[]{4,5,6}); - add(null); - }}; - fm = new LinkedHashMap<String,byte[]>() {{ - put("foo", new byte[]{1,2,3}); - put("bar", null); - put(null, new byte[]{4,5,6}); - }}; - return this; - } - } -} \ No newline at end of file
