Skip to content
Permalink
Browse files

http.put query params overloads

  • Loading branch information...
MykolaGolubyev committed Jul 8, 2019
1 parent 82d8de6 commit 1e66ec72594854de1b16c10ff5142db88ec7982b
@@ -105,22 +105,50 @@ class HttpExtensions {
http.post(url, new JsonRequestBody(requestBody))
}

static def put(Http http, String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, Closure validation) {
return http.put(url, queryParams, header, requestBody, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpQueryParams queryParams, HttpHeader header, Map<String, Object> requestBody, Closure validation) {
return http.put(url, queryParams, header, new JsonRequestBody(requestBody), closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpHeader header, Map<String, Object> requestBody, Closure validation) {
return http.put(url, header, new JsonRequestBody(requestBody), closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpHeader header, HttpRequestBody requestBody, Closure validation) {
return http.put(url, header, requestBody, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpQueryParams queryParams, HttpRequestBody requestBody, Closure validation) {
return http.put(url, queryParams, requestBody, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpRequestBody requestBody, Closure validation) {
return http.put(url, requestBody, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpQueryParams queryParams, Map<String, Object> requestBody, Closure validation) {
return http.put(url, queryParams, new JsonRequestBody(requestBody), closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, Map<String, Object> requestBody, Closure validation) {
return http.put(url, new JsonRequestBody(requestBody), closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpQueryParams queryParams, Closure validation) {
return http.put(url, queryParams, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, Closure validation) {
return http.put(url, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpQueryParams queryParams, HttpHeader header, Closure validation) {
return http.put(url, queryParams, header, closureToHttpResponseValidator(validation))
}

static def put(Http http, String url, HttpHeader header, Closure validation) {
return http.put(url, header, closureToHttpResponseValidator(validation))
}
@@ -0,0 +1,175 @@
/*
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.twosigma.webtau.http

import org.junit.Test

import static com.twosigma.webtau.http.Http.http
import static com.twosigma.webtau.http.HttpOverloadsTestCommon.*

class HttpGroovyOverloadsTest extends HttpTestBase {
@Test
void "put without return overloads"() {
http.put("/full-echo", query, requestHeader, requestBodyMap) {
headerValidation.accept(body)
bodyValidation.accept(body)
urlValidation.accept(body)
}

http.put("/full-echo", query, requestHeader, requestBody) {
headerValidation.accept(body)
bodyValidation.accept(body)
urlValidation.accept(body)
}

http.put("/full-echo", query, requestBody) {
bodyValidation.accept(body)
urlValidation.accept(body)
}

http.put("/full-echo", query, requestBodyMap) {
bodyValidation.accept(body)
urlValidation.accept(body)
}

http.put("/full-echo", requestHeader, requestBodyMap) {
headerValidation.accept(body)
bodyValidation.accept(body)
pathValidation.accept(body)
}

http.put("/full-echo", requestHeader, requestBody) {
headerValidation.accept(body)
bodyValidation.accept(body)
pathValidation.accept(body)
}

http.put("/full-echo", query, requestHeader) {
headerValidation.accept(body)
urlValidation.accept(body)
}

http.put("/full-echo", query) {
urlValidation.accept(body)
}

http.put("/full-echo", requestHeader) {
headerValidation.accept(body)
pathValidation.accept(body)
}

http.put("/full-echo", requestBody) {
bodyValidation.accept(body)
pathValidation.accept(body)
}

http.put("/full-echo") {
pathValidation.accept(body)
}
}

@Test
void "put with return overloads"() {
def v
v = http.put("/full-echo", query, requestHeader, requestBodyMap) {
headerValidation.accept(body)
bodyValidation.accept(body)
urlValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

v = http.put("/full-echo", query, requestHeader, requestBody) {
headerValidation.accept(body)
bodyValidation.accept(body)
urlValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

http.put("/full-echo", query, requestBody) {
bodyValidation.accept(body)
urlValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

v = http.put("/full-echo", query, requestBodyMap) {
bodyValidation.accept(body)
urlValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

v = http.put("/full-echo", requestHeader, requestBodyMap) {
headerValidation.accept(body)
bodyValidation.accept(body)
pathValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

v = http.put("/full-echo", requestHeader, requestBody) {
headerValidation.accept(body)
bodyValidation.accept(body)
pathValidation.accept(body)

return body[HEADER_KEY]
}
v.should == HEADER_EXPECTED_RETURN

v = http.put("/full-echo", query, requestHeader) {
headerValidation.accept(body)
urlValidation.accept(body)

return body[HEADER_KEY]
}
v.should == HEADER_EXPECTED_RETURN

v = http.put("/full-echo", query) {
urlValidation.accept(body)
return body[PATH_KEY]
}
v.should == PATH_EXPECTED_RETURN

v = http.put("/full-echo", requestHeader) {
headerValidation.accept(body)
pathValidation.accept(body)
return body[PATH_KEY]
}
v.should == PATH_EXPECTED_RETURN

v = http.put("/full-echo", requestBody) {
bodyValidation.accept(body)
pathValidation.accept(body)

return body[BODY_KEY]
}
v.should == BODY_EXPECTED_RETURN

v = http.put("/full-echo") {
pathValidation.accept(body)
return body[PATH_KEY]
}
v.should == PATH_EXPECTED_RETURN
}
}
@@ -47,31 +47,9 @@ import static com.twosigma.webtau.cfg.WebTauConfig.cfg
import static com.twosigma.webtau.http.Http.*
import static org.junit.Assert.*

class HttpGroovyTest implements HttpConfiguration {
private static final HttpTestDataServer testServer = new HttpTestDataServer()

class HttpGroovyTest extends HttpTestBase {
private static final byte[] sampleFile = [1, 2, 3]

@BeforeClass
static void startServer() {
testServer.start()
}

@AfterClass
static void stopServer() {
testServer.stop()
}

@Before
void initCfg() {
HttpConfigurations.add(this)
}

@After
void cleanCfg() {
HttpConfigurations.remove(this)
}

@Test
void "use groovy closure as validation"() {
http.get("/end-point") {
@@ -1171,20 +1149,6 @@ class HttpGroovyTest implements HttpConfiguration {
ret.getClass().should == Integer
}

@Override
String fullUrl(String url) {
if (UrlUtils.isFull(url)) {
return url
}

return UrlUtils.concat(testServer.uri, url)
}

@Override
HttpHeader fullHeader(String fullUrl, String passedUrl, HttpHeader given) {
return given
}

private static void assertStatusCodeMismatchRegistered() {
http.lastValidationResult.mismatches.should contain(~/statusCode/)
}
@@ -235,18 +235,34 @@ public void post(String url, HttpRequestBody requestBody) {
post(url, requestBody, EMPTY_RESPONSE_VALIDATOR);
}

public <E> E put(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {
return executeAndValidateHttpCall("PUT", url,
public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {
return executeAndValidateHttpCall("PUT", queryParams.attachToUrl(url),
(fullUrl, fullHeader) -> putToFullUrl(fullUrl, fullHeader, requestBody),
header,
requestBody,
validator);
}

public void put(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {
put(url, queryParams, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {
return put(url, HttpQueryParams.EMPTY, header, requestBody, validator);
}

public void put(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {
put(url, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {
return put(url, queryParams, HttpHeader.EMPTY, requestBody, validator);
}

public void put(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidator validator) {
put(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {
return put(url, HttpHeader.EMPTY, requestBody, validator);
}
@@ -255,6 +271,14 @@ public void put(String url, HttpRequestBody requestBody, HttpResponseValidator v
put(url, requestBody, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {
return put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, validator);
}

public void put(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {
put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpResponseValidatorWithReturn validator) {
return put(url, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, validator);
}
@@ -279,6 +303,14 @@ public void put(String url, Map<String, Object> requestBody, HttpResponseValidat
put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {
return put(url, queryParams, header, EmptyRequestBody.INSTANCE, validator);
}

public void put(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {
put(url, queryParams, header, new HttpResponseValidatorIgnoringReturn(validator));
}

public <E> E put(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {
return put(url, header, EmptyRequestBody.INSTANCE, validator);
}
@@ -295,6 +327,10 @@ public void put(String url) {
put(url, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, EMPTY_RESPONSE_VALIDATOR);
}

public void put(String url, HttpQueryParams queryParams) {
put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, EMPTY_RESPONSE_VALIDATOR);
}

public <E> E delete(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {
return executeAndValidateHttpCall("DELETE", url,
this::deleteToFullUrl,
@@ -544,7 +580,6 @@ private HttpResponse followRedirects(String requestMethod, HttpCall httpCall, Ht
}
}

@SuppressWarnings("unchecked")
private DataNode createBodyDataNode(HttpResponse response) {
try {
DataNodeId id = new DataNodeId("body");
@@ -16,8 +16,6 @@

package com.twosigma.webtau.http;

import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;

0 comments on commit 1e66ec7

Please sign in to comment.
You can’t perform that action at this time.