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


Java Response类代码示例

本文整理汇总了Java中io.restassured.response.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: create

import io.restassured.response.Response; //导入依赖的package包/类
/**
 * The C of CRUD
 * 
 * @param reqSpec
 * @return The URL of the created customer
 */
private String create(RequestSpecification reqSpec) {
	
	final Customer newCustomer = Customer.ofType(PERSON)
			.withBirthDate(LocalDate.of(1990, Month.AUGUST, 16))
			.build();
	
	// Create a new customer
	final Response resp = 
		given()
			.spec(reqSpec)
			.body(newCustomer)
		.when()
			.post("/customers")
		.then()
			.assertThat()
			.statusCode(201)
			.extract().response();
	
	final String newCustomerUrl = resp.header("Location");
	assertThat(newCustomerUrl).contains("/customers/");
	
	return newCustomerUrl;
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:30,代码来源:CustomerServiceIT.java

示例2: execute

import io.restassured.response.Response; //导入依赖的package包/类
/**
 * @author wasiq.bhamla
 * @since Aug 25, 2017 2:49:52 PM
 * @param method
 * @param shouldWork
 * @return instance
 */
public RequestHandler execute (final Method method, final boolean shouldWork) {
	LOG.info (LINE);
	LOG.info (format ("Executing request with method [%s]...", method));
	LOG.info (LINE);
	try {
		final Response res = this.request.request (method);
		this.response = new ResponseHandler (this.name, res, this.setting);
		if (shouldWork) {
			res.then ()
				.statusCode (200);
		}
	}
	catch (final Exception e) {
		fail (RequestExecutionFailedError.class, "Execute failed:", e);
	}
	return this;
}
 
开发者ID:WasiqB,项目名称:coteafs-services,代码行数:25,代码来源:RequestHandler.java

示例3: queryForToken

import io.restassured.response.Response; //导入依赖的package包/类
/**
 * Request an OAuth2 token from the Authentication Server
 * 
 * @return The token
 */
private String queryForToken() {
	
	final Response response = 
		given()
			.auth().basic(CLIENT_ID, CLIENT_SECRET)
			.and().relaxedHTTPSValidation("TLS")
			.and().contentType(ContentType.URLENC)
			.and().accept(ContentType.JSON)
			.and().body("grant_type=client_credentials")
		.when()
			.post("/oauth/token")
		.then()
			.statusCode(200)
			.and().body("access_token", is(notNullValue()))
			.extract().response();
	
	return response.path("access_token");
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:24,代码来源:CustomerServiceIT.java

示例4: test

import io.restassured.response.Response; //导入依赖的package包/类
@Test
public void test() throws InstantiationException, IllegalAccessException {
	String url = getBaseUri() + "country/ch";
	io.restassured.response.Response getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());

	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Schweiz"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));

	String patchData = "{'data':{'id':'ch','type':'country','attributes':{'deText':'Test','enText':'Switzerland','ctlActCd':true}}}".replaceAll("'", "\"");

	Response patchResponse = RestAssured.given().body(patchData.getBytes()).header("content-type", JsonApiMediaType.APPLICATION_JSON_API).when().patch(url);
	patchResponse.then().statusCode(HttpStatus.SC_OK);

	getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());
	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Test"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:20,代码来源:CustomResourceFieldTest.java

示例5: init

import io.restassured.response.Response; //导入依赖的package包/类
public String init() throws Exception {
    String result;
    fillTemplate();
    Response r =
            given()
                    .log().all()
                    .headers(headers)
                    .body(requestBody)
                    .when().post(URL);

    String xmlResponse = r.getBody().asString();
    LOG.debug("Response: "+ xmlResponse);
    result = "<![CDATA["+from(xmlResponse).get("Envelope.Body.PrepareRequestResponse.response").toString()+"]]>";
    return result;
}
 
开发者ID:asmodeirus,项目名称:BackOffice,代码行数:16,代码来源:MesProWrp.java

示例6: durationAndDistanceTablesTest

import io.restassured.response.Response; //导入依赖的package包/类
@Test
public void durationAndDistanceTablesTest() {
	Response response = given()
			.param("locations", getParameter("locations"))
			.param("sources", getParameter("sources1"))
			.param("destinations", getParameter("destinations1"))
			.param("metrics", "distance|duration")
			.param("profile", "driving-car")
			.when()
			.log().all()
			.get(getEndPointName());

	Assert.assertEquals(response.getStatusCode(), 200);
	JSONObject jResponse = new JSONObject(response.body().asString());
	checkTableDimensions(jResponse, "durations", 2, 1);
	checkTableDimensions(jResponse, "distances", 2, 1);
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:18,代码来源:ResultsValidationTest.java

示例7: testAuthJson

import io.restassured.response.Response; //导入依赖的package包/类
@Test
public void testAuthJson() {
	Map<String, Object> map = new HashMap<>();
	map.put("mode", 2);
	map.put("id", "23452345234");
	map.put("identity", "11111111");
	map.put("challenge", "s随风倒根深蒂固g");
	map.put("response", "98CF0059D520E39E2016EB3AC70763BB26B665D77CD81378F11E5479E7094ACD");
	map.put("sign", "1232321");
	
	Response post = RestAssured
			.given()
			.contentType("application/json")
			.request()
			.body(JSON.toJSONString(map))
			.post("/auth");
	
	Assert.assertEquals(500, post.getStatusCode());
	//JsonPath jp = new JsonPath(post.asString());
	//System.out.println(post.asString());//根据要求添加断言
}
 
开发者ID:strictnerd,项目名称:LearningSummary,代码行数:22,代码来源:HTTPAPITest.java

示例8: canGetC3POandParseWithJsonPath

import io.restassured.response.Response; //导入依赖的package包/类
@Test
public void canGetC3POandParseWithJsonPath(){

    // use RestAssured to make an HTML Call
    Response response = RestAssured.get(
                      "http://swapi.co/api/people/2/?format=json").
                       andReturn();

    String json = response.getBody().asString();
    System.out.println(json);

    // Use the JsonPath parsing library of RestAssured to Parse the JSON
    
    JsonPath jsonPath = new JsonPath(json);
    Assert.assertEquals(
            "C-3PO",
            jsonPath.getString("name"));

}
 
开发者ID:eviltester,项目名称:libraryexamples,代码行数:20,代码来源:SwapiAPIUsageTest.java

示例9: canGetC3POandParseWithJsonPathIntoObject

import io.restassured.response.Response; //导入依赖的package包/类
@Test
public void canGetC3POandParseWithJsonPathIntoObject(){

    // use RestAssured to make an HTML Call
    Response response = RestAssured.get(
            "http://swapi.co/api/people/2/?format=json").
            andReturn();

    String json = response.getBody().asString();
    System.out.println(json);

    // Use the JsonPath parsing library of RestAssured to Parse the JSON into an object

   Person c3po = new JsonPath(json).getObject("$", Person.class);
    Assert.assertEquals(
            "C-3PO",
            c3po.name);

}
 
开发者ID:eviltester,项目名称:libraryexamples,代码行数:20,代码来源:SwapiAPIUsageTest.java

示例10: CreateBugForTesting

import io.restassured.response.Response; //导入依赖的package包/类
@Before
public void CreateBugForTesting() {
    driver.navigate().to(baseUrl);

    // Login
    Map<String, String> payload = new LoginPayload("[email protected]", "password").build();
    Response login = Login.postLogin(payload);

    String loginCookieToken = login.getCookie("Bugzilla_logincookie");

    LoginManager loginManager = new LoginManager(driver);
    loginManager.setLoginCookies(loginCookieToken);

    // Create bug
    BugPayload bugPayload = new BugPayload("TestProduct", "TestComponent", "testing", "unspecified", "Mac OS", "PC", "This is a minor description");
    bugResponsePayload = Bug.postBug(bugPayload).as(BugResponsePayload.class);
}
 
开发者ID:mwinteringham,项目名称:api-webdriver-harmony,代码行数:18,代码来源:BugPageTest.java

示例11: amendProject

import io.restassured.response.Response; //导入依赖的package包/类
public Response amendProject(String projectId,
                             Map<String, String> fieldsToAmend) {

    StringBuilder messageBody = new StringBuilder();

    messageBody.append("<project>");

    for(String key: fieldsToAmend.keySet()){
        messageBody.append(String.format("<%s>", key));
        String value = fieldsToAmend.get(key);
        if(value!=null){
            messageBody.append(value);
        }
        messageBody.append(String.format("</%s>", key));
    }

    messageBody.append("</project>");

    return httpMessageSender.putXmlMessageTo(
                                TracksApiEndPoints.project(projectId),
                                messageBody.toString());
}
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:23,代码来源:TracksApi.java

示例12: login

import io.restassured.response.Response; //导入依赖的package包/类
public void login() {

        Response response = httpMessageSender.getResponseFrom("/login");

        String authenticity_token =
                        getAuthenticityTokenFromResponse(response);

        // post the login form and get the cookies
        response = loginUserPost(username, password, authenticity_token);

        if(response.getStatusCode()==302) {
            //get the cookies
            loggedInCookieJar = response.getCookies();
        }else{
            System.out.println(response.asString());
            new RuntimeException("Could not login");
        }
    }
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:19,代码来源:TracksAppAsApi.java

示例13: loginUserPost

import io.restassured.response.Response; //导入依赖的package包/类
private Response loginUserPost(String username, String password,
                               String authenticityToken) {

    UrlParams params = new UrlParams();
    params.add("utf8","%E2%9C%93");
    params.addEncoded("authenticity_token",
                        authenticityToken);
    params.add("user_login", username);
    params.add("user_password", password);
    params.add("user_noexpiry", "on");
    params.add("login", "Sign+in");

    Response response = httpMessageSender.postFormMessageTo(
                                                params.toString(),
                                        "/login");
    return response;
}
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:18,代码来源:TracksAppAsApi.java

示例14: createUserPost

import io.restassured.response.Response; //导入依赖的package包/类
private Response createUserPost(String username, String password,
                                String authenticityToken,
                                Map<String, String> loggedInCookieJar) {

    UrlParams params = new UrlParams();
    params.add("utf8","%E2%9C%93");
    params.addEncoded("authenticity_token", authenticityToken);
    params.add("user%5Blogin%5D", username);
    params.add("user%5Bpassword%5D", password);
    params.add("user%5Bpassword_confirmation%5D", password);

    Response response = httpMessageSender.postFormMessageTo(
                                                params.toString(),
                                                "/users",
                                                loggedInCookieJar);

    return response;
}
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:19,代码来源:TracksAppAsApi.java

示例15: putXmlMessageTo

import io.restassured.response.Response; //导入依赖的package包/类
public Response putXmlMessageTo(String endpoint, String msg,
                                Map<String, String> cookieJar) {

    URL theEndPointUrl = createEndPointURL(url, endpoint);

    Response ret =
            given().
                    auth().preemptive().
                                basic(authUser, authPassword).
                    body(msg).contentType("text/xml").
                    cookies(cookieJar).
            when().
                    put(theEndPointUrl.toExternalForm()).
            andReturn();

    return setLastResponse(ret);
}
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:18,代码来源:HttpMessageSender.java


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