Package core.apiCore.helpers
Class DataHelper
java.lang.Object
core.apiCore.helpers.DataHelper
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 invalid input: '<'@variable> from value in configstatic booleanevaluateLogic(String logicString) evaluates string logic.static Filestatic 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.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 invalid input: '&'invalid input: '&' 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 Stringstatic 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.getValidationMap(String expected) gets the map of the validation requirements split by ";"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 booleanstatic booleanisEmptyResponseExpected(String expected) returns true if empty response is expected.static booleanisGreaterThan(String value1, String value2) static booleanisLessThan(String value1, String value2) 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 invalid input: '&'invalid input: '&' or || identifiers at the beginning of logic string used for getting the actual expression to evaluate format: eg.static String[]removeEmptyElements(String[] array) removeEmptyElements(List<String> list) removes empty elements from liststatic StringremoveLogicIdentifiers(String criterion) remove logic values if criteria starts with "(", invalid input: '&'invalid input: '&', "||" or end with ")"static StringremoveSectionFromExpectedResponse(String section, String expectedResponse) remove section from expected response separated by invalid input: '&'invalid input: '&' 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:invalid input: '<'$key> separated by colon ';'splitRight(String value, String regex, int limit) 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 errorvalidateEmptyResponse(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 valuesvalidateExpectedResponse(String criterion, List<String> responseString) validates expected requirement against response stringsvalidateExpectedValues(List<String> responseValues, String expectedResponse) validates expected values (xml, json, text, or jsonpath keywords
-
Field Details
-
VERIFY_JSON_PART_INDICATOR
- See Also:
-
VERIFY_JSON_PART_INDICATOR_UNDERSCORE
- See Also:
-
VERIFY_RESPONSE_BODY_INDICATOR
- See Also:
-
VERIFY_RESPONSE_NO_EMPTY
- See Also:
-
VERIFY_HEADER_PART_INDICATOR
- See Also:
-
VERIFY_TOPIC_PART_INDICATOR
- See Also:
-
EXPECTED_MESSAGE_COUNT
- See Also:
-
IS_IGNORE_XML_NAMESPACE
- See Also:
-
TEST_DATA_TEMPLATE_DATA_PATH
- See Also:
-
VALIDATION_OR_CONDITION_ECODE
- See Also:
-
VALIDATION_OR_CONDITION
- See Also:
-
VALIDATION_AND_CONDITION
- See Also:
-
REQUEST_BODY_UPDATE_INDICATOR
- See Also:
-
-
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. invalid input: '<'@_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-finalTime-maxLength-- 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_invalid input: '<'@_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_invalid input: '<'@_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:invalid input: '<'$key> separated by colon ';'- Parameters:
source-
-
convertFileToString
get file content as text replaces parameters using syntax invalid input: '<'@variable> from value in config- Parameters:
templatePath-- Returns:
-
removeSectionFromExpectedResponse
remove section from expected response separated by invalid input: '&'invalid input: '&' the section will start with the identifier. eg. _VERIFY_RESPONSE_BODY_- Parameters:
section-expectedResponse-- Returns:
-
getSectionFromExpectedResponse
get section from expected response separated by invalid input: '&'invalid input: '&' 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 invalid input: '&'invalid input: '&' or || identifiers at the beginning of logic string used for getting the actual expression to evaluate format: eg. invalid input: '&'invalid input: '&' expression- Parameters:
value-- Returns:
-
evaluateLogic
evaluates string logic. eg ((true) invalid input: '&'invalid input: '&' (false || false || true)) returns true- Parameters:
logicString-- Returns:
-
removeLogicIdentifiers
remove logic values if criteria starts with "(", invalid input: '&'invalid input: '&', "||" 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:
-