Search in sources :

Example 16 with FilterableResponseSpecification

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/"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 17 with FilterableResponseSpecification

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"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 18 with FilterableResponseSpecification

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/"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 19 with FilterableResponseSpecification

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);
}
Also used : Response(io.restassured.response.Response) AuthenticationScheme(io.restassured.authentication.AuthenticationScheme) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) PreemptiveOAuth2HeaderScheme(io.restassured.authentication.PreemptiveOAuth2HeaderScheme) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 20 with FilterableResponseSpecification

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));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

FilterContext (io.restassured.filter.FilterContext)49 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)49 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)49 Test (org.junit.Test)49 Filter (io.restassured.filter.Filter)48 ResponseBuilder (io.restassured.builder.ResponseBuilder)40 PrintStream (java.io.PrintStream)35 StringWriter (java.io.StringWriter)35 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)35 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)32 Response (io.restassured.response.Response)17 MutableObject (org.apache.commons.lang3.mutable.MutableObject)8 HttpClient (org.apache.http.client.HttpClient)6 SystemDefaultHttpClient (org.apache.http.impl.client.SystemDefaultHttpClient)5 LogConfig (io.restassured.config.LogConfig)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)3 ErrorLoggingFilter (io.restassured.filter.log.ErrorLoggingFilter)3 FormAuthFilter (io.restassured.internal.filter.FormAuthFilter)3 SpookyGreetJsonResponseFilter (io.restassured.itest.java.support.SpookyGreetJsonResponseFilter)3