@Test public void testBadJSON() { HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"), "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); assertEquals(400, response.status()); }
@Test public void test() { HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"), "[{\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); assertEquals(202, response.status()); while (ref.get() == null) { Sys.sleep(10); } assertNotNull(ref.get()); }
@Test public void testBadJSONCustomHandler() { serviceEndpointServer.stop(); openPort = PortUtils.findOpenPort(); serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder() .setPort(openPort) .setErrorHandler(new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { final Optional<HttpRequest> httpRequest = new HttpContext().getHttpRequest(); if (httpRequest.isPresent()) { httpRequest.get().getReceiver().respondOK("\"Bad JSON" + throwable.getMessage() + "\""); httpRequest.get().handled(); } } }) .build(); serviceEndpointServer.initServices(new TestService()); serviceEndpointServer.startServerAndWait(); HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"), "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); assertEquals(200, response.status()); }
@Test public void testBadJSONWithReturn() { serviceEndpointServer.stop(); openPort = PortUtils.findOpenPort(); serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder() .setPort(openPort) .setErrorHandler(new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { final Optional<HttpRequest> httpRequest = new HttpContext().getHttpRequest(); if (httpRequest.isPresent()) { httpRequest.get().getReceiver().respondOK("\"Bad JSON" + throwable.getMessage() + "\""); httpRequest.get().handled(); } } }) .build(); serviceEndpointServer.initServices(new TestService()); serviceEndpointServer.startServerAndWait(); HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall2"), "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); puts(response); assertEquals(200, response.status()); }