Search in sources :

Example 6 with RequestSpecBuilder

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

the class SpecificationBuilderITest method mergesStaticallyDefinedRequestSpecificationsCorrectly.

@Test
public void mergesStaticallyDefinedRequestSpecificationsCorrectly() throws Exception {
    RestAssured.requestSpecification = new RequestSpecBuilder().addCookie("Cookie1", "Value1").build();
    RequestSpecification reqSpec1 = new RequestSpecBuilder().addCookie("Cookie2", "Value2").build();
    RequestSpecification reqSpec2 = new RequestSpecBuilder().addCookie("Cookie3", "Value3").build();
    try {
        Cookies cookies = given().spec(reqSpec1).when().get("/reflect").then().extract().detailedCookies();
        assertThat(cookies.size(), is(2));
        assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
        assertThat(cookies.hasCookieWithName("Cookie2"), is(true));
        cookies = given().spec(reqSpec2).when().get("/reflect").then().extract().detailedCookies();
        assertThat(cookies.size(), is(2));
        assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
        assertThat(cookies.hasCookieWithName("Cookie3"), is(true));
    } finally {
        RestAssured.reset();
    }
}
Also used : Cookies(io.restassured.http.Cookies) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 7 with RequestSpecBuilder

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

the class SpecificationBuilderITest method supportsMergingMultiValueQueryParametersWhenUsingRequestSpecBuilder.

@Test
public void supportsMergingMultiValueQueryParametersWhenUsingRequestSpecBuilder() throws Exception {
    final RequestSpecification spec = new RequestSpecBuilder().addQueryParam("list", "1", "2", "3").build();
    given().spec(spec).expect().body("list", equalTo("1,2,3")).when().get("/multiValueParam");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 8 with RequestSpecBuilder

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

the class SpecificationBuilderITest method supportsMergingHeadersWhenUsingRequestSpecBuilder.

@Test
public void supportsMergingHeadersWhenUsingRequestSpecBuilder() throws Exception {
    final RequestSpecification spec = new RequestSpecBuilder().addHeader("header1", "value1").build();
    given().spec(spec).header("header2", "value2").expect().body(containsString("header1")).body(containsString("header2")).when().get("/header");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Example 9 with RequestSpecBuilder

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

the class URLEncodingITest method urlEncodingDisabledUsingRequestSpecBuilder.

@Test
@Ignore("2.0.alpha1 no longer working")
public void urlEncodingDisabledUsingRequestSpecBuilder() {
    final RequestSpecification specification = new RequestSpecBuilder().setUrlEncodingEnabled(false).build();
    final String body = given().specification(specification).get("https://jira.atlassian.com:443/rest/api/2.0.alpha1/search?jql=project%20=%20BAM%20AND%20issuetype%20=%20Bug").asString();
    assertThat(body, containsString("issues"));
}
Also used : FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with RequestSpecBuilder

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

the class MultiPartUploadITest method bytesAndFormParamUploadingWorkUsingRequestBuilder.

@Test
public void bytesAndFormParamUploadingWorkUsingRequestBuilder() throws Exception {
    final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd"));
    final RequestSpecification spec = new RequestSpecBuilder().addMultiPart("file", "myFile", bytes).addFormParam("text", "Some text").build();
    // When
    given().spec(spec).expect().body(is(new String(bytes) + "Some text")).when().post("/multipart/fileAndText");
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Test(org.junit.Test)

Aggregations

RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)43 RequestSpecification (io.restassured.specification.RequestSpecification)40 Test (org.junit.Test)39 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)7 Filter (io.restassured.filter.Filter)4 Header (io.restassured.http.Header)4 PrintStream (java.io.PrintStream)4 StringWriter (java.io.StringWriter)4 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)4 FilterContext (io.restassured.filter.FilterContext)3 Response (io.restassured.response.Response)3 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)3 Headers (io.restassured.http.Headers)2 List (java.util.List)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 SecurityTest (com.capgemini.ntc.security.SecurityTest)1 ResponseBuilder (io.restassured.builder.ResponseBuilder)1 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)1 LogConfig (io.restassured.config.LogConfig)1 Cookies (io.restassured.http.Cookies)1