Search in sources :

Example 26 with FilterableRequestSpecification

use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.

the class CookieFilterTest method doesntAddCookiesToNonMatchingUrlRequest.

@Test
public void doesntAddCookiesToNonMatchingUrlRequest() {
    FilterableRequestSpecification reqNonMatchingDomain = (FilterableRequestSpecification) given().with().baseUri("https://someother.com/somepath");
    cookieFilter.filter(reqOriginDomain, response, testFilterContext);
    cookieFilter.filter(reqNonMatchingDomain, response, testFilterContext);
    assertThat(reqNonMatchingDomain.getCookies().size(), Matchers.is(0));
}
Also used : FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) Test(org.junit.Test)

Example 27 with FilterableRequestSpecification

use of io.restassured.specification.FilterableRequestSpecification 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"));
}
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 28 with FilterableRequestSpecification

use of io.restassured.specification.FilterableRequestSpecification 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"));
}
Also used : Response(io.restassured.response.Response) 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 29 with FilterableRequestSpecification

use of io.restassured.specification.FilterableRequestSpecification 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"));
}
Also used : Response(io.restassured.response.Response) 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 30 with FilterableRequestSpecification

use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.

the class URLITest method fullyQualifiedUrlIncludingPortWorks.

@Test
public void fullyQualifiedUrlIncludingPortWorks() 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://tototiti.alarmesomfy.net:8080/");
    // Then
    assertThat(loggedRequestPathIn(writer), equalTo("http://tototiti.alarmesomfy.net:8080/"));
}
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)

Aggregations

FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)50 Test (org.junit.Test)50 FilterContext (io.restassured.filter.FilterContext)49 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)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