Search in sources :

Example 46 with RequestSpecification

use of io.restassured.specification.RequestSpecification 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)

Example 47 with RequestSpecification

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

the class AcceptHeaderITest method accept_headers_are_overwritten_from_request_spec_by_default.

@Test
public void accept_headers_are_overwritten_from_request_spec_by_default() {
    RequestSpecification spec = new RequestSpecBuilder().setAccept(ContentType.JSON).build();
    final MutableObject<List<String>> headers = new MutableObject<List<String>>();
    RestAssured.given().accept("text/jux").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"));
}
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 48 with RequestSpecification

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

the class AuthenticationITest method formAuthenticationUsingSpringAuthConfDefinedInRequestSpec.

@Test
public void formAuthenticationUsingSpringAuthConfDefinedInRequestSpec() throws Exception {
    final RequestSpecification specification = new RequestSpecBuilder().setAuth(form("John", "Doe", FormAuthConfig.springSecurity())).build();
    given().spec(specification).expect().statusCode(200).body(equalTo("OK")).when().get("/formAuth");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 49 with RequestSpecification

use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.

the class DriverManager method getDriver.

public static RequestSpecification getDriver() {
    RequestSpecification driver = drivers.get();
    if (driver == null) {
        driver = createDriver();
        drivers.set(driver);
        BFLogger.logDebug("driver: " + driver.toString());
    }
    return driver;
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification)

Example 50 with RequestSpecification

use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.

the class DirectoryBrowsingTest method testHeader.

@Test
public void testHeader() {
    RequestSpecification rs = getSessionManager().initBuilder(session).setBaseUri(origin.getValue()).setBasePath(path.getValue()).build();
    given(rs).when().get().then().statusCode(statusCode);
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) Test(org.junit.Test) SecurityTest(com.capgemini.ntc.security.SecurityTest)

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