Search in sources :

Example 11 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class URLITest method takesSpecificationPortIntoAccountWhenLocalhostHostAndPort8080IsSpecifiedStatically.

@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostAndPort8080IsSpecifiedStatically() throws Exception {
    // Given
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssured.port = 8080;
    RestAssured.baseURI = "http://localhost/";
    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://localhost: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 12 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class URLITest method takesStaticSpecificationPortIntoAccountWhenNoHostIsSpecified.

@Test
public void takesStaticSpecificationPortIntoAccountWhenNoHostIsSpecified() throws Exception {
    // Given
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssured.port = 9093;
    // 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://localhost: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 13 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class URLITest method addsSingleTrailingSlashToPathWhenSlashIsUsedAsPathInGetMethod.

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

use of io.restassured.filter.log.RequestLoggingFilter in project rest-assured by rest-assured.

the class URLITest method takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedStatically.

@Test
public void takesSpecificationPortIntoAccountWhenLocalhostHostIsSpecifiedStatically() throws Exception {
    // Given
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssured.port = 8084;
    RestAssured.baseURI = "http://localhost";
    // 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://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 15 with RequestLoggingFilter

use of io.restassured.filter.log.RequestLoggingFilter 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)

Aggregations

RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)47 PrintStream (java.io.PrintStream)45 StringWriter (java.io.StringWriter)43 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)43 Test (org.junit.Test)43 ResponseBuilder (io.restassured.builder.ResponseBuilder)31 Filter (io.restassured.filter.Filter)31 FilterContext (io.restassured.filter.FilterContext)31 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)31 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)31 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3 Response (io.restassured.response.Response)3 LogConfig (io.restassured.config.LogConfig)2 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)2 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 AsyncConfig (io.restassured.module.mockmvc.config.AsyncConfig)1 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)1