comparison src/test/java/org/msgpack/annotation/TestOptionalReflectionPackUnpack.java @ 0:cb825acd883a

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