use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class LoggingIfValidationFailsTest method given_writer_and_captor_is_initialized.
@Before
public void given_writer_and_captor_is_initialized() {
writer = new StringWriter();
captor = new PrintStream(new WriterOutputStream(writer), true);
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class ResponseLoggingTest method given_config_is_stored_in_writer.
@Before
public void given_config_is_stored_in_writer() {
writer = new StringWriter();
PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLEncodingITest method urlsWithSchemeIsOkToSendInUrlWithoutBeingUrlEncoded.
@Test
public void urlsWithSchemeIsOkToSendInUrlWithoutBeingUrlEncoded() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
String agentUrl = "https://localhost:9888";
RestAssured.urlEncodingEnabled = false;
// 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();
}
}).log().all().expect().statusCode(200).body(equalTo("changed")).when().get("/agents/probeUrl/" + agentUrl);
} finally {
RestAssured.reset();
}
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/agents/probeUrl/https://localhost:9888"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLEncodingITest method urlEncodesNamedPathParameters.
@Test
public void urlEncodesNamedPathParameters() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
String agentUrl = "https://localhost:9888";
RestAssured.urlEncodingEnabled = true;
// When
try {
given().contentType(JSON).pathParam("x", agentUrl).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).when().get("/agents/probeUrl/{x}");
} finally {
RestAssured.reset();
}
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/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 urlEncodesUnnamedPathParameters.
@Test
public void urlEncodesUnnamedPathParameters() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
String agentUrl = "https://localhost:9888";
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).when().get("/agents/probeUrl/{x}", agentUrl);
} finally {
RestAssured.reset();
}
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/agents/probeUrl/https%3A%2F%2Flocalhost%3A9888"));
}
Aggregations