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
All Methods Static Methods Concrete Methods 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 Detail
-
VERIFY_JSON_PART_INDICATOR
public static final String VERIFY_JSON_PART_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_JSON_PART_INDICATOR_UNDERSCORE
public static final String VERIFY_JSON_PART_INDICATOR_UNDERSCORE
- See Also:
- Constant Field Values
-
VERIFY_RESPONSE_BODY_INDICATOR
public static final String VERIFY_RESPONSE_BODY_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_RESPONSE_NO_EMPTY
public static final String VERIFY_RESPONSE_NO_EMPTY
- See Also:
- Constant Field Values
-
VERIFY_HEADER_PART_INDICATOR
public static final String VERIFY_HEADER_PART_INDICATOR
- See Also:
- Constant Field Values
-
VERIFY_TOPIC_PART_INDICATOR
public static final String VERIFY_TOPIC_PART_INDICATOR
- See Also:
- Constant Field Values
-
EXPECTED_MESSAGE_COUNT
public static final String EXPECTED_MESSAGE_COUNT
- See Also:
- Constant Field Values
-
IS_IGNORE_XML_NAMESPACE
public static final String IS_IGNORE_XML_NAMESPACE
- See Also:
- Constant Field Values
-
TEST_DATA_TEMPLATE_DATA_PATH
public static final String TEST_DATA_TEMPLATE_DATA_PATH
- See Also:
- Constant Field Values
-
VALIDATION_OR_CONDITION_ECODE
public static final String VALIDATION_OR_CONDITION_ECODE
- See Also:
- Constant Field Values
-
VALIDATION_OR_CONDITION
public static final String VALIDATION_OR_CONDITION
- See Also:
- Constant Field Values
-
VALIDATION_AND_CONDITION
public static final String VALIDATION_AND_CONDITION
- See Also:
- Constant Field Values
-
REQUEST_BODY_UPDATE_INDICATOR
public static final String REQUEST_BODY_UPDATE_INDICATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public static boolean isObjectEmpty(Object value)
-
getIncrementalValue
public static int getIncrementalValue(String parameter)
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
public static String getTimeSubstring(String parameter, String finalTime)
get substring of time based on time string length format _TIME_STRING_17-72h. 17 is the length- Parameters:
parameter-maxLength-finalTime-- Returns:
-
getValidationMap
public static List<KeyValue> getValidationMap(String expected)
gets the map of the validation requirements split by ";"- Parameters:
expected-- Returns:
-
getValidationMap
public static List<KeyValue> getValidationMap(String expected, String separator)
gets the map of the validation requirements split by ";"- Parameters:
expected-- Returns:
-
getServiceObjectTemplateString
public static String getServiceObjectTemplateString(ServiceObject serviceObject)
returns service object template file as string Template file name is from Template column in csv- Parameters:
apiObject-- Returns:
- Throws:
IOException
-
validateCommand
public static String validateCommand(String command, String responseString, String expectedString)
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
public static List<String> getResponseArray(String array)
converts string separated by "," to array[] trims each value and removes quotes or array brackets- Parameters:
array-- Returns:
-
getResponseArrayLength
public static int getResponseArrayLength(List<String> actualArray, String responseString)
-
compareNumbers
public static boolean compareNumbers(String value1, String value2, String comparator)
compare string integer values based on comparator value- Parameters:
value1-value2-comparator-- Returns:
-
compareNumbers
public static boolean compareNumbers(double value1, double value2, String comparator)compare integer values- Parameters:
value1-value2-comparator-- Returns:
-
listToString
public static String listToString(List<String> values)
converts list to string separated by ","- Parameters:
values-- Returns:
-
objectToString
public static String objectToString(Object values)
convert object to string object can be array- Parameters:
values-- Returns:
-
splitToKeyPositionValue
public static List<String> splitToKeyPositionValue(String keyvalue, String regex, int limit)
split based on key position value- Parameters:
keyvalue-regex-limit-- Returns:
-
isEmpty
public static boolean isEmpty(String value)
-
getRequestBodyIncludingTemplate
public static String getRequestBodyIncludingTemplate(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. "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
public static void loadDataFile(ServiceObject serviceObject)
loads template data info based on value set on request body format: DataFile:file:dataId- Parameters:
serviceObject-
-
saveDataToConfig
public static void saveDataToConfig(String source)
stores value in config format: value:<$key> separated by colon ';'- Parameters:
source-
-
convertFileToString
public static String convertFileToString(Path templatePath)
get file content as text replaces parameters using syntax <@variable> from value in config- Parameters:
templatePath-- Returns:
-
removeSectionFromExpectedResponse
public static String removeSectionFromExpectedResponse(String section, String expectedResponse)
remove section from expected response separated by && the section will start with the identifier. eg. _VERIFY_RESPONSE_BODY_- Parameters:
section-expectedResponse-- Returns:
-
getSectionFromExpectedResponse
public static String getSectionFromExpectedResponse(String section, String expectedResponse)
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
public static String removeAndOrIndicator(String value)
removes && or || identifiers at the beginning of logic string used for getting the actual expression to evaluate format: eg. && expression- Parameters:
value-- Returns:
-
evaluateLogic
public static boolean evaluateLogic(String logicString)
evaluates string logic. eg ((true) && (false || false || true)) returns true- Parameters:
logicString-- Returns:
-
removeLogicIdentifiers
public static String removeLogicIdentifiers(String criterion)
remove logic values if criteria starts with "(", &&, "||" or end with ")"- Parameters:
criterion-- Returns:
-
getValidationPattern
public static String getValidationPattern(String criterion)
converts response validation to proper logic pattern- Parameters:
criterion-- Returns:
-
validateEmptyResponse
public static List<String> validateEmptyResponse(List<String> responseValues, String expected)
validates if empty response is expected and received- Parameters:
responseValues-expected-- Returns:
-
isEmptyResponseExpected
public static boolean isEmptyResponseExpected(String expected)
returns true if empty response is expected. denoted by isEmpty- Parameters:
expected-- Returns:
-
validateExpectedResponse
public static List<String> validateExpectedResponse(String criterion, List<String> responseString)
validates expected requirement against response strings- Parameters:
criterion-responseString-- Returns:
-
isValidExpectation
public static boolean isValidExpectation(String expectedValue)
validates if expected value is valid: json, xml or starts with valid indicator- Parameters:
expectedValue-- Returns:
-
removeEmptyElements
public static List<String> removeEmptyElements(List<String> list)
removes empty elements from list- Parameters:
list-- Returns:
-
-