Package core.apiCore.helpers
Class DataHelper
java.lang.Object
core.apiCore.helpers.DataHelper
public class DataHelper extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataHelper.JSON_COMMAND -
Field Summary
Fields Modifier and Type Field Description static StringEXPECTED_MESSAGE_COUNTstatic StringIS_IGNORE_XML_NAMESPACEstatic StringREQUEST_BODY_UPDATE_INDICATORstatic StringTEST_DATA_TEMPLATE_DATA_PATHstatic StringVALIDATION_AND_CONDITIONstatic StringVALIDATION_OR_CONDITIONstatic StringVALIDATION_OR_CONDITION_ECODEstatic StringVERIFY_HEADER_PART_INDICATORstatic StringVERIFY_JSON_PART_INDICATORstatic StringVERIFY_JSON_PART_INDICATOR_UNDERSCOREstatic StringVERIFY_RESPONSE_BODY_INDICATORstatic StringVERIFY_RESPONSE_NO_EMPTYstatic StringVERIFY_TOPIC_PART_INDICATOR -
Constructor Summary
Constructors Constructor Description DataHelper() -
Method Summary
Modifier and Type Method Description static booleancompareNumbers(double value1, double value2, String comparator)compare integer valuesstatic booleancompareNumbers(String value1, String value2, String comparator)compare string integer values based on comparator valuestatic StringconvertFileToString(Path templatePath)get file content as text replaces parameters using syntax <@variable> from value in configstatic booleanevaluateLogic(String logicString)evaluates string logic.static FilegetFile(String filename)static intgetIncrementalValue(String parameter)incremental keyword value setter starting value + current run count by default: starting value = 1 eg.static StringgetRequestBodyIncludingTemplate(ServiceObject serviceObject)get request body from template file: json, xml, other json template: - if request body is set, replace value in template with format: - request body: json path:position:value or json path:vlaue - eg.static List<String>getResponseArray(String array)converts string separated by "," to array[] trims each value and removes quotes or array bracketsstatic intgetResponseArrayLength(List<String> actualArray, String responseString)static StringgetSectionFromExpectedResponse(String section, String expectedResponse)get section from expected response separated by && the section will start with the identifier.static StringgetServiceObjectTemplateString(ServiceObject serviceObject)returns service object template file as string Template file name is from Template column in csvstatic StringgetTemplateFileLocation(String file)static PathgetTemplateFilePath(String file)static InstantgetTimeInstance(String timeString)static StringgetTimeSubstring(String parameter, String finalTime)get substring of time based on time string length format _TIME_STRING_17-72h.static List<KeyValue>getValidationMap(String expected)gets the map of the validation requirements split by ";"static List<KeyValue>getValidationMap(String expected, String separator)gets the map of the validation requirements split by ";"static StringgetValidationPattern(String criterion)converts response validation to proper logic patternstatic booleanisEmpty(String value)static booleanisEmptyResponseExpected(String expected)returns true if empty response is expected.static booleanisGreaterThan(String value1, String value2)static booleanisLessThan(String value1, String value2)static Set<String>isListContain(String actual, List<String> expectedValues)verifies actual string contains list of expected valuesstatic booleanisObjectEmpty(Object value)static booleanisValidExpectation(String expectedValue)validates if expected value is valid: json, xml or starts with valid indicatorstatic StringlistToString(List<String> values)converts list to string separated by ","static voidloadDataFile(ServiceObject serviceObject)loads template data info based on value set on request body format: DataFile:file:dataIdstatic voidlogJsonResponse(List<String> responseValues)static StringobjectToString(Object values)convert object to string object can be arraystatic StringremoveAndOrIndicator(String value)removes && or || identifiers at the beginning of logic string used for getting the actual expression to evaluate format: eg.static String[]removeEmptyElements(String[] array)static List<String>removeEmptyElements(List<String> list)removes empty elements from liststatic StringremoveLogicIdentifiers(String criterion)remove logic values if criteria starts with "(", &&, "||" or end with ")"static StringremoveSectionFromExpectedResponse(String section, String expectedResponse)remove section from expected response separated by && the section will start with the identifier.static StringreplaceParameters(String source)static StringreplaceParameters(String source, String tagPattern, String openingTag, String closingTag)replaces placeholder values with values from config properties replaces only string valuesstatic voidsaveDataToConfig(String source)stores value in config format: value:<$key> separated by colon ';'static List<String>splitRight(String value, String regex, int limit)static List<String>splitToKeyPositionValue(String keyvalue, String regex, int limit)split based on key position valuestatic StringvalidateCommand(String command, String responseString, String expectedString)validates response against expected valuesstatic StringvalidateCommand(String command, String responseString, String expectedString, String position, boolean skipValidation)validates response against expected values if skipValidation = false -> response variable contains errorstatic List<String>validateEmptyResponse(List<String> responseValues, String expected)validates if empty response is expected and receivedstatic StringvalidateExpectedCommand(String command, String responseString, String expectedString, String position)validates response against expected valuesstatic List<String>validateExpectedResponse(String criterion, List<String> responseString)validates expected requirement against response stringsstatic List<String>validateExpectedValues(List<String> responseValues, String expectedResponse)validates expected values (xml, json, text, or jsonpath keywords
-
Field Details
-
VERIFY_JSON_PART_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_JSON_PART_INDICATOR_UNDERSCORE
- See Also:
- Constant Field Values
-
VERIFY_RESPONSE_BODY_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_RESPONSE_NO_EMPTY
- See Also:
- Constant Field Values
-
VERIFY_HEADER_PART_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_TOPIC_PART_INDICATOR
- See Also:
- Constant Field Values
-
EXPECTED_MESSAGE_COUNT
- See Also:
- Constant Field Values
-
IS_IGNORE_XML_NAMESPACE
- See Also:
- Constant Field Values
-
TEST_DATA_TEMPLATE_DATA_PATH
- See Also:
- Constant Field Values
-
VALIDATION_OR_CONDITION_ECODE
- See Also:
- Constant Field Values
-
VALIDATION_OR_CONDITION
- See Also:
- Constant Field Values
-
VALIDATION_AND_CONDITION
- See Also:
- Constant Field Values
-
REQUEST_BODY_UPDATE_INDICATOR
- See Also:
- Constant Field Values
-
-
Constructor Details
-
DataHelper
public DataHelper()
-
-
Method Details
-
replaceParameters
-
replaceParameters
public static String replaceParameters(String source, String tagPattern, String openingTag, String closingTag)replaces placeholder values with values from config properties replaces only string values- Parameters:
source-- Returns:
-
isObjectEmpty
-
getIncrementalValue
incremental keyword value setter starting value + current run count by default: starting value = 1 eg. <@_INCREMENT_FROM_3> current test count is appended to test case id. eg. validateId_run_1- Parameters:
parameter-
-
getTimeSubstring
get substring of time based on time string length format _TIME_STRING_17-72h. 17 is the length- Parameters:
parameter-maxLength-finalTime-- Returns:
-
getTimeInstance
-
getValidationMap
gets the map of the validation requirements split by ";"- Parameters:
expected-- Returns:
-
getValidationMap
gets the map of the validation requirements split by ";"- Parameters:
expected-- Returns:
-
getTemplateFileLocation
-
getTemplateFilePath
-
getFile
-
getServiceObjectTemplateString
returns service object template file as string Template file name is from Template column in csv- Parameters:
apiObject-- Returns:
- Throws:
IOException
-
validateCommand
validates response against expected values- Parameters:
command-responseString-expectedString-- Returns:
-
validateCommand
public static String validateCommand(String command, String responseString, String expectedString, String position, boolean skipValidation)validates response against expected values if skipValidation = false -> response variable contains error- Parameters:
command-responseString-expectedString-position-- Returns:
-
validateExpectedCommand
public static String validateExpectedCommand(String command, String responseString, String expectedString, String position)validates response against expected values- Parameters:
command-responseString-expectedString-position-
-
getResponseArray
converts string separated by "," to array[] trims each value and removes quotes or array brackets- Parameters:
array-- Returns:
-
getResponseArrayLength
-
isGreaterThan
-
isLessThan
-
compareNumbers
compare string integer values based on comparator value- Parameters:
value1-value2-comparator-- Returns:
-
compareNumbers
compare integer values- Parameters:
value1-value2-comparator-- Returns:
-
listToString
converts list to string separated by ","- Parameters:
values-- Returns:
-
objectToString
convert object to string object can be array- Parameters:
values-- Returns:
-
splitToKeyPositionValue
split based on key position value- Parameters:
keyvalue-regex-limit-- Returns:
-
splitRight
-
isEmpty
-
getRequestBodyIncludingTemplate
get request body from template file: json, xml, other json template: - if request body is set, replace value in template with format: - request body: json path:position:value or json path:vlaue - eg. "features.feature.name:1:value_<@_TIME_19>" xml template: - if request body is set, replace value in template with format: - request body: tag:position:value or tag:value - eg. "soi:EquipmentID:1:equip_<@_TIME_17>" other file type: - return as string if no template set: - return request body- Parameters:
serviceObject-- Returns:
-
loadDataFile
loads template data info based on value set on request body format: DataFile:file:dataId- Parameters:
serviceObject-
-
saveDataToConfig
stores value in config format: value:<$key> separated by colon ';'- Parameters:
source-
-
convertFileToString
get file content as text replaces parameters using syntax <@variable> from value in config- Parameters:
templatePath-- Returns:
-
removeSectionFromExpectedResponse
remove section from expected response separated by && the section will start with the identifier. eg. _VERIFY_RESPONSE_BODY_- Parameters:
section-expectedResponse-- Returns:
-
getSectionFromExpectedResponse
get section from expected response separated by && the section will start with the identifier. eg. _VERIFY_RESPONSE_BODY_- Parameters:
section-expectedResponse-- Returns:
-
validateExpectedValues
public static List<String> validateExpectedValues(List<String> responseValues, String expectedResponse)validates expected values (xml, json, text, or jsonpath keywords- Parameters:
responseValues-expectedResponse-- Returns:
-
removeAndOrIndicator
removes && or || identifiers at the beginning of logic string used for getting the actual expression to evaluate format: eg. && expression- Parameters:
value-- Returns:
-
evaluateLogic
evaluates string logic. eg ((true) && (false || false || true)) returns true- Parameters:
logicString-- Returns:
-
removeLogicIdentifiers
remove logic values if criteria starts with "(", &&, "||" or end with ")"- Parameters:
criterion-- Returns:
-
getValidationPattern
converts response validation to proper logic pattern- Parameters:
criterion-- Returns:
-
logJsonResponse
-
validateEmptyResponse
validates if empty response is expected and received- Parameters:
responseValues-expected-- Returns:
-
isEmptyResponseExpected
returns true if empty response is expected. denoted by isEmpty- Parameters:
expected-- Returns:
-
validateExpectedResponse
validates expected requirement against response strings- Parameters:
criterion-responseString-- Returns:
-
isValidExpectation
validates if expected value is valid: json, xml or starts with valid indicator- Parameters:
expectedValue-- Returns:
-
removeEmptyElements
removes empty elements from list- Parameters:
list-- Returns:
-
removeEmptyElements
-
isListContain
verifies actual string contains list of expected values- Parameters:
actual-expectedValues-- Returns:
-