diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-10-14 15:21:15 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-10-14 15:21:15 +0200 |
commit | 3ad3556fd9c5d1162ad948916872b6122f8f4452 (patch) | |
tree | f3da5454f4da427bd1a9df9785b302c68aacebf4 /vespaclient-container-plugin | |
parent | c430a9ed1a8afaeae4b96a7df18a056bfd13a437 (diff) |
Test empty payload for document POST, and fix indentation
Diffstat (limited to 'vespaclient-container-plugin')
2 files changed, 29 insertions, 19 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java index df837970168..ff36c108572 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java @@ -211,27 +211,27 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { }; HttpRequest request = (HttpRequest) rawRequest; - try { - Path requestPath = new Path(request.getUri()); - for (String path : handlers.keySet()) - if (requestPath.matches(path)) { - Map<Method, Handler> methods = handlers.get(path); - if (methods.containsKey(request.getMethod())) - return methods.get(request.getMethod()).handle(request, new DocumentPath(requestPath), responseHandler); + try { + Path requestPath = new Path(request.getUri()); + for (String path : handlers.keySet()) + if (requestPath.matches(path)) { + Map<Method, Handler> methods = handlers.get(path); + if (methods.containsKey(request.getMethod())) + return methods.get(request.getMethod()).handle(request, new DocumentPath(requestPath), responseHandler); - if (request.getMethod() == OPTIONS) - options(methods.keySet(), responseHandler); + if (request.getMethod() == OPTIONS) + options(methods.keySet(), responseHandler); - methodNotAllowed(request, methods.keySet(), responseHandler); - } - notFound(request, handlers.keySet(), responseHandler); - } - catch (IllegalArgumentException e) { - badRequest(request, e, responseHandler); - } - catch (RuntimeException e) { - serverError(request, e, responseHandler); - } + methodNotAllowed(request, methods.keySet(), responseHandler); + } + notFound(request, handlers.keySet(), responseHandler); + } + catch (IllegalArgumentException e) { + badRequest(request, e, responseHandler); + } + catch (RuntimeException e) { + serverError(request, e, responseHandler); + } return ignoredContent; } diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java index e10b162078a..74f49367e88 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java @@ -343,6 +343,16 @@ public class DocumentV1ApiTest { "}", response.readAll()); assertEquals(200, response.getStatus()); + // POST with no payload is a 400 + access.session.expect((__, ___) -> { throw new AssertionError("Not supposed to happen"); }); + response = driver.sendRequest("http://localhost/document/v1/space/music/number/1/two?condition=test%20it", POST, ""); + assertSameJson("{" + + " \"pathId\": \"/document/v1/space/music/number/1/two\"," + + " \"message\": \"Could not read document, no document?\"" + + "}", + response.readAll()); + assertEquals(400, response.getStatus()); + // POST with illegal payload is a 400 access.session.expect((__, ___) -> { throw new AssertionError("Not supposed to happen"); }); response = driver.sendRequest("http://localhost/document/v1/space/music/number/1/two?condition=test%20it", POST, |