Skip to content

Commit

Permalink
Add java setUrl() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
htmldoug committed Aug 13, 2018
1 parent 10b0afd commit 66fdadb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class StandaloneAhcWSRequest implements StandaloneWSRequest {

private BodyWritable<?> bodyWritable;

private final String url;
private String url;
private String method = "GET";
private final Map<String, List<String>> headers = new HashMap<>();
private final Map<String, List<String>> queryParameters = new LinkedHashMap<>();
Expand Down Expand Up @@ -225,6 +225,12 @@ public Optional<String> getContentType() {
return getHeader(CONTENT_TYPE);
}

@Override
public StandaloneWSRequest setUrl(String url) {
this.url = url;
return this;
}

@Override
public StandaloneAhcWSRequest setMethod(String method) {
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class AhcWSRequestSpec extends Specification with Mockito with DefaultBodyReadab
actual must beEqualTo("foo.com")
}

"set the url" in {
val client = mock[StandaloneAhcWSClient]
val req = new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
req.getUrl must be_===("http://playframework.com/")

val setReq = req.setUrl("http://example.com")
setReq.getUrl must be_===("http://example.com")
setReq must be_===(req)
}

"For POST requests" in {

"get method" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public interface StandaloneWSRequest {
// Setters
//-------------------------------------------------------------------------

/**
* Sets the URL of the request.
*
* @param url the URL of the request
* @return the modified WSRequest.
*/
StandaloneWSRequest setUrl(String url);

/**
* Sets the HTTP method this request should use, where the no args execute() method is invoked.
*
Expand Down

0 comments on commit 66fdadb

Please sign in to comment.