Skip to content

Instantly share code, notes, and snippets.

@anthonydahanne
Last active December 28, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonydahanne/7531730 to your computer and use it in GitHub Desktop.
Save anthonydahanne/7531730 to your computer and use it in GitHub Desktop.
RestAssured Issue #181, using 1.8.2-SNAPSHOT
given()
.log().all()
.contentType(ContentType.JSON)
.expect()
.log().all()
.statusCode(200)
.when()
.get("/agents/probeUrl/" + agentUrl);
1) Not encoding
String agentUrl = "https://localhost:9888";
RestAssured.urlEncodingEnabled = false;
-->java.net.MalformedURLException: no protocol: /agents/probeUrl/https://localhost:9888
2) urlEncodingEnabled = true
String agentUrl = "https://localhost:9888";
RestAssured.urlEncodingEnabled = true;
-->java.net.MalformedURLException: no protocol: /agents/probeUrl/https://localhost:9888
3) urlEncodingFalse = false, encoding the url with URLEncoder
String agentUrl = "https://localhost:9888";
agentUrl = URLEncoder.encode(agentUrl, "UTF-8");
RestAssured.urlEncodingEnabled = false;
-->Request path: http://localhost:29889/tmc/api/agents/probeUrl/https%253A%252F%252Flocalhost%253A9888
4) urlEncodingFalse = true, encoding the url with URLEncoder
String agentUrl = "https://localhost:9888";
agentUrl = URLEncoder.encode(agentUrl, "UTF-8");
RestAssured.urlEncodingEnabled = true;
-->Request path: http://localhost:29889/tmc/api/agents/probeUrl/https%253A%252F%252Flocalhost%253A9888
RestAssured NEVER sent expected url /agents/probeUrl/https%3A%2F%2Flocalhost%3A9888 on the wire
Solutions
---------
String agentUrl = "https://localhost:9888";
RestAssured.urlEncodingEnabled = true;
given().pathParam("x", agentUrl)
.log().all()
.contentType(ContentType.JSON)
.expect()
.log().all()
.statusCode(200)
.when()
.get("/agents/probeUrl/{x}");
correctly produced :
Request method: GET
Request path: http://localhost:29889/tmc/api/agents/probeUrl/https%3A%2F%2Flocalhost%3A29888
Request params: <none>
Query params: <none>
Form params: <none>
Path params: x=https://localhost:29888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment