Search in sources :

Example 76 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class ResponseITest method pathThrowsExceptionWhenTryingToUseJsonPathAfterHavingUsedXmlPath.

@Test
public void pathThrowsExceptionWhenTryingToUseJsonPathAfterHavingUsedXmlPath() throws Exception {
    exception.expect(JsonPathException.class);
    exception.expectMessage("Failed to parse the JSON document");
    Response response = get("/videos");
    response.path("videos.music[0].title.toString().trim()");
    response.jsonPath().get("videos");
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 77 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class ResponseITest method canParsePathAfterPrettyPeek.

@Test
public void canParsePathAfterPrettyPeek() throws Exception {
    Response response = get("/videos").prettyPeek();
    String title = response.path("videos.music[0].title.toString().trim()");
    String artist = response.path("videos.music[0].artist.toString().trim()");
    assertThat(title, equalTo("Video Title 1"));
    assertThat(artist, equalTo("Artist 1"));
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 78 with Response

use of io.restassured.response.Response 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 79 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class CookieITest method getDetailedCookieWorks.

@Test
public void getDetailedCookieWorks() throws Exception {
    final Response response = get("/html_with_cookie");
    final Cookie detailedCookieJsessionId = response.getDetailedCookie("JSESSIONID");
    assertThat(detailedCookieJsessionId, notNullValue());
    assertThat(detailedCookieJsessionId.getPath(), equalTo("/"));
    assertThat(detailedCookieJsessionId.getValue(), equalTo("B3134D534F40968A3805968207273EF5"));
}
Also used : Response(io.restassured.response.Response) Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Test(org.junit.Test)

Example 80 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class CookieITest method multipleCookiesWithSameKey.

@Test
public void multipleCookiesWithSameKey() throws Exception {
    final Response response = get("/setCommonIdCookies");
    Map<String, String> map = new HashMap<String, String>();
    map = response.cookies();
    assertThat(map.get("key1"), equalTo("value3"));
}
Also used : Response(io.restassured.response.Response) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Response (io.restassured.response.Response)270 Test (org.junit.Test)209 Matchers.containsString (org.hamcrest.Matchers.containsString)43 ValidatableResponse (io.restassured.response.ValidatableResponse)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)29 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)25 HttpResponse (org.apache.http.HttpResponse)25 Matchers.emptyString (org.hamcrest.Matchers.emptyString)24 FilterContext (io.restassured.filter.FilterContext)17 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)17 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)17 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)17 Filter (io.restassured.filter.Filter)16 VerifyTest (org.apache.knox.test.category.VerifyTest)15 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 Book (org.baeldung.persistence.model.Book)13 JSONObject (org.json.simple.JSONObject)13 ResponseBuilder (io.restassured.builder.ResponseBuilder)12 IOException (java.io.IOException)11