public class JsonHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
failOnEscapeChars |
| Constructor and Description |
|---|
JsonHelper() |
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
arrayRemoveAllEmptyString(List<String> list) |
static void |
configMapJsonKeyValues(io.restassured.response.Response response,
KeyValue keyword)
map key value to config eg.features.features.id:1:<$id>
|
static void |
configMapKeyValues(io.restassured.response.Response response,
KeyValue keyword)
map key value to config eg.features.features.id:1:<$id>
|
static boolean |
containsEscapeChar(String value)
\t Insert a tab in the text at this point.
|
static String |
convertJsonFileToString(Path templatePath) |
static Object |
convertToObject(String value,
boolean isPathValueString)
convert string to object converts string to appropriate object type json
supports string, number, boolean, null, object, array
|
static org.json.JSONArray |
getJsonArray(String jsonString)
return true if json string is a json array
|
static org.json.JSONObject |
getJsonObject(String jsonString)
return true if json string is a json o
|
static Object |
getJsonPathValue(String json,
String path,
boolean isAlwaysReturnList)
gets json value as list if applicable, or string if single item converts to
string separated by "," https://github.com/json-path/JsonPath
|
static Object |
getJsonPathValue(String json,
String path,
boolean isAlwaysReturnList,
boolean checkError)
gets json value as list if applicable, or string if single item converts to
string separated by "," https://github.com/json-path/JsonPath
|
static String |
getJsonValue(io.restassured.response.Response response,
String path)
gets json value as list if applicable, or string if single item converts to
string separated by ","
|
static String |
getJsonValue(String json,
String path)
gets json value as list if applicable, or string if single item converts to
string separated by "," https://github.com/json-path/JsonPath
|
static String |
getJsonValue(String json,
String path,
boolean isAlwaysReturnList)
gets json value as list if applicable, or string if single item converts to
string separated by "," https://github.com/json-path/JsonPath
|
static String |
getJsonValueFromXml(String xml,
String path)
get json path value from xml string
|
static String |
getRequestBodyFromJsonTemplate(ServiceObject serviceObject)
if request body is empty, return json template string if request body
contains @ variable tag, replace tag with value format for request body: json
path:position:value or json path:vlaue eg.
|
static String |
getResponseValue(io.restassured.response.Response response) |
static boolean |
isJsonFile(String filename)
return true if file is json file
|
static boolean |
isJsonPathValueExist(String jsonString,
String jsonPath) |
static boolean |
isJsonPathValueString(String json,
String path) |
static boolean |
isJSONValid(String value,
boolean isFailOnError)
validates json string
|
static boolean |
isValidJsonObject(Object jsonObject)
checks if json string is a structured json body with key value pairs, or just
array list.
|
static String |
removeResponseIndicator(String expected)
remove response indicators
|
static String |
replaceJsonPathValue(String jsonString,
String path,
String value)
replace json string value based on json path eg.
|
static void |
saveOutboundJsonParameters(io.restassured.response.Response response,
String outputParam)
replaces output parameter with response values eg.
|
static String |
updateJsonFromRequestBody(ServiceObject service) |
static String |
updateJsonFromRequestBody(String requestbody,
String jsonString) |
static String |
validateByJsonBody(String expectedJson,
String response)
validates expected json string against json body from response
|
static String |
validateByJsonBody(String expectedJson,
String response,
boolean hasToBeJsonBody)
validates expected json string against json body from response
|
static List<String> |
validateByKeywords(String expectedJson,
io.restassured.response.Response response)
validates json response against keywords
|
static List<String> |
validateByKeywords(String expectedJson,
String responseString)
validates json response against keywords
|
static List<String> |
validateJsonKeywords(List<KeyValue> keywords,
String responseString)
validates the json maps against the keyword requirements examples:
"person.roles.name": hasItems("admin"), "person.lastName":
equalTo("Administrator"), "person.lastName": isNotEmpty, "person.roles.name":
contains("admin"), "person.roles.name": containsInAnyOrder(admin),
"person.roles": nodeSizeGreaterThan(0), "person.sites.": nodeSizeExact(0)
"person.roles.name": sequence("admin"),
|
static String |
validateResponseBody(String expected,
io.restassured.response.Response response)
validates response body this is validating the response body as text
|
static String |
validateResponseBody(String expected,
String responseString)
validates response body this is validating the response body as text
|
static String |
XMLToJson(String xml)
convert xml string to json string
|
public static String failOnEscapeChars
public static void saveOutboundJsonParameters(io.restassured.response.Response response,
String outputParam)
response - outputParam - public static void configMapJsonKeyValues(io.restassured.response.Response response,
KeyValue keyword)
response - keyValue - public static void configMapKeyValues(io.restassured.response.Response response,
KeyValue keyword)
response - keyValue - public static String getJsonValue(io.restassured.response.Response response, String path)
response - path - public static String getJsonValue(String json, String path)
path - https://github.com/json-path/JsonPath
for testing json path values: http://jsonpath.herokuapp.com/public static String getJsonValue(String json, String path, boolean isAlwaysReturnList)
path - https://github.com/json-path/JsonPath
for testing json path values: http://jsonpath.herokuapp.com/public static Object getJsonPathValue(String json, String path, boolean isAlwaysReturnList)
path - https://github.com/json-path/JsonPath
for testing json path values: http://jsonpath.herokuapp.com/public static Object getJsonPathValue(String json, String path, boolean isAlwaysReturnList, boolean checkError)
path - https://github.com/json-path/JsonPath
for testing json path values: http://jsonpath.herokuapp.com/public static boolean containsEscapeChar(String value)
value - public static String getJsonValueFromXml(String xml, String path)
xml - path - public static String XMLToJson(String xml)
xml - stringpublic static String getResponseValue(io.restassured.response.Response response)
public static List<String> validateJsonKeywords(List<KeyValue> keywords, String responseString)
jsonMap - response - public static boolean isJSONValid(String value, boolean isFailOnError)
value - public static String validateByJsonBody(String expectedJson, String response)
expectedJson - actualJson - public static String validateByJsonBody(String expectedJson, String response, boolean hasToBeJsonBody)
expectedJson - actualJson - public static List<String> validateByKeywords(String expectedJson, io.restassured.response.Response response)
expectedJson - response - public static List<String> validateByKeywords(String expectedJson, String responseString)
expectedJson - response - public static String validateResponseBody(String expected, io.restassured.response.Response response)
expected - response - public static String validateResponseBody(String expected, String responseString)
expected - response - public static String removeResponseIndicator(String expected)
expected - public static String getRequestBodyFromJsonTemplate(ServiceObject serviceObject)
serviceObject - public static boolean isJsonFile(String filename)
filename - public static String updateJsonFromRequestBody(ServiceObject service)
public static String updateJsonFromRequestBody(String requestbody, String jsonString)
public static String replaceJsonPathValue(String jsonString, String path, String value)
jsonString - path - value - public static Object convertToObject(String value, boolean isPathValueString)
value - isPathValueString - the path value to replace. if string, then
replacement type will be stringpublic static org.json.JSONArray getJsonArray(String jsonString)
jsonString - public static org.json.JSONObject getJsonObject(String jsonString)
jsonString - public static boolean isValidJsonObject(Object jsonObject)
jsonString - Copyright © 2022. All rights reserved.