use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class URLITest method takesSpecificationPortIntoAccountWhenNoHostIsSpecified.
@Test
public void takesSpecificationPortIntoAccountWhenNoHostIsSpecified() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().port(8083).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:8083/"));
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class URLITest method fullyQualifiedLocalhostUrlEndingWithSlashDoesntAddsPort8080.
@Test
public void fullyQualifiedLocalhostUrlEndingWithSlashDoesntAddsPort8080() 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("http://localhost");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080"));
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class URLITest method trailingSlashesAreRetainedWhenConfiguredStatically.
@Test
public void trailingSlashesAreRetainedWhenConfiguredStatically() 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 io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class URLITest method doesntAddPort8080ToFullyQualifiedUrlDefinedInHttpVerbMethod.
@Test
public void doesntAddPort8080ToFullyQualifiedUrlDefinedInHttpVerbMethod() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
// When
given().port(8080).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://tototiti.alarmesomfy.net/");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://tototiti.alarmesomfy.net:8080/"));
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class LoggingITest method logsFullyQualifiedUrlsAreLoggedCorrectly.
@Test
public void logsFullyQualifiedUrlsAreLoggedCorrectly() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("http://www.beijingchina.net.cn/transportation/train/train-to-shanghai.html");
assertThat(writer.toString(), startsWith("Request method:\tGET\nRequest URI:\thttp://www.beijingchina.net.cn/transportation/train/train-to-shanghai.html"));
}
Aggregations