ErrorResponseMessage extends RexProMessage { public void metaSetFlag(Integer val) { Meta.put(FLAG_META_KEY, val); }  Integer metaGetFlag(); void metaSetFlag(Integer val); public String ErrorMessage; static final Integer INVALID_MESSAGE_ERROR; static final Integer INVALID_SESSION_ERROR; static final Integer SCRIPT_FAILURE_ERROR; static final Integer AUTH_FAILURE_ERROR; static final Integer GRAPH_CONFIG_ERROR; static final Integer CHANNEL_CONFIG_ERROR; static final Integer RESULT_SERIALIZATION_ERROR; static final Integer UNKNOWN_ERROR; }
@Test public void testMetaValidation() { ErrorResponseMessage msg = new ErrorResponseMessage(); msg.setRequestAsUUID(UUID.randomUUID()); msg.setSessionAsUUID(UUID.randomUUID()); msg.metaSetFlag(ErrorResponseMessage.INVALID_SESSION_ERROR); msg.ErrorMessage = "brokenness"; try { msg.metaSetFlag(ErrorResponseMessage.INVALID_MESSAGE_ERROR); msg.validateMetaData(); msg.metaSetFlag(ErrorResponseMessage.INVALID_SESSION_ERROR); msg.validateMetaData(); msg.metaSetFlag(ErrorResponseMessage.SCRIPT_FAILURE_ERROR); msg.validateMetaData(); msg.metaSetFlag(ErrorResponseMessage.AUTH_FAILURE_ERROR); msg.validateMetaData(); } catch (RexProException ex) { Assert.fail(); } try { msg.Meta.put(ErrorResponseMessage.FLAG_META_KEY, "session"); msg.validateMetaData(); } catch (RexProException ex) { } try { msg.Meta.put(ErrorResponseMessage.FLAG_META_KEY, false); msg.validateMetaData(); } catch (RexProException ex) { } try { msg.Meta.put(ErrorResponseMessage.FLAG_META_KEY, 3.14f); msg.validateMetaData(); } catch (RexProException ex) { } }
@Test public void testSerialization() { MessagePack msgpack = new MessagePack(); msgpack.register(RexProMessageMeta.class, MetaTemplate.getInstance()); msgpack.register(RexProBindings.class, RexProBindings.SerializationTemplate.getInstance()); msgpack.register(RexProScriptResult.class, ResultsTemplate.getInstance()); ErrorResponseMessage outMsg = new ErrorResponseMessage(); outMsg.setRequestAsUUID(UUID.randomUUID()); outMsg.setSessionAsUUID(UUID.randomUUID()); outMsg.metaSetFlag(ErrorResponseMessage.INVALID_SESSION_ERROR); outMsg.ErrorMessage = "brokenness"; final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); final Packer packer = msgpack.createPacker(outStream); try { packer.write(outMsg); packer.close(); } catch (IOException ex) { Assert.fail(); } byte[] bytes = outStream.toByteArray(); final ByteArrayInputStream in = new ByteArrayInputStream(bytes); final Unpacker unpacker = msgpack.createUnpacker(in); ErrorResponseMessage inMsg; try { inMsg = unpacker.read(ErrorResponseMessage.class); Assert.assertEquals(outMsg.Meta, inMsg.Meta); Assert.assertEquals(UUID.nameUUIDFromBytes(outMsg.Request), UUID.nameUUIDFromBytes(inMsg.Request)); Assert.assertEquals(UUID.nameUUIDFromBytes(outMsg.Session), UUID.nameUUIDFromBytes(inMsg.Session)); Assert.assertEquals(outMsg.ErrorMessage, inMsg.ErrorMessage); } catch (IOException ex) { Assert.fail(); } }