diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-07-05 09:53:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-05 09:53:09 +0200 |
commit | 2ca4a89b20a5e629b21ac5970b1963b784096e7f (patch) | |
tree | e4bf178a7461b9fadff5f993c1cdca853af2cfc3 /container-core | |
parent | d701496a9175df1c1c74de24458735395112f20b (diff) | |
parent | 118c4706121fae7ae315081e08727ebdea431b5d (diff) |
Merge pull request #6271 from vespa-engine/henrhoi/json-query-api
Henrhoi/json query api
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/RequestHandlerTestDriver.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/RequestHandlerTestDriver.java b/container-core/src/main/java/com/yahoo/container/jdisc/RequestHandlerTestDriver.java index 132b1153fc5..22933556d9f 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/RequestHandlerTestDriver.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/RequestHandlerTestDriver.java @@ -63,10 +63,16 @@ public class RequestHandlerTestDriver implements AutoCloseable { return sendRequest(uri, method, ""); } + /** Send a POST request */ public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, String body) { return sendRequest(uri, method, ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8))); } + /** Send a POST request with defined content type */ + public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, String body, String contentType) { + return sendRequest(uri, method, ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8)), contentType); + } + public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body) { responseHandler = new MockResponseHandler(); Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method); @@ -78,6 +84,18 @@ public class RequestHandlerTestDriver implements AutoCloseable { return responseHandler; } + public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body, String contentType) { + responseHandler = new MockResponseHandler(); + Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method); + request.context().put("contextVariable", 37); // TODO: Add a method for accepting a Request instead + request.headers().put(com.yahoo.jdisc.http.HttpHeaders.Names.CONTENT_TYPE, contentType); + ContentChannel requestContent = request.connect(responseHandler); + requestContent.write(body, null); + requestContent.close(null); + request.release(); + return responseHandler; + } + /** Replaces all occurrences of 0-9 digits by d's */ public String censorDigits(String s) { return s.replaceAll("[0-9]","d"); |