Skip to content
Permalink
Browse files

http.delete queryParams overload (#458)

  • Loading branch information
MykolaGolubyev committed Nov 25, 2019
1 parent 69427ed commit b1f86fc9689fd8961b0edf6d9510d789f88f7e1d
@@ -161,14 +161,30 @@ class HttpExtensions {
return http.put(url, header, closureToHttpResponseValidator(validation))
}

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

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

static def delete(Http http, String url, Map<String, ?> queryParams, Closure validation) {
return http.delete(url, new HttpQueryParams(queryParams), closureToHttpResponseValidator(validation))
}

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

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

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

private static HttpResponseValidatorWithReturn closureToHttpResponseValidator(validation) {
return new HttpResponseValidatorWithReturn() {
@Override
@@ -180,4 +180,85 @@ class HttpGroovyOverloadsTest extends HttpTestBase {
}
v.should == PATH_EXPECTED_RETURN
}

@Test
void "delete without return overloads"() {
http.delete("/full-echo", query, requestHeader) {
headerValidation.accept(body)
urlValidation.accept(body)
}

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

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

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

http.delete("/full-echo", queryAsMap) {
urlValidation.accept(body)
}

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

@Test
void "delete with return overloads"() {
def number
def expected = 200

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

return header.statusCode
}
number.should == expected

number = http.delete("/full-echo", queryAsMap, requestHeader) {
headerValidation.accept(body)
urlValidation.accept(body)

return header.statusCode
}
number.should == expected

number = http.delete("/full-echo", requestHeader) {
headerValidation.accept(body)
pathValidation.accept(body)

return header.statusCode
}
number.should == expected

number = http.delete("/full-echo", query) {
urlValidation.accept(body)

return header.statusCode
}
number.should == expected

number = http.delete("/full-echo", queryAsMap) {
urlValidation.accept(body)

return header.statusCode
}
number.should == expected

number = http.delete("/full-echo", ) {
pathValidation.accept(body)

return header.statusCode
}
number.should == expected
}
}
@@ -351,32 +351,56 @@ 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,
public <E> E delete(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {
return executeAndValidateHttpCall("DELETE", queryParams.attachToUrl(url),
this::deleteToFullUrl,
header,
null,
validator);
}

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

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

public void delete(String url, HttpHeader header, HttpResponseValidator validator) {
delete(url, header, new HttpResponseValidatorIgnoringReturn(validator));
delete(url, HttpQueryParams.EMPTY, header, new HttpResponseValidatorIgnoringReturn(validator));
}

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

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

public <E> E delete(String url, HttpResponseValidatorWithReturn validator) {
return delete(url, HttpHeader.EMPTY, validator);
return delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, validator);
}

public void delete(String url, HttpResponseValidator validator) {
delete(url, new HttpResponseValidatorIgnoringReturn(validator));
delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));
}

public void delete(String url, HttpQueryParams queryParams, HttpHeader header) {
delete(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);
}

public void delete(String url, HttpHeader header) {
delete(url, header, EMPTY_RESPONSE_VALIDATOR);
delete(url, HttpQueryParams.EMPTY, header, EMPTY_RESPONSE_VALIDATOR);
}

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

public void delete(String url) {
delete(url, EMPTY_RESPONSE_VALIDATOR);
delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);
}

public HttpHeader header(String... properties) {
@@ -142,4 +142,61 @@ public void putWithReturnOverloads() {
});
actual(text).should(equal(PATH_EXPECTED_RETURN));
}

@Test
public void deleteWithoutReturnOverloads() {
http.delete("/full-echo", query, requestHeader, (header, body) -> {
headerValidation.accept(body);
urlValidation.accept(body);
});

http.delete("/full-echo", requestHeader, (header, body) -> {
headerValidation.accept(body);
pathValidation.accept(body);
});

http.delete("/full-echo", query, (header, body) -> {
urlValidation.accept(body);
});

http.delete("/full-echo", (header, body) -> {
pathValidation.accept(body);
});
}

@Test
public void deleteWithReturnOverloads() {
Integer number;
Integer expected = 200;

number = http.delete("/full-echo", query, requestHeader, (header, body) -> {
headerValidation.accept(body);
urlValidation.accept(body);

return header.statusCode();
});
actual(number).should(equal(expected));

number = http.delete("/full-echo", requestHeader, (header, body) -> {
headerValidation.accept(body);
pathValidation.accept(body);

return header.statusCode();
});
actual(number).should(equal(expected));

number = http.delete("/full-echo", query, (header, body) -> {
urlValidation.accept(body);

return header.statusCode();
});
actual(number).should(equal(expected));

number = http.delete("/full-echo", (header, body) -> {
pathValidation.accept(body);

return header.statusCode();
});
actual(number).should(equal(expected));
}
}
@@ -16,6 +16,7 @@

package com.twosigma.webtau.http;

import com.twosigma.webtau.WebTauCore;
import com.twosigma.webtau.http.datanode.DataNode;
import com.twosigma.webtau.http.json.JsonRequestBody;
import com.twosigma.webtau.http.request.HttpQueryParams;
@@ -39,6 +40,7 @@
public static final String PATH_EXPECTED_RETURN = "/full-echo";

public static final HttpQueryParams query = http.query("a", "1", "b", "text");
public static final Map<String, ?> queryAsMap = WebTauCore.aMapOf("a", "1", "b", "text");
public static final HttpHeader requestHeader = http.header(HEADER_KEY, HEADER_EXPECTED_RETURN);

public static final Map<String, Object> requestBodyMap = Collections.singletonMap(BODY_KEY, BODY_EXPECTED_RETURN);
@@ -56,6 +56,8 @@ public HttpTestDataServer() {
testServer.registerPut("/echo", new TestServerResponseEcho(200));
testServer.registerPut("/full-echo", new TestServerRequestFullEcho(200));
testServer.registerPut("/full-echo?a=1&b=text", new TestServerRequestFullEcho(200));
testServer.registerDelete("/full-echo", new TestServerRequestFullEcho(200));
testServer.registerDelete("/full-echo?a=1&b=text", new TestServerRequestFullEcho(200));
testServer.registerGet("/echo-header", new TestServerRequestHeaderEcho(200));
testServer.registerGet("/echo-header?qp1=v1", new TestServerRequestHeaderEcho(200));
testServer.registerPost("/echo-header", new TestServerRequestHeaderEcho(201));

0 comments on commit b1f86fc

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