NewRpcMessageWriter implements RpcMessageWriter { public void write(RpcRequest request) throws RpcException { try { writer.write(buildPar(request)); } catch (IOException e) { throw new RpcException("unable to write request message", e); } } NewRpcMessageWriter(Writer w); void writeStartConnection(String hostname, String address, int localPort); void writeStopConnection(); void write(RpcRequest request); void flush(); static String SPack(String str); static String LPack(String str, int nDigits); static final String PREFIX; }
@Test public void testWriteRequestWithNoParameters() throws RpcException { RpcRequest r = new RpcRequest("FOO BAR"); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR54f\u0004", s.toString()); }
@Test public void testWriteRequestWithLiteralParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); params.add(new RpcParam("baz")); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR50003bazf\u0004", s.toString()); }
@Test public void testWriteRequestWithReferenceParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); params.add(new RpcParam("baz", RpcParam.Type.REFERENCE)); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR51003bazf\u0004", s.toString()); }
@Test public void testWriteRequestWithEmptyParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); params.add(new RpcParam("baz", RpcParam.Type.EMPTY)); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR54f\u0004", s.toString()); }
@Test public void testWriteRequestWithListParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); Mult mult = new Mult(); mult.put("baz", "spaz"); mult.put("waz", "craz"); params.add(new RpcParam(mult)); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR52003baz004spazt003waz004crazf\u0004", s.toString()); }
@Test public void testWriteRequestWithGlobalParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); Mult mult = new Mult(); mult.put("baz", "spaz"); params.add(new RpcParam(mult, RpcParam.Type.GLOBAL)); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR53003baz004spazf\u0004", s.toString()); }
@Test public void testWriteRequestWithStreamParameter() throws RpcException { List<RpcParam> params = new ArrayList<RpcParam>(); params.add(new RpcParam("baz", RpcParam.Type.STREAM)); RpcRequest r = new RpcRequest("FOO BAR", params); w.write(r); assertEquals("[XWB]11302\u00010\u0007FOO BAR55003bazf\u0004", s.toString()); }