use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLEncodingITest method doesntUrlEncodePathFragmentsWhenUrlEncodingIsDisabled.
@Test
public void doesntUrlEncodePathFragmentsWhenUrlEncodingIsDisabled() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
String agentUrl = URLEncoder.encode("https://localhost:9888", "UTF-8");
RestAssured.urlEncodingEnabled = false;
RestAssured.basePath = "/tmc/api";
// When
try {
given().contentType(JSON).filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
/*
* Note that Scalatra cannot handle request with path parameters containing "/" (like path/param) even though it's URL encoded.
* Scalatra decodes the path prior to finding the method to invoke and thus we'll get an error back (since no resource mapping to /path/param/manyParams exist).
*/
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("/agents/probeUrl/" + agentUrl);
} finally {
RestAssured.reset();
}
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/tmc/api/agents/probeUrl/https%3A%2F%2Flocalhost%3A9888"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLEncodingITest method urlEncodesPathFragmentsRegardlessIfTheyHaveBeenManuallyEncodedWhenUrlEncodingIsEnabled.
@Test
public void urlEncodesPathFragmentsRegardlessIfTheyHaveBeenManuallyEncodedWhenUrlEncodingIsEnabled() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
String agentUrl = URLEncoder.encode("https://localhost:9888", "UTF-8");
RestAssured.urlEncodingEnabled = true;
// When
try {
given().contentType(JSON).filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
/*
* Note that Scalatra cannot handle request with path parameters containing "/" (like path/param) even though it's URL encoded.
* Scalatra decodes the path prior to finding the method to invoke and thus we'll get an error back (since no resource mapping to /path/param/manyParams exist).
*/
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("/agents/probeUrl/" + agentUrl);
} finally {
RestAssured.reset();
}
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/agents/probeUrl/https%253A%252F%252Flocalhost%253A9888"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method trailingSlashesAreRetainedWhenPassedAsArgumentToGetMethod.
@Test
public void trailingSlashesAreRetainedWhenPassedAsArgumentToGetMethod() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("/v1/");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/v1/"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method doesntAddTrailingSlashesWhenNoTrailingSlashIsUsed.
@Test
public void doesntAddTrailingSlashesWhenNoTrailingSlashIsUsed() throws Exception {
// Given
RestAssured.basePath = "/v1";
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
try {
given().filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("");
} finally {
RestAssured.reset();
}
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/v1"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedWithoutEndingWithSlash.
@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedWithoutEndingWithSlash() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().port(8084).contentType(JSON).filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).expect().statusCode(200).body(equalTo("changed")).when().get("http://localhost");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8084"));
}
Aggregations