use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method addsSingleTrailingSlashToPathWhenSlashIsUsedAsPathInGetMethod.
@Test
public void addsSingleTrailingSlashToPathWhenSlashIsUsedAsPathInGetMethod() 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 takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedStatically.
@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedStatically() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.port = 8084;
RestAssured.baseURI = "http://localhost";
// When
try {
given().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("/");
} finally {
RestAssured.reset();
}
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8084/"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method get_using_fully_qualified_url_uses_port_80.
@Test
public void get_using_fully_qualified_url_uses_port_80() {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().baseUri("http://httpbin.org/get").filter(new RequestLoggingFilter(captor)).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).when().get().then().statusCode(200).body(equalTo("changed"));
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://httpbin.org/get"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method whenNoAuthorityOrPortIsSpecifiedThenLocalhostOnPort8080IsUsed.
@Test
public void whenNoAuthorityOrPortIsSpecifiedThenLocalhostOnPort8080IsUsed() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().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("/");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/"));
}
use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.
the class URLITest method urlWithUnderscoreInHostNameWorks.
@Test
public void urlWithUnderscoreInHostNameWorks() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().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(// Has _ in host name
"http://toto_titi.alarmesomfy.net");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://toto_titi.alarmesomfy.net"));
}
Aggregations