diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/org/msgpack/util/json/TestSimpleJSONPackUnpack.java	Sat Oct 18 15:06:15 2014 +0900
@@ -0,0 +1,47 @@
+package org.msgpack.util.json;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.msgpack.MessagePack;
+import org.msgpack.type.Value;
+import org.msgpack.type.ValueFactory;
+import org.msgpack.util.json.JSONBufferPacker;
+import org.msgpack.util.json.JSONBufferUnpacker;
+
+
+public class TestSimpleJSONPackUnpack {
+    @Test
+    public void testSimplePackUnpack() throws IOException {
+        MessagePack msgpack = new MessagePack();
+
+        Value v = ValueFactory.createMapValue(new Value[] {
+                        ValueFactory.createRawValue("k1"),
+                        ValueFactory.createIntegerValue(1),
+                        ValueFactory.createRawValue("k2"),
+                        ValueFactory.createArrayValue(new Value[] {
+                            ValueFactory.createNilValue(),
+                            ValueFactory.createBooleanValue(true),
+                            ValueFactory.createBooleanValue(false)
+                        }),
+                        ValueFactory.createRawValue("k3"),
+                        ValueFactory.createFloatValue(0.1)
+                    });
+
+        JSONBufferPacker pk = new JSONBufferPacker(msgpack);
+        pk.write(v);
+
+        byte[] raw = pk.toByteArray();
+
+        String str = new String(raw);
+        assertEquals("{\"k1\":1,\"k2\":[null,true,false],\"k3\":0.1}", str);
+
+        JSONBufferUnpacker u = new JSONBufferUnpacker(msgpack).wrap(raw);
+        Value v2 = u.readValue();
+
+        assertEquals(v, v2);
+    }
+}
+