ScriptResponseMessage extends RexProMessage { public static byte[] convertResultToBytes(final Object result) throws Exception { return converter.convert(result); }  static byte[] convertResultToBytes(final Object result); public RexProScriptResult Results; public RexProBindings Bindings; }
@Test public void serializeString() throws Exception { byte[] bytes = ScriptResponseMessage.convertResultToBytes("xyz"); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); Assert.assertEquals("xyz", dst); }
@Test public void serializeInt() throws Exception { byte[] bytes = ScriptResponseMessage.convertResultToBytes(31); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); Assert.assertEquals(31L, dst); }
@Test public void serializeFloat() throws Exception { byte[] bytes = ScriptResponseMessage.convertResultToBytes(1.2); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); Assert.assertEquals(1.2, dst); }
@Test public void serializeBool() throws Exception { byte[] bytes = ScriptResponseMessage.convertResultToBytes(true); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); Assert.assertEquals(true, dst); }
@Test public void serializeArray() throws Exception { ArrayList<Object> srcArray = new ArrayList<Object>(); srcArray.add(true); srcArray.add("abc"); srcArray.add(1L); byte[] bytes = ScriptResponseMessage.convertResultToBytes(srcArray); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); Assert.assertEquals(srcArray, dst); }
@Test public void serializeMap() throws Exception { HashMap<Object, Object> srcMap = new HashMap<Object, Object>(); srcMap.put("city", "LA"); srcMap.put(1L, 2L); ArrayList<Object> arr = new ArrayList<Object>(); arr.add(1L); arr.add("str"); arr.add(true); srcMap.put(1.2d, arr); byte[] bytes = ScriptResponseMessage.convertResultToBytes(srcMap); Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); Object dst = ResultsConverter.deserializeObject(unpacker.readValue()); for (Object key : srcMap.keySet()) { Assert.assertEquals(srcMap.get(key), ((HashMap<Object, Object>) dst).get(key)); } }