@Test public void parseRpcRequest_NoMethodNameGiven_ThrowIllegalArgumentExecption() { // given final String json = "{\"service\":\"x\",\"params\":[{\"data\":\"\"}],\"id\":\"dead-beef\"}"; // when Throwable thrown = catchThrowable(() -> { servlet.parseRpcRequest(json); }); // then assertThat(thrown).isInstanceOf(IllegalArgumentException.class); assertThat(thrown).hasMessage("Missing method name"); }
@Test public void testParseRpcRequestStringNumericId() { String input = "{\"service\":\"x\",\"method\":\"a\",\"params\":[{\"data\":\"\"}],\"id\":\"234234\"}"; JsonRpcRequest request = servlet.parseRpcRequest(input); JsonElement idElement = request.getId(); assertThat(idElement.toString()).isEqualTo("\"234234\""); }
@Test public void testParseRpcRequestNumericId() { String input = "{\"service\":\"x\",\"method\":\"a\",\"params\":[{\"data\":\"\"}],\"id\":123456789}"; JsonRpcRequest request = servlet.parseRpcRequest(input); JsonElement idElement = request.getId(); assertThat(idElement.toString()).isEqualTo("123456789"); }
@Test public void testParseRpcRequestStringId() { String input = "{\"service\":\"x\",\"method\":\"a\",\"params\":[{\"data\":\"\"}],\"id\":\"dead-beef\"}"; JsonRpcRequest request = servlet.parseRpcRequest(input); JsonElement idElement = request.getId(); assertThat(idElement.toString()).isEqualTo("\"dead-beef\""); }
@Test public void parseRpcRequest_NotJson_ThrowIllegalArgumentException() { // given final String json = "xxxx"; // when Throwable thrown = catchThrowable(() -> { servlet.parseRpcRequest(json); }); LOGGER.debug(thrown.getMessage()); // then assertThat(thrown).isInstanceOf(IllegalArgumentException.class); assertThat(thrown).hasMessageContaining("Not a JSON"); }
@Test public void parseRpcRequest_NotValidJson_ThrowIllegalArgumentException() { // given final String json = "xxxx}"; // when Throwable thrown = catchThrowable(() -> { servlet.parseRpcRequest(json); }); LOGGER.debug(thrown.getMessage()); // then assertThat(thrown).isInstanceOf(IllegalArgumentException.class); assertThat(thrown).hasMessageContaining("Malformed"); }
@Test public void testParseRpcRequestNoId() { String input = "{\"service\":\"x\",\"method\":\"a\",\"params\":[{\"data\":\"\"}]}"; JsonRpcRequest request = servlet.parseRpcRequest(input); assertThat(request.getId()).isNull(); }
@Test public void testParseRpcRequestNullId() { String input = "{\"service\":\"x\",\"method\":\"a\",\"params\":[{\"data\":\"\"}],\"id\":null}"; JsonRpcRequest request = servlet.parseRpcRequest(input); assertThat(request.getId()).isInstanceOf(JsonNull.class); }
rpcRequest = parseRpcRequest(postedContent); } catch (IllegalArgumentException iaex) { logger.warn("Error parsing request: " + postedContent, iaex);