当前位置: 首页>>代码示例>>Java>>正文


Java Response.asString方法代码示例

本文整理汇总了Java中com.jayway.restassured.response.Response.asString方法的典型用法代码示例。如果您正苦于以下问题:Java Response.asString方法的具体用法?Java Response.asString怎么用?Java Response.asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jayway.restassured.response.Response的用法示例。


在下文中一共展示了Response.asString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retriveStringFromPath

import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
/**
 * This method is useful to retrieve a json path from a json response.
 * Example:
 * rsp:  {"status":"FAILURE","machines":[{"name":"m1","status":"OK"},{"name":"m2","status":"NOT OK"}]}
 * if path = "status" --> expected output = "FAILURE"
 * if path = "machines[0].name" --> expected output = "m1"
 * if path = "machines.name" --> expected output = "[m1,m2]"
 * if path = "." --> expected output = "{"status":"FAILURE","machines":[{"name":"m1","status":"OK"},{"name":"m2","status":"NOT OK"}]}"
 * @param rsp is the Response object coming from the request to the service under test
 * @param path is the json path to retrieve
 * @return the string retrieved
 */
private String retriveStringFromPath(Response rsp, String path) {
    String output = "";
    try {
        if (JSONPATH_COMPLETE.equals(path)) {
            output = rsp.asString().trim();
        } else {
            JsonPathConfig config = new JsonPathConfig(JsonPathConfig.NumberReturnType.BIG_DECIMAL);
            output = rsp.jsonPath(config).get(path).toString();
        }
    } catch (Exception oEx) {
        logUtils.error("It is not possible to retrieve the jsonPath "
                + "('{}') from the current response. --> response: {}", path, rsp.asString());
        throw new HeatException(logUtils.getExceptionDetails() + "It is not possible to retrieve the jsonPath (" + path
                + ") from the current response. --> response: " + rsp.asString());
    }
    return output;
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:30,代码来源:PlaceholderHandler.java

示例2: getUserStory

import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
@RequestMapping(value="/ustory",method=RequestMethod.POST)
public String getUserStory(@RequestBody String payload)
{
	String c1="/getusers"; //get
	String c2="/add"; //post
	String c3="/greet"; //get
	String responseC1="URL = /getusers";
	String responseC2="URL = /add";
	String responseC3="URL = /greet";
	
	
	ServiceCalls sc = new ServiceCalls();
	try
	{
	
	 // C1	
	 Response  resp = sc.goGet(c1);
	 responseC1=responseC1+resp.asString();
	 
	 //C2
	 Response respc2 = sc.goPost(c2,payload);
	 
	 responseC2 = responseC2+respc2.asString();
	 
	 //C3
	 
	 Response  respC3 = sc.goGet(c3);
	 responseC3=responseC3+respC3.asString();
	 
	}catch(Exception ex)
	{
		ex.printStackTrace();
	}
	
	
	return responseC1+"\n"+responseC2+"\n"+responseC3;
}
 
开发者ID:kattavijay,项目名称:spring-microservices,代码行数:38,代码来源:Userdataservice.java

示例3: getJsonPath

import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
/**
 * Gets the json path.
 *
 * @param res
 *            the res
 * @return the json path
 */
/*
 *** Returns JsonPath object*** First convert the API's response to String
 * type with "asString()" method. Then, send this String formatted json
 * response to the JsonPath class and return the JsonPath
 */
public static JsonPath getJsonPath(final Response res) {
	final String json = res.asString();
	return new JsonPath(json);
}
 
开发者ID:ERS-HCL,项目名称:itest-starter,代码行数:17,代码来源:RestUtil.java

示例4: getJsonPath

import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
public static JsonPath getJsonPath( Response res )
{
    String json = res.asString();
    //System.out.print("returned json: " + json +"\n");
    return new JsonPath( json );
}
 
开发者ID:hemano,项目名称:cucumber-framework-java,代码行数:7,代码来源:RestUtil.java


注:本文中的com.jayway.restassured.response.Response.asString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。