comparison src/test/java/org/msgpack/util/json/TestSimpleJSONPackUnpack.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.util.json;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.IOException;
6
7 import org.junit.Test;
8 import org.msgpack.MessagePack;
9 import org.msgpack.type.Value;
10 import org.msgpack.type.ValueFactory;
11 import org.msgpack.util.json.JSONBufferPacker;
12 import org.msgpack.util.json.JSONBufferUnpacker;
13
14
15 public class TestSimpleJSONPackUnpack {
16 @Test
17 public void testSimplePackUnpack() throws IOException {
18 MessagePack msgpack = new MessagePack();
19
20 Value v = ValueFactory.createMapValue(new Value[] {
21 ValueFactory.createRawValue("k1"),
22 ValueFactory.createIntegerValue(1),
23 ValueFactory.createRawValue("k2"),
24 ValueFactory.createArrayValue(new Value[] {
25 ValueFactory.createNilValue(),
26 ValueFactory.createBooleanValue(true),
27 ValueFactory.createBooleanValue(false)
28 }),
29 ValueFactory.createRawValue("k3"),
30 ValueFactory.createFloatValue(0.1)
31 });
32
33 JSONBufferPacker pk = new JSONBufferPacker(msgpack);
34 pk.write(v);
35
36 byte[] raw = pk.toByteArray();
37
38 String str = new String(raw);
39 assertEquals("{\"k1\":1,\"k2\":[null,true,false],\"k3\":0.1}", str);
40
41 JSONBufferUnpacker u = new JSONBufferUnpacker(msgpack).wrap(raw);
42 Value v2 = u.readValue();
43
44 assertEquals(v, v2);
45 }
46 }
47