Search in sources :

Example 11 with FilterableResponseSpecification

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

use of io.restassured.specification.FilterableResponseSpecification 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/"));
}
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 13 with FilterableResponseSpecification

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

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

the class URLITest method fullyQualifiedUrlAddsPort8080IfExplicitlyDefinedStatically.

@Test
public void fullyQualifiedUrlAddsPort8080IfExplicitlyDefinedStatically() throws Exception {
    // Given
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssured.port = 8080;
    RestAssured.baseURI = "http://tototiti.alarmesomfy.net/";
    RestAssured.basePath = "/api";
    // 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://tototiti.alarmesomfy.net:8080/api/"));
}
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 15 with FilterableResponseSpecification

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

the class URLITest method given_a_base_uri_with_fully_qualified_url_defaults_to_using_port_80_if_port_is_not_explicitly_defined.

@Test
public void given_a_base_uri_with_fully_qualified_url_defaults_to_using_port_80_if_port_is_not_explicitly_defined() {
    // 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"));
}
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

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