io.restassured.response.ResponseBodyExtractionOptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-assured Show documentation
Show all versions of rest-assured Show documentation
Java DSL for easy testing of REST services
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.restassured.response;
import io.restassured.mapper.ObjectMapper;
import io.restassured.mapper.ObjectMapperType;
import io.restassured.path.json.JsonPath;
import io.restassured.path.json.config.JsonPathConfig;
import io.restassured.path.xml.XmlPath;
import io.restassured.path.xml.config.XmlPathConfig;
import java.lang.reflect.Type;
public interface ResponseBodyExtractionOptions extends ResponseBodyData {
/**
* Get the body and map it to a Java object. For JSON responses this requires that you have either
*
* - Jackson, or
* - Gson
*
* in the classpath or for XML responses it requires JAXB to be in the classpath.
*
* It also requires that the response content-type is either JSON or XML or that a default parser has been been set.
* You can also force a specific object mapper using {@link #as(Class, ObjectMapper)}.
*
* @return The object
*/
T as(Class cls);
/**
* Get the body and map it to a Java object using a specific object mapper type. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Class cls, ObjectMapperType mapperType);
/**
* Get the body and map it to a Java object using a specific object mapper. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Class cls, ObjectMapper mapper);
/**
* Get the body and map it to a Java type with specified type. For JSON responses this requires that you have either
*
* - Jackson, or
* - Gson
*
* in the classpath or for XML responses it requires JAXB to be in the classpath.
*
* It also requires that the response content-type is either JSON or XML or that a default parser has been been set.
* You can also force a specific object mapper using {@link #as(Type, ObjectMapper)}.
*
* @return The object
*/
T as(Type cls);
/**
* Get the body and map it to a Java type with specified type using a specific object mapper type. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Type cls, ObjectMapperType mapperType);
/**
* Get the body and map it to a Java type using a specific object mapper. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Type cls, ObjectMapper mapper);
/**
* Get a JsonPath view of the response body. This will let you use the JsonPath syntax to get values from the response.
* Example:
*
* Assume that the GET request (to http://localhost:8080/lotto) returns JSON as:
*
* {
* "lotto":{
* "lottoId":5,
* "winning-numbers":[2,45,34,23,7,5,3],
* "winners":[{
* "winnerId":23,
* "numbers":[2,45,34,23,3,5]
* },{
* "winnerId":54,
* "numbers":[52,3,12,11,18,22]
* }]
* }
* }
*
*
* You can the make the request and get the winner id's by using JsonPath:
*
* List winnerIds = get("/lotto").jsonPath().getList("lotto.winnders.winnerId");
*
*/
JsonPath jsonPath();
/**
* Get a JsonPath view of the response body using the specified configuration.
*
* @param config The configuration to use
* @see #jsonPath()
*/
JsonPath jsonPath(JsonPathConfig config);
/**
* Get an XmlPath view of the response body. This will let you use the XmlPath syntax to get values from the response.
* Example:
*
* Imagine that a POST request to http://localhost:8080/greetXML returns:
*
* <greeting>
* <firstName>John</firstName>
* <lastName>Doe</lastName>
* </greeting>
*
*
*
* You can the make the request and get the winner id's by using JsonPath:
* * String firstName = get("/greetXML").xmlPath().getString("greeting.firstName"); **/ XmlPath xmlPath(); /** * Get an XmlPath view of the response body with a given configuration. * * @param config The configuration of the XmlPath * @see #xmlPath() */ XmlPath xmlPath(XmlPathConfig config); /** * Get an XmlPath view of the response body but also pass in a {@link XmlPath.CompatibilityMode}. * This is mainly useful if you want to parse HTML documents. * * @param compatibilityMode The compatibility mode to use * @see #htmlPath() * @see #xmlPath() */ XmlPath xmlPath(XmlPath.CompatibilityMode compatibilityMode); /** * Get an XmlPath view of the response body that uses {@link XmlPath.CompatibilityMode}
HTML
.
* This is mainly useful when parsing HTML documents.
*
* Note that this is the same as calling {@link #xmlPath(XmlPath.CompatibilityMode)} with CompatibilityMode
HTML
.
*
* Note that you can also also supply arguments, for example: *
* String z = get("/x").path("x.y.%s", "z"); ** * The path and arguments follows the standard formatting syntax of Java. * * * @param path The json- or xml path * @param