Package com.shaft.api

Class RestActions

java.lang.Object
com.shaft.api.RestActions

public class RestActions extends Object
  • Constructor Details

    • RestActions

      public RestActions(String serviceURI)
  • Method Details

    • buildNewRequest

      public static RequestBuilder buildNewRequest(String serviceURI, String serviceName, RestActions.RequestType requestType)
    • parseBodyToJson

      public static InputStream parseBodyToJson(io.restassured.response.Response response)
    • parseBodyToJson

      public static InputStream parseBodyToJson(Object body)
    • getResponseBody

      public static String getResponseBody(io.restassured.response.Response response)
      Extracts the response body and returns it as a plain string
      Parameters:
      response - the target API response object
      Returns:
      a string value that represents the response body
    • getResponseJSONValue

      public static String getResponseJSONValue(io.restassured.response.Response response, String jsonPath)
      Extracts a string value from the response body by parsing the target jsonpath
      Parameters:
      response - the full response object returned by 'performRequest()' method
      jsonPath - the JSONPath expression that will be evaluated in order to extract the desired value [without the trailing $.], please refer to these urls for examples: https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html http://jsonpath.com/
      Returns:
      a string value that contains the extracted object
    • getResponseJSONValue

      public static String getResponseJSONValue(Object response, String jsonPath)
    • getResponseJSONValueAsList

      public static List<Object> getResponseJSONValueAsList(io.restassured.response.Response response, String jsonPath)
    • getResponseJSONValueFromList

      public static String getResponseJSONValueFromList(io.restassured.response.Response response, String jsonPathToList, String jsonPathToValueNeeded, String jsonPathToValueReference, String valueReference)
      Extracts a string value from an object of a list by reference of another attribute inside the same object
      Parameters:
      response - The target API response object
      jsonPathToList - The JSON path to the list of object inside the full response
      jsonPathToValueNeeded - The JSON path to the attribute value you need to extract inside an object from the list. for example: id
      jsonPathToValueReference - The JSON path that refers to the needed attribute value inside an object from the list. for example: username
      valueReference - The attribute value of the reference JSON path
      Returns:
      A string value from the object of the list
    • getResponseXMLValue

      public static String getResponseXMLValue(io.restassured.response.Response response, String xmlPath)
    • getResponseXMLValue

      public static String getResponseXMLValue(Object response, String xmlPath)
    • getResponseXMLValueAsList

      public static List<Object> getResponseXMLValueAsList(io.restassured.response.Response response, String xmlPath)
    • getResponseStatusCode

      public static int getResponseStatusCode(io.restassured.response.Response response)
    • getResponseTime

      public static long getResponseTime(io.restassured.response.Response response)
    • compareJSON

      public static boolean compareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType)
      Compares the Response object against the content of the referenceJsonFilePath
      Parameters:
      response - the full response object returned by performRequest method.
      referenceJsonFilePath - the full absolute path to the test data file that will be used as a reference for this comparison
      comparisonType - ComparisonType.EQUALS, CONTAINS, MATCHES, EQUALS_STRICT; Note that MATCHES ignores the content ordering inside the JSON
      Returns:
      a boolean value that is TRUE in case the comparison passed, or FALSE in case it failed
    • compareJSON

      public static boolean compareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType, String jsonPathToTargetArray)
      Compares the Response object against the content of the referenceJsonFilePath
      Parameters:
      response - the full response object returned by performRequest method.
      referenceJsonFilePath - the full absolute path to the test data file that will be used as a reference for this comparison
      comparisonType - ComparisonType.EQUALS, CONTAINS; Note that MATCHES ignores the content ordering inside the JSON
      jsonPathToTargetArray - a jsonpath that will be parsed to point to the target JSON Array
      Returns:
      a boolean value that is TRUE in case the comparison passed, or FALSE in case it failed
    • formatXML

      public static String formatXML(String input)
    • sendGraphQlRequest

      public static io.restassured.response.Response sendGraphQlRequest(String base_URI, String query)
      Perform Graphql Request using Query - WITHOUT Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      Returns:
      Graphql Response
    • sendGraphQlRequest

      public static io.restassured.response.Response sendGraphQlRequest(String base_URI, String query, String variables)
      Perform Graphql Request using Query and Variables - WITHOUT Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      variables - graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variables
      Returns:
      Graphql Response
    • sendGraphQlRequest

      public static io.restassured.response.Response sendGraphQlRequest(String base_URI, String query, String variables, String fragment)
      Perform Graphql Request using Query, Variables, and Fragments - WITHOUT Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      variables - graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variables
      fragment - graphql fragment; reusable units let you construct sets of fields, and then include them in queries where you need to. please refer to this url for examples:: https://graphql.org/learn/queries/#fragments
      Returns:
      Graphql Response
    • sendGraphQlRequestWithHeader

      public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String header_key, String header_value)
      Perform Graphql Request using Query - WITH Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      header_key - the name of the header that you want to add. example:: "Authorization"
      header_value - the value that will be put inside the key. example:: "bearer ${token}"
      Returns:
      Graphql Response
    • sendGraphQlRequestWithHeader

      public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String variables, String header_key, String header_value)
      Perform Graphql Request using Query and Variables - WITH Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      variables - graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variables
      header_key - the name of the header that you want to add. example:: "Authorization"
      header_value - the value that will be put inside the key. example:: "bearer ${token}"
      Returns:
      Graphql Response
    • sendGraphQlRequestWithHeader

      public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String variables, String fragment, String header_key, String header_value)
      Perform Graphql Request using Query, Variables, and Fragments - WITH Header.
      Parameters:
      base_URI - The Base URI without "graphql". example:: "https://api.example.com/"
      query - graphql query or mutation.
      variables - graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variables
      fragment - graphql fragment; reusable units let you construct sets of fields, and then include them in queries where you need to. please refer to this url for examples:: https://graphql.org/learn/queries/#fragments
      header_key - the name of the header that you want to add. example:: "Authorization"
      header_value - the value that will be put inside the key. example:: "bearer ${token}"
      Returns:
      Graphql Response
    • buildNewRequest

      public RequestBuilder buildNewRequest(String serviceName, RestActions.RequestType requestType)
    • addHeaderVariable

      public RestActions addHeaderVariable(String key, String value)
      Append a header to the current session to be used in all the following requests. Note: This feature is commonly used for authentication tokens.
      Parameters:
      key - the name of the header that you want to add
      value - the value that will be put inside the key
      Returns:
      self-reference to be used for chaining actions
    • addCookieVariable

      public RestActions addCookieVariable(String key, String value)