rest-assured

How to set OAuth realm in RestAssured

与世无争的帅哥 提交于 2020-07-22 08:53:32
问题 I am using RestAssured library for automating NetSuite Restlets. This Restlets are using OAuth 1.0 for authentication. Apart from consumer key, consumer secret, access token and token secret, I need to set advanced fields like REALM. But I couldn't find any way to set that in RestAssured. RequestSpecification request = new RequestSpecBuilder() .addHeader("Content-Type", ContentType.JSON.toString()) .setBaseUri(url).build() .auth().oauth( netsuiteConfig.getNetsuiteConsumerKey(), netsuiteConfig

“Application/vnd.api+json” throws “Unsupported Media Type”

社会主义新天地 提交于 2020-07-22 05:47:59
问题 I am automating an API for a POST call using Rest Assured and for Content-Type and ACCEPT header I have to use " application/vnd.api+json ". But every time I use "application/vnd.api+json" I get 415 status code. Although the same POST call using Postman works perfectly fine. Here is my sample code : ApiUtils.setBaseURI("xxxxx"); ApiUtils.setBasePath("/orders"); RequestSpecification request = RestAssured.given().auth().oauth2(BaseClass.token); request.header("ACCEPT", "application/vnd.api+json

“Application/vnd.api+json” throws “Unsupported Media Type”

烂漫一生 提交于 2020-07-22 05:47:06
问题 I am automating an API for a POST call using Rest Assured and for Content-Type and ACCEPT header I have to use " application/vnd.api+json ". But every time I use "application/vnd.api+json" I get 415 status code. Although the same POST call using Postman works perfectly fine. Here is my sample code : ApiUtils.setBaseURI("xxxxx"); ApiUtils.setBasePath("/orders"); RequestSpecification request = RestAssured.given().auth().oauth2(BaseClass.token); request.header("ACCEPT", "application/vnd.api+json

RestAssured Parsing Json Array Response using foreach loop

ぃ、小莉子 提交于 2020-07-09 19:16:25
问题 I have response from RestAssured which is a JsonArray looks similar to the below code [{ "id": "1", "applicationId": "ABC" }, { "id": "2", "applicationId": "CDE" }, { "id": "3", "applicationId": "XYZ" }] I use code to get the "id" from the first Json element List<String> jresponse = response.jsonPath().getList("$"); for (int i = 0; i < jsonResponse.size(); i++) { String id = response.jsonPath().getString("id[" + i + "]"); if(id.equals("1"){ do something } else { something else } } Is there a

RestAssured Parsing Json Array Response using foreach loop

十年热恋 提交于 2020-07-09 19:15:08
问题 I have response from RestAssured which is a JsonArray looks similar to the below code [{ "id": "1", "applicationId": "ABC" }, { "id": "2", "applicationId": "CDE" }, { "id": "3", "applicationId": "XYZ" }] I use code to get the "id" from the first Json element List<String> jresponse = response.jsonPath().getList("$"); for (int i = 0; i < jsonResponse.size(); i++) { String id = response.jsonPath().getString("id[" + i + "]"); if(id.equals("1"){ do something } else { something else } } Is there a

java REST Assured response body with Content-Type: text/html with injected html tags

心不动则不痛 提交于 2020-07-07 01:30:00
问题 Let's say someone developed rest api that returns data in json format but he didn't set response Content-Type to application/json but text/html . Now I have test written in REST Assured: given() .param("username", username) .param("password", password) .when() .get("/authenticate") .then() .statusCode(200) .body("user.id" , hasItem(20)); but it doesn't work. I logged out response body and and that's what I get: <html> <body>{"key":"752E7A74E8F3999BE9EFE3EA0E0DF320","user":{"id":20,"firstName"

java REST Assured response body with Content-Type: text/html with injected html tags

不羁岁月 提交于 2020-07-07 01:28:10
问题 Let's say someone developed rest api that returns data in json format but he didn't set response Content-Type to application/json but text/html . Now I have test written in REST Assured: given() .param("username", username) .param("password", password) .when() .get("/authenticate") .then() .statusCode(200) .body("user.id" , hasItem(20)); but it doesn't work. I logged out response body and and that's what I get: <html> <body>{"key":"752E7A74E8F3999BE9EFE3EA0E0DF320","user":{"id":20,"firstName"

Gson.toJsonTree(intValue) throws Null pointer exception when trying to pass Integer parameter value

若如初见. 提交于 2020-06-29 04:15:19
问题 We are automating rest APIs using Rest Assured. During this process, trying to have a re-usable method created to pass different JSON nodes with different values. Interger variable created: Integer amt = 50; Method created: public void replaceValues_gson(String mainNode, String childNode, Integer amt) { if(amt != null){ jsonObjectNew.getAsJsonObject("mainNode").add("childNode", gson.toJsonTree(amt)); } //here 'amt' throws an error as java.lang.NullPointerException; Also the amt it shows as 9

how to see actual body sent from restassured

有些话、适合烂在心里 提交于 2020-06-27 08:17:30
问题 I have created a jax-rs rest api and tested it with rest-assured. All tests are green. Now I am trying to create an html/js front end for it. My problem is I do not know how my json objects should look like to be accepted by my rest api. Thanks to restassured/jax-rs I never handled request strings. I fill in objects and I get objects, (un)marshaling (json) is invisible. Is there any way I can see (debug) what strings are created by rest-assured/java and sent over the "wire"? 回答1: If you want

Building a nested JSONObject

大城市里の小女人 提交于 2020-06-17 07:24:06
问题 Below is the code I am using JSONObject requestParams = new JSONObject(); requestParams.put("something", "something value"); requestParams.put("another.child", "child value"); This is how the API needs to be posted { "something":"something value", "another": { "child": "child value" } } I get an error stating that "The another.child field is required." How do I go about posting this via restAssured? The other APIs that do not require posting with nesting work, so I'm assuming that's why it's