use of io.restassured.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class URLITest method takesStaticSpecificationPortIntoAccountWhenBaseUriIsSpecified.
@Test
public void takesStaticSpecificationPortIntoAccountWhenBaseUriIsSpecified() throws Exception {
// Given
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.port = 9093;
RestAssured.baseURI = "http://something.com";
// 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://something.com:9093/"));
}
use of io.restassured.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class URLITest method fullyQualifiedUrlIsHandledCorrectlyInLogWithNoValueParam.
@Test
public void fullyQualifiedUrlIsHandledCorrectlyInLogWithNoValueParam() 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("http://ya.ru/bla/?param=value=&ikk");
// Then
assertThat(loggedRequestPathIn(writer), equalTo("http://ya.ru/bla/?param=value%3D&ikk"));
}
use of io.restassured.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class URLITest method takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedEndingWithSlash.
@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedEndingWithSlash() 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/"));
}
use of io.restassured.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class OAuthITest method oauth2_works_with_non_preemptive_header_signing.
@Test
public void oauth2_works_with_non_preemptive_header_signing() {
final String accessToken = "accessToken";
given().auth().oauth2(accessToken).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
AuthenticationScheme scheme = requestSpec.getAuthenticationScheme();
assertThat(scheme, instanceOf(PreemptiveOAuth2HeaderScheme.class));
assertThat(((PreemptiveOAuth2HeaderScheme) scheme).getAccessToken(), equalTo(accessToken));
return new ResponseBuilder().setBody("ok").setStatusCode(200).build();
}
}).when().get("/somewhere").then().statusCode(200);
}
use of io.restassured.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class FilterITest method httpClientIsAccessibleFromTheRequestSpecification.
@Test
public void httpClientIsAccessibleFromTheRequestSpecification() {
// Given
final MutableObject<HttpClient> client = new MutableObject<HttpClient>();
// When
given().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client.setValue(requestSpec.getHttpClient());
return new ResponseBuilder().setStatusCode(200).setContentType("application/json").setBody("{ \"message\" : \"hello\"}").build();
}
}).expect().body("message", equalTo("hello")).when().get("/something");
// Then
assertThat(client.getValue(), instanceOf(DefaultHttpClient.class));
}
Aggregations