Class DataHelper


  • public class DataHelper
    extends Object
    • Constructor Detail

      • DataHelper

        public DataHelper()
    • Method Detail

      • replaceParameters

        public static String replaceParameters​(String source)
      • 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:
      • getTimeInstance

        public static Instant getTimeInstance​(String timeString)
      • 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:
      • getTemplateFileLocation

        public static String getTemplateFileLocation​(String file)
      • getTemplateFilePath

        public static Path getTemplateFilePath​(String file)
      • getFile

        public static File getFile​(String filename)
      • 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)
      • isGreaterThan

        public static boolean isGreaterThan​(String value1,
                                            String value2)
      • isLessThan

        public static boolean isLessThan​(String value1,
                                         String value2)
      • 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:
      • logJsonResponse

        public static void logJsonResponse​(List<String> responseValues)
      • 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:
      • removeEmptyElements

        public static String[] removeEmptyElements​(String[] array)
      • isListContain

        public static Set<String> isListContain​(String actual,
                                                List<String> expectedValues)
        verifies actual string contains list of expected values
        Parameters:
        actual -
        expectedValues -
        Returns: