@Test public void noParamsRequestTest() { Request<Void> request = new Request<Void>(1, "method", null); request.setSessionId("xxxxxxx"); String requestJson = request.toString(); Assert.assertEquals( "{\"id\":1,\"method\":\"method\",\"jsonrpc\":\"2.0\",\"params\":{\"sessionId\":\"xxxxxxx\"}}", requestJson); log.info(requestJson); Request<Void> newRequest = JsonUtils.fromJsonRequest(requestJson, Void.class); // Assert.assertEquals(null, newRequest.getParams()); Assert.assertEquals(newRequest.getSessionId(), "xxxxxxx"); }
@Test public void requestTest() { Params params = new Params(); params.param1 = "Value1"; Request<Params> request = new Request<Params>(1, "method", params); request.setSessionId("xxxxxxx"); String requestJson = request.toString(); Assert.assertEquals( "{\"id\":1,\"method\":\"method\",\"params\":{\"param1\":\"Value1\",\"sessionId\":\"xxxxxxx\"},\"jsonrpc\":\"2.0\"}", requestJson); log.info(requestJson); Request<Params> newRequest = JsonUtils.fromJsonRequest(requestJson, Params.class); Assert.assertEquals(params.param1, newRequest.getParams().param1); Assert.assertEquals(newRequest.getSessionId(), "xxxxxxx"); }
@Test public void requestTest() { Params params = new Params(); params.param1 = "Value1"; params.param2 = "Value2"; params.data = new Data(); params.data.data1 = "XX"; params.data.data2 = "YY"; Request<Params> request = new Request<Params>(1, "method", params); String requestJson = JsonUtils.toJsonRequest(request); log.info(requestJson); Request<Params> newRequest = JsonUtils.fromJsonRequest(requestJson, Params.class); Assert.assertEquals(params.param1, newRequest.getParams().param1); Assert.assertEquals(params.param2, newRequest.getParams().param2); Assert.assertEquals(params.data.data1, newRequest.getParams().data.data1); Assert.assertEquals(params.data.data2, newRequest.getParams().data.data2); }