0
|
1 package org.msgpack.template;
|
|
2
|
|
3 import static org.junit.Assert.assertEquals;
|
|
4
|
|
5 import java.io.IOException;
|
|
6 import java.nio.ByteBuffer;
|
|
7 import java.util.List;
|
|
8 import java.util.Map;
|
|
9 import java.util.Collection;
|
|
10 import java.util.Date;
|
|
11 import java.math.BigInteger;
|
|
12 import java.math.BigDecimal;
|
|
13 import java.util.ArrayList;
|
|
14
|
|
15 import org.msgpack.MessagePack;
|
|
16 import org.msgpack.packer.BufferPacker;
|
|
17 import org.msgpack.unpacker.Unpacker;
|
|
18
|
|
19 import static org.msgpack.template.Templates.*;
|
|
20
|
|
21 import org.junit.Test;
|
|
22
|
|
23
|
|
24 public class TestTemplates {
|
|
25 public static enum MyEnum {
|
|
26 A, B, C;
|
|
27 }
|
|
28
|
|
29 @SuppressWarnings("unused")
|
|
30 @Test
|
|
31 public void testGenericsTypesCompliable() throws IOException {
|
|
32 Template<Byte> tbyte = TByte;
|
|
33 Template<Short> tshort = TShort;
|
|
34 Template<Integer> tinteger = TInteger;
|
|
35 Template<Long> tlong = TLong;
|
|
36 Template<Character> tcharacter = TCharacter;
|
|
37 Template<BigInteger> tbiginteger = TBigInteger;
|
|
38 Template<BigDecimal> tbigdecimail = TBigDecimal;
|
|
39 Template<Float> tfloat = TFloat;
|
|
40 Template<Double> tdouble = TDouble;
|
|
41 Template<Boolean> tboolean = TBoolean;
|
|
42 Template<String> tstring = TString;
|
|
43 Template<byte[]> tbytearray = TByteArray;
|
|
44 Template<ByteBuffer> tbytebuffer = TByteBuffer;
|
|
45 Template<Date> tdate = TDate;
|
|
46
|
|
47 Template<List<String>> tlist = tList(TString);
|
|
48 Template<Map<String,Integer>> tmap = tMap(TString, TInteger);
|
|
49 Template<Collection<Long>> tcollection = tCollection(TLong);
|
|
50 Template<MyEnum> tordinalenum = tOrdinalEnum(MyEnum.class);
|
|
51 }
|
|
52
|
|
53 @Test
|
|
54 public void testList() throws IOException {
|
|
55 MessagePack msgpack = new MessagePack();
|
|
56
|
|
57 BufferPacker pk = msgpack.createBufferPacker();
|
|
58
|
|
59 Template<List<String>> t = tList(TString);
|
|
60 List<String> list1 = new ArrayList<String>();
|
|
61 list1.add("a");
|
|
62 list1.add("b");
|
|
63 t.write(pk, list1);
|
|
64
|
|
65 byte[] raw = pk.toByteArray();
|
|
66 Unpacker u = msgpack.createBufferUnpacker(raw);
|
|
67 List<String> list2 = t.read(u, new ArrayList<String>());
|
|
68
|
|
69 assertEquals(list1, list2);
|
|
70 }
|
|
71 }
|
|
72
|