Search in sources :

Example 46 with ResponseBuilder

use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.

the class PathParamITest method urlEncodesUnnamedPathParametersThatContainsCurlyBracesAndEquals.

@Test
public void urlEncodesUnnamedPathParametersThatContainsCurlyBracesAndEquals() throws Exception {
    // When
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).log().all().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
        }
    }).get("/feed?canonicalName={trackingName}&platform=ed4", "{trackingName='trackingname1'}");
    // Then
    assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/feed?canonicalName=%7BtrackingName%3D%27trackingname1%27%7D&platform=ed4"));
}
Also used : PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) LogConfig(io.restassured.config.LogConfig) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 47 with ResponseBuilder

use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.

the class RequestSpecMergingITest method mergesHeadersCorrectlyWhenUsingGivenRequestSpec.

@Test
public void mergesHeadersCorrectlyWhenUsingGivenRequestSpec() {
    given(jsonRequest).filter((requestSpec, responseSpec, ctx) -> {
        Headers headers = requestSpec.getHeaders();
        assertThat(requestSpec.getContentType(), equalTo("application/json; charset=" + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
        assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
        assertThat(headers.getValue("accept"), equalTo("application/json+json"));
        assertThat(headers.getValue("content-type"), equalTo("application/json; charset=" + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
        assertThat(headers.size(), is(3));
        return new ResponseBuilder().setStatusCode(200).build();
    }).when().get();
}
Also used : Headers(io.restassured.http.Headers) ResponseBuilder(io.restassured.builder.ResponseBuilder) Test(org.junit.Test)

Example 48 with ResponseBuilder

use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.

the class RequestSpecMergingITest method mergesHeadersCorrectlyWhenUsingGivenSpecRequestSpec.

@Test
public void mergesHeadersCorrectlyWhenUsingGivenSpecRequestSpec() {
    given().spec(jsonRequest).filter((requestSpec, responseSpec, ctx) -> {
        Headers headers = requestSpec.getHeaders();
        assertThat(requestSpec.getContentType(), equalTo("application/json; charset=" + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
        assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
        assertThat(headers.getValue("accept"), equalTo("application/json+json"));
        assertThat(headers.getValue("content-type"), equalTo("application/json; charset=" + config().getEncoderConfig().defaultCharsetForContentType(JSON)));
        assertThat(headers.size(), is(3));
        return new ResponseBuilder().setStatusCode(200).build();
    }).when().get();
}
Also used : Headers(io.restassured.http.Headers) ResponseBuilder(io.restassured.builder.ResponseBuilder) Test(org.junit.Test)

Example 49 with ResponseBuilder

use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.

the class RequestSpecificationITest method filterable_request_specification_returns_correct_port.

@Test
public void filterable_request_specification_returns_correct_port() {
    try {
        RestAssured.baseURI = "http://localhost:8089";
        RequestSpecification spec = new RequestSpecBuilder().addHeader("authorization", "abracadabra").build();
        given().spec(spec).filter(new Filter() {

            public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                assertThat(requestSpec.getPort(), is(8089));
                return new ResponseBuilder().setStatusCode(200).build();
            }
        }).when().get("/test");
    } finally {
        RestAssured.reset();
    }
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

ResponseBuilder (io.restassured.builder.ResponseBuilder)49 Test (org.junit.Test)47 Filter (io.restassured.filter.Filter)40 FilterContext (io.restassured.filter.FilterContext)40 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)40 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)40 PrintStream (java.io.PrintStream)36 StringWriter (java.io.StringWriter)36 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)36 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)32 Response (io.restassured.response.Response)11 LogConfig (io.restassured.config.LogConfig)4 Headers (io.restassured.http.Headers)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)3 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 HttpClient (org.apache.http.client.HttpClient)2 AuthenticationScheme (io.restassured.authentication.AuthenticationScheme)1 PreemptiveOAuth2HeaderScheme (io.restassured.authentication.PreemptiveOAuth2HeaderScheme)1 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)1 ErrorLoggingFilter (io.restassured.filter.log.ErrorLoggingFilter)1