Search in sources :

Example 86 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingIfValidationFailsTest method given_writer_and_captor_is_initialized.

@Before
public void given_writer_and_captor_is_initialized() {
    writer = new StringWriter();
    captor = new PrintStream(new WriterOutputStream(writer), true);
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Before(org.junit.Before)

Example 87 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class ResponseLoggingTest method given_config_is_stored_in_writer.

@Before
public void given_config_is_stored_in_writer() {
    writer = new StringWriter();
    PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true));
}
Also used : PrintStream(java.io.PrintStream) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Before(org.junit.Before)

Example 88 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream 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 89 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream 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 90 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream 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)

Aggregations

WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)159 StringWriter (java.io.StringWriter)150 PrintStream (java.io.PrintStream)141 Test (org.junit.Test)133 LogConfig (io.restassured.config.LogConfig)46 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)44 ResponseBuilder (io.restassured.builder.ResponseBuilder)36 Filter (io.restassured.filter.Filter)35 FilterContext (io.restassured.filter.FilterContext)35 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)35 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)35 OutputStream (java.io.OutputStream)8 IOException (java.io.IOException)7 Col (org.apache.karaf.shell.table.Col)6 ShellTable (org.apache.karaf.shell.table.ShellTable)6 InputStream (java.io.InputStream)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3