本文整理汇总了Java中com.jayway.restassured.response.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.jayway.restassured.response包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: goPost
import com.jayway.restassured.response.Response; //导入依赖的package包/类
public Response goPost(String url,String input)
{
Response resp=null;
try
{
RequestSpecBuilder builder = new RequestSpecBuilder();
builder.setBody(input);
builder.setContentType("application/json; charset=UTF-8");
RequestSpecification requestSpec = builder.build();
resp = given().spec(requestSpec).when().post(url);
}catch(Exception ex)
{
ex.printStackTrace();
}
return resp;
}
示例2: secondRequestOnStatefulComplexEndpointWithCookiesGivesSessionResult
import com.jayway.restassured.response.Response; //导入依赖的package包/类
@Test
public void secondRequestOnStatefulComplexEndpointWithCookiesGivesSessionResult() {
// first request should give us the proper name and a cookie
Response response = given().get(HOST + "/complex/foo");
response.then().assertThat().body(containsString("your name is: foo"));
Cookies cookies = response.getDetailedCookies();
assertNotNull(cookies);
LOG.debug("cookies are: " + cookies);
assertTrue(cookies.exist());
assertTrue(cookies.hasCookieWithName(SessionToCookieFilter.SESSIONDATACOOKIENAME));
// second request with given cookie and ANOTHER name should still give us "foo" instead of "bar" since this info is stored in the session data cookie
// we also expect the same cookie as before
response = given().with().cookies(cookies).get(HOST + "/complex/bar");
response.then().assertThat().body(containsString("your name is: foo"));
cookies = response.getDetailedCookies();
LOG.debug("cookies are: " + cookies);
assertTrue(cookies.exist());
assertTrue(cookies.hasCookieWithName(SessionToCookieFilter.SESSIONDATACOOKIENAME));
}
示例3: sendPostRequest
import com.jayway.restassured.response.Response; //导入依赖的package包/类
public static Response sendPostRequest( String endPoint, Map dataMap, Map headerMap, String modifiedXMLRequest )
{
String requestDetails = "\nEndpoint : " + endPoint + "\n--------------------\n" + modifiedXMLRequest;
saveTextLog( "Modified XML Request", requestDetails );
String responseXML = new String();
try
{
Response response = given()
.auth().basic( dataMap.get( "username" ).toString(), dataMap.get( "password" ).toString() )
.headers( headerMap )
.body( modifiedXMLRequest )
.post( endPoint );
responseXML = getResponseInString( response );
String responseDetails = "\nResponse : " + "\n--------------------\n" + ModifyXML.getPrettyXML( responseXML );
saveTextLog( "Response", responseDetails );
return response;
} catch( Exception e )
{
Throwables.propagate( new Exception( String.format( "Failed at sending post request : URI - [%s] and endpoint - [%s] : \n and the response is %s", baseURI, endPoint, responseXML ), e ) );
}
return null;
}
示例4: restrictions
import com.jayway.restassured.response.Response; //导入依赖的package包/类
@Test
public void restrictions() throws IOException, DateParseException
{
String stagingUrl = staging.create();
// put a file to the folder1 content url
final File file = new File(getPathFromUrl(Attachments.get("avatar.png")));
Response response = staging.putFile(stagingUrl, AVATAR_PATH, file);
assertEquals(response.getHeader("ETag"), AVATAR_PNG_ETAG);
RequestSpecification notModified = staging.notModified();
notModified.header("If-None-Match", AVATAR_PNG_ETAG);
staging.get(notModified, stagingUrl, AVATAR_PATH);
response = staging.head(stagingUrl, AVATAR_PATH);
Date date = DateUtil.parseDate(response.header("Last-Modified"));
notModified = staging.notModified();
notModified.header("If-Modified-Since", DateUtil.formatDate(date));
staging.get(notModified, stagingUrl, AVATAR_PATH);
}
示例5: goGet
import com.jayway.restassured.response.Response; //导入依赖的package包/类
public Response goGet(String url)
{
System.out.println("inside doget");
Response resp =null;
try
{
resp = given().when().get(url);
}catch(Exception ex)
{
ex.printStackTrace();
}
return resp;
}
示例6: retrieveInfo
import com.jayway.restassured.response.Response; //导入依赖的package包/类
/**
* This method retrieves info from the JSON input objects.
*
* @param testCaseParamsInput the input parameters to define a test case
* @return Map webapp name, response from the specified webapp
*/
public Map<String, Response> retrieveInfo(Map testCaseParamsInput) {
Map<String, Response> respRetrieved = new HashMap<>();
try {
compactInfoToCompare(testCaseParamsInput);
if (isRunnableTest) {
this.logUtils.trace("number of blocks to load: {}", httpMethods.size());
httpMethods.entrySet().stream().map((entry) -> entry.getKey()).forEach((serviceId) -> {
Response rsp = retrieveSingleBlockRsp(serviceId);
if (rsp == null) {
this.logUtils.debug("response for '{}' : null", serviceId);
} else {
this.logUtils.debug("response for '{}': '{}'", serviceId, rsp.asString());
}
respRetrieved.put(serviceId, rsp);
});
}
} catch (Exception oEx) {
this.logUtils.debug("Exception message: '{}'", oEx.getLocalizedMessage());
}
return respRetrieved;
}
示例7: eval
import com.jayway.restassured.response.Response; //导入依赖的package包/类
public Object eval(Response response) {
Object value = null;
String data = response.body().asString();
if (bodyAssert.getSelect() != null) {
Multimap<String, List<String>> exps = parsedExpressions(bodyAssert.getSelect());
for (Entry<String, List<String>> entry : exps.entries()) {
if (entry.getKey().toLowerCase().startsWith(ExpressionType.jsonpath.toString().toLowerCase())) {
value = JsonExpression.build(data, entry.getKey(), entry.getValue()).parse();
} else if (entry.getKey().toLowerCase().startsWith(ExpressionType.regex.toString().toLowerCase())) {
value = RegexExpression.build(data, entry.getKey(), entry.getValue()).parse();
} else {
throw new TestException("Expression="+entry.getKey()+" not supported in select=" + bodyAssert.getSelect());
}
data = JsonMapper.toJson(value);
}
}
return value;
}
示例8: jsonSchemaValidation
import com.jayway.restassured.response.Response; //导入依赖的package包/类
/**
* Check on the json schema of the retrieved responses; if the element
"jsonSchemaToCheck" is not present in the json input file, the check will
be simply skipped.
*
* @param testCaseParams it is a map retrieved from the json input file with
* all input test data
* @return true if the check is ok, false otherwise
*/
private boolean jsonSchemaValidation(Map testCaseParams) {
boolean isCheckOk = true;
TestCaseUtils tcUtils = TestSuiteHandler.getInstance().getTestCaseUtils();
//isBlocking: if it is true, in case of failure the test stops running, otherwise it will go on running with the other checks (the final result does not change)
boolean isBlocking = tcUtils.getSystemParamOnBlocking();
Map<String, String> expectedParams = (Map<String, String>) testCaseParams.get(EXPECTS_JSON_ELEMENT);
String jsonSchemaPathToCheck = tcUtils.getRspJsonSchemaPath(expectedParams.get(JSON_SCHEMA_TO_CHECK_JSON_ELEMENT));
if (expectedParams.containsKey(JSON_SCHEMA_TO_CHECK_JSON_ELEMENT) && jsonSchemaPathToCheck != null) {
logUtils.debug("starting json schema validation");
try {
getClass().getResourceAsStream("/" + jsonSchemaPathToCheck).available();
isCheckOk &= validateSchema(isBlocking, (Response) responses, jsonSchemaPathToCheck);
} catch (Exception oEx) {
assertionHandler.assertion(isBlocking, "fail",
logUtils.getTestCaseDetails() + "BasicChecks - jsonSchemaValidation -- the file '/" + jsonSchemaPathToCheck + "' does not exist");
}
} else {
logUtils.debug("json schema validation disabled");
}
return isCheckOk;
}
示例9: validateSchema
import com.jayway.restassured.response.Response; //导入依赖的package包/类
/**
* Json Schema validation.
*
* @param isBlocking boolean value: if it is true, in case of failure the
* test stops running, otherwise it will go on running with the other checks
* (the final result does not change)
* @param resp Response retrieved
* @param jsonSchemaPath path of the json schema to use for the check
* @return true if the check is ok, false otherwise
*/
private boolean validateSchema(boolean isBlocking, Response resp, String jsonSchemaPath) {
boolean isCheckOk = true;
try {
JsonSchemaValidator validator = JsonSchemaValidator.matchesJsonSchemaInClasspath(jsonSchemaPath);
resp.then().assertThat().body(validator);
logUtils.debug("json schema validation OK");
} catch (Exception oEx) {
isCheckOk = false;
logUtils.error("json schema validation NOT OK");
assertionHandler.assertion(isBlocking, "fail", logUtils.getTestCaseDetails()
+ "BasicChecks - validateSchema >> validation schema failed. -- exception: "
+ oEx.getLocalizedMessage());
}
return isCheckOk;
}
示例10: cookieChecks
import com.jayway.restassured.response.Response; //导入依赖的package包/类
/**
* Check on the specific header element of the response; if the element
* "cookieCheck" is not present in the json input file, the check will be
* simply skipped.
*
* @param testCaseParams it is a map retrieved from the json input file with
* all input test data
*/
private boolean cookieChecks(Map testCaseParams) {
boolean isCheckOk = true;
//isBlocking if it is true, in case of failure the test stops running, otherwise it will go on running with the other checks(the final result does not change)
boolean isBlocking = TestSuiteHandler.getInstance().getTestCaseUtils().getSystemParamOnBlocking();
Map<String, Object> expectedParams = (Map<String, Object>) testCaseParams.get(EXPECTS_JSON_ELEMENT);
if (expectedParams.containsKey(COOKIE_CHECK_JSON_ELEMENT)) {
Map<String, String> cookieCheckMaps = (Map<String, String>) expectedParams.get(COOKIE_CHECK_JSON_ELEMENT);
Set<Map.Entry<String, String>> cookieEntries = cookieCheckMaps.entrySet();
for (Map.Entry<String, String> cookieEntry: cookieEntries) {
String cookieName = cookieEntry.getKey();
String cookieExpectedValue = cookieEntry.getValue();
logUtils.debug("cookie name '{}'", cookieName);
String currentCookie = ((Response) responses).getCookie(cookieName);
isCheckOk &= assertionHandler.assertion(isBlocking, "assertEquals", logUtils.getTestCaseDetails() + "check on cookie '" + cookieName + "'-- ",
currentCookie, cookieExpectedValue);
}
}
return isCheckOk;
}
示例11: process
import com.jayway.restassured.response.Response; //导入依赖的package包/类
/**
* This method gets in input the structure of "actualValue" or "expectedValue" and gives in output
* the final string we have to use for the verification step.
* @param extractionObj the input "object" that represents "actualValue" or "expectedValue". It can be, in the
simplest context, a string. But it can be another json object with inner parameters, for example a regexp on
the service response, useful to retrieve a value. In case of inner json object, there is a recursive use
of "placeholderProcessString" method.
* @param response It is the response retrieved after the request to the service under test.
* @param retrievedParametersFlowMode The parameters passed to the steps in flow mode
* @return the final string we have to use for the verification step
*/
public String process(Object extractionObj, Response response, Map retrievedParametersFlowMode) {
String outputStr = "";
this.retrievedParametersFlowMode = retrievedParametersFlowMode;
logUtils.trace("extractionObj = '{}'", extractionObj.toString());
if (extractionObj.getClass().equals(String.class)) {
outputStr = processString((String) extractionObj, response);
} else if (extractionObj.getClass().equals(HashMap.class)) {
// we are using HashMap because JsonPath uses maps to manage json object
outputStr = processMap((Map) extractionObj, response);
} else {
throw new HeatException(logUtils.getExceptionDetails() + "actualValue/expectedValue belongs to "
+ extractionObj.getClass().toString() + " not supported");
}
logUtils.trace("outputStr = '{}' (class: {})", outputStr, extractionObj.getClass().toString());
return outputStr;
}
示例12: retrieveObj
import com.jayway.restassured.response.Response; //导入依赖的package包/类
private String retrieveObj(String objName, Map<String, Object> singleCheckMap, Map<String, Response> mapServiceIdResponse) {
Map<String, Object> objMapRetrieved = (Map<String, Object>) singleCheckMap.get(objName);
String strRetrieved = "";
try {
if (objMapRetrieved.containsKey(JSON_ELEM_ACTUAL_VALUE)) {
if (objMapRetrieved.containsKey(JSON_ELEM_REFERRING_OBJECT)) {
Response rsp = mapServiceIdResponse.get(objMapRetrieved.get(JSON_ELEM_REFERRING_OBJECT).toString());
DataExtractionSupport dataSupport = new DataExtractionSupport(this.logUtils);
strRetrieved = dataSupport.process(objMapRetrieved.get(JSON_ELEM_ACTUAL_VALUE), rsp, retrievedParameters);
} else {
if (!objMapRetrieved.get(JSON_ELEM_ACTUAL_VALUE).toString().contains(PlaceholderHandler.PLACEHOLDER_SYMBOL_BEGIN)) {
strRetrieved = objMapRetrieved.get(JSON_ELEM_ACTUAL_VALUE).toString();
} else {
throw new HeatException(this.logUtils.getExceptionDetails() + "Input Json does not contain 'referringObjectName' field");
}
}
} else {
throw new HeatException(this.logUtils.getExceptionDetails() + "Input Json does not contain 'actualValue' field");
}
} catch (Exception oEx) {
throw new HeatException(this.logUtils.getExceptionDetails() + "Exception occurred: '" + oEx.getLocalizedMessage() + "'");
}
return strRetrieved;
}
示例13: checkJsonPathPresence
import com.jayway.restassured.response.Response; //导入依赖的package包/类
private boolean checkJsonPathPresence(String expectedValue) {
boolean isExecutionOk = false;
String actualValue = fieldsToCheck.get(JSON_ELEM_ACTUAL_VALUE).toString();
// the check can be executed ONLY if the actual value is a "${path"-style placeholder
if (actualValue.contains(PlaceholderHandler.PATH_PLACEHOLDER)) {
TestCaseUtils testCaseUtils = TestSuiteHandler.getInstance().getTestCaseUtils();
String jsonPathToCheck = testCaseUtils.regexpExtractor(actualValue, PlaceholderHandler.PATH_JSONPATH_REGEXP, 1);
this.logUtils.debug("check if the path '{}' is {} in the response",
jsonPathToCheck, expectedValue);
boolean isPathPresent = fieldPresent((Response) responses, jsonPathToCheck);
if (PlaceholderHandler.PLACEHOLDER_NOT_PRESENT.equals(expectedValue)) {
isExecutionOk = assertionHandler.assertion(isBlocking, "assertFalse",
logUtils.getTestCaseDetails() + "json path '" + jsonPathToCheck + "' has not to be present in the response --> ", isPathPresent);
} else if (PlaceholderHandler.PLACEHOLDER_PRESENT.equals(expectedValue)) {
isExecutionOk = assertionHandler.assertion(isBlocking, "assertTrue",
logUtils.getTestCaseDetails() + "json path '" + jsonPathToCheck + "' has to be present in the response -->", isPathPresent);
}
} else {
isExecutionOk = false;
logUtils.error("the check can be executed ONLY if the actual value is a \"" + PlaceholderHandler.PLACEHOLDER_SYMBOL_BEGIN + "path\"-style placeholder");
}
return isExecutionOk;
}
示例14: cleanRequestOnStatelessEndpointCreatesNoSession
import com.jayway.restassured.response.Response; //导入依赖的package包/类
@Test
public void cleanRequestOnStatelessEndpointCreatesNoSession() {
Response response = given().get(HOST + "/sessioncheck");
response.then().assertThat().body(containsString("you have no session"));
Cookies cookies = response.getDetailedCookies();
LOG.debug("cookies are: " + cookies);
assertFalse(cookies.exist());
}
示例15: cleanRequestCreatingEmptySessionReturnsNoSessionDataCookie
import com.jayway.restassured.response.Response; //导入依赖的package包/类
@Test
public void cleanRequestCreatingEmptySessionReturnsNoSessionDataCookie() {
Response response = given().get(HOST + "/createemptysession");
response.then().assertThat().body(containsString("hello, your session is"));
Cookies cookies = response.getDetailedCookies();
LOG.debug("cookies are: " + cookies);
if (cookies != null) {
assertFalse(cookies.hasCookieWithName(SessionToCookieFilter.SESSIONDATACOOKIENAME));
}
}