0
|
1 package org.msgpack.annotation;
|
|
2
|
|
3 import static org.junit.Assert.assertEquals;
|
|
4
|
|
5 import java.io.ByteArrayOutputStream;
|
|
6
|
|
7 import org.junit.Test;
|
|
8 import org.msgpack.MessagePack;
|
|
9 import org.msgpack.packer.Packer;
|
|
10 import org.msgpack.template.Template;
|
|
11 import org.msgpack.template.TemplateRegistry;
|
|
12 import org.msgpack.template.builder.ReflectionTemplateBuilder;
|
|
13 import org.msgpack.unpacker.BufferUnpacker;
|
|
14
|
|
15
|
|
16 public class TestOptionalReflectionBufferPackBufferUnpack {
|
|
17
|
|
18 @org.junit.Ignore
|
|
19 public static class TestMessagePack extends TestSetOptional {
|
|
20 public void testOptional0101() throws Exception {
|
|
21 super.testOptional0101();
|
|
22 }
|
|
23
|
|
24 public MyMessage01 testOptional0101(MyMessage01 src) throws Exception {
|
|
25 MessagePack msgpack = new MessagePack();
|
|
26 TemplateRegistry registry = new TemplateRegistry(null);
|
|
27 ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
|
|
28 Template<MyMessage01> tmpl01 = builder.buildTemplate(MyMessage01.class);
|
|
29 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
30 Packer packer = msgpack.createPacker(out);
|
|
31 tmpl01.write(packer, src);
|
|
32 byte[] bytes = out.toByteArray();
|
|
33 BufferUnpacker unpacker = msgpack.createBufferUnpacker();
|
|
34 unpacker.resetReadByteCount();
|
|
35 unpacker.wrap(bytes);
|
|
36 MyMessage01 dst = tmpl01.read(unpacker, null);
|
|
37 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
38 return dst;
|
|
39 }
|
|
40
|
|
41 public void testOptional0102() throws Exception {
|
|
42 super.testOptional0102();
|
|
43 }
|
|
44
|
|
45 public MyMessage02 testOptional0102(MyMessage01 src) throws Exception {
|
|
46 MessagePack msgpack = new MessagePack();
|
|
47 TemplateRegistry registry = new TemplateRegistry(null);
|
|
48 ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
|
|
49 Template<MyMessage01> tmpl01 = builder.buildTemplate(MyMessage01.class);
|
|
50 Template<MyMessage02> tmpl02 = builder.buildTemplate(MyMessage02.class);
|
|
51 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
52 Packer packer = msgpack.createPacker(out);
|
|
53 tmpl01.write(packer, src);
|
|
54 byte[] bytes = out.toByteArray();
|
|
55 BufferUnpacker unpacker = msgpack.createBufferUnpacker();
|
|
56 unpacker.resetReadByteCount();
|
|
57 unpacker.wrap(bytes);
|
|
58 MyMessage02 dst = tmpl02.read(unpacker, null);
|
|
59 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
60 return dst;
|
|
61 }
|
|
62
|
|
63 public void testOptional0103() throws Exception {
|
|
64 super.testOptional0103();
|
|
65 }
|
|
66
|
|
67 public MyMessage03 testOptional0103(MyMessage01 src) throws Exception {
|
|
68 MessagePack msgpack = new MessagePack();
|
|
69 TemplateRegistry registry = new TemplateRegistry(null);
|
|
70 ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
|
|
71 Template<MyMessage01> tmpl01 = builder.buildTemplate(MyMessage01.class);
|
|
72 Template<MyMessage03> tmpl03 = builder.buildTemplate(MyMessage03.class);
|
|
73 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
74 Packer packer = msgpack.createPacker(out);
|
|
75 tmpl01.write(packer, src);
|
|
76 byte[] bytes = out.toByteArray();
|
|
77 BufferUnpacker unpacker = msgpack.createBufferUnpacker();
|
|
78 unpacker.resetReadByteCount();
|
|
79 unpacker.wrap(bytes);
|
|
80 MyMessage03 dst = tmpl03.read(unpacker, null);
|
|
81 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
82 return dst;
|
|
83 }
|
|
84
|
|
85 public void testOptional0203() throws Exception {
|
|
86 super.testOptional0203();
|
|
87 }
|
|
88
|
|
89 public MyMessage03 testOptional0202(MyMessage02 src) throws Exception {
|
|
90 MessagePack msgpack = new MessagePack();
|
|
91 TemplateRegistry registry = new TemplateRegistry(null);
|
|
92 ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry);
|
|
93 Template<MyMessage02> tmpl02 = builder.buildTemplate(MyMessage02.class);
|
|
94 Template<MyMessage03> tmpl03 = builder.buildTemplate(MyMessage03.class);
|
|
95 ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
96 Packer packer = msgpack.createPacker(out);
|
|
97 tmpl02.write(packer, src);
|
|
98 byte[] bytes = out.toByteArray();
|
|
99 BufferUnpacker unpacker = msgpack.createBufferUnpacker();
|
|
100 unpacker.resetReadByteCount();
|
|
101 unpacker.wrap(bytes);
|
|
102 MyMessage03 dst = tmpl03.read(unpacker, null);
|
|
103 assertEquals(bytes.length, unpacker.getReadByteCount());
|
|
104 return dst;
|
|
105 }
|
|
106 }
|
|
107
|
|
108 @Test
|
|
109 public void test0101() throws Exception {
|
|
110 new TestMessagePack().testOptional0101();
|
|
111 }
|
|
112 @Test
|
|
113 public void test0102() throws Exception {
|
|
114 new TestMessagePack().testOptional0102();
|
|
115 }
|
|
116 @Test
|
|
117 public void test0103() throws Exception {
|
|
118 new TestMessagePack().testOptional0103();
|
|
119 }
|
|
120 @Test
|
|
121 public void test0203() throws Exception {
|
|
122 new TestMessagePack().testOptional0203();
|
|
123 }
|
|
124 }
|