Search in sources :

Example 26 with RequestSpecification

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

the class AcceptHeaderITest method accept_method_from_spec_is_set_to_request_when_specified_as_content_type.

@Test
public void accept_method_from_spec_is_set_to_request_when_specified_as_content_type() {
    RequestSpecification spec = new RequestSpecBuilder().setAccept(ContentType.JSON).build();
    RestAssured.given().spec(spec).body("{ \"message\" : \"hello world\"}").when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world"));
}
Also used : FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 27 with RequestSpecification

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

the class AcceptHeaderITest method accept_headers_are_merged_from_request_spec_and_request_when_configured_to.

@Test
public void accept_headers_are_merged_from_request_spec_and_request_when_configured_to() {
    RequestSpecification spec = new RequestSpecBuilder().setAccept("text/jux").build();
    final MutableObject<List<String>> headers = new MutableObject<List<String>>();
    RestAssured.given().config(RestAssuredConfig.config().headerConfig(HeaderConfig.headerConfig().mergeHeadersWithName("Accept"))).accept(ContentType.JSON).spec(spec).body("{ \"message\" : \"hello world\"}").filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            headers.setValue(requestSpec.getHeaders().getValues("Accept"));
            return ctx.next(requestSpec, responseSpec);
        }
    }).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world"));
    assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript, text/json", "text/jux"));
}
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) List(java.util.List) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 28 with RequestSpecification

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

the class SpecificationsDemoITest method demoRequestSpecification.

@Test
public void demoRequestSpecification() throws Exception {
    final RequestSpecification books = new RequestSpecBuilder().addQueryParam("category", "books").addCookie("user", "admin").build();
    given().specification(books).expect().body(equalTo("Catch 22")).when().get("/demoRequestSpecification");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 29 with RequestSpecification

use of io.restassured.specification.RequestSpecification in project spring-cloud-netflix by spring-cloud.

the class AbstractDocumentationTests method document.

protected RequestSpecification document(Object body) {
    RestDocumentationFilter filter = filter("{method-name}");
    RequestSpecification assured = RestAssured.given(spec(body, filter));
    return assured.filter(filter);
}
Also used : RestDocumentationFilter(org.springframework.restdocs.restassured3.RestDocumentationFilter) RequestSpecification(io.restassured.specification.RequestSpecification)

Example 30 with RequestSpecification

use of io.restassured.specification.RequestSpecification in project spring-cloud-netflix by spring-cloud.

the class AbstractDocumentationTests method spec.

private RequestSpecification spec(Object body, Filter... filters) {
    RequestSpecBuilder builder = new RequestSpecBuilder().addFilter(documentationConfiguration(this.restDocumentation).snippets().withAdditionalDefaults(new WireMockSnippet()));
    for (Filter filter : filters) {
        builder = builder.addFilter(filter);
    }
    RequestSpecification spec = builder.setPort(this.port).build();
    if (body != null) {
        spec.contentType("application/json").body(body, new EurekaObjectMapper());
    }
    return spec;
}
Also used : RestDocumentationFilter(org.springframework.restdocs.restassured3.RestDocumentationFilter) Filter(io.restassured.filter.Filter) RequestSpecification(io.restassured.specification.RequestSpecification) WireMockSnippet(org.springframework.cloud.contract.wiremock.restdocs.WireMockSnippet) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder)

Aggregations

RequestSpecification (io.restassured.specification.RequestSpecification)55 Test (org.junit.Test)47 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)40 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)7 SecurityTest (com.capgemini.ntc.security.SecurityTest)6 ResponseSpecification (io.restassured.specification.ResponseSpecification)5 Filter (io.restassured.filter.Filter)4 Parameters (junitparams.Parameters)4 FilterContext (io.restassured.filter.FilterContext)3 Header (io.restassured.http.Header)3 Response (io.restassured.response.Response)3 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 RestDocumentationFilter (org.springframework.restdocs.restassured3.RestDocumentationFilter)3 Headers (io.restassured.http.Headers)2 List (java.util.List)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1