java.lang.Object
com.adobe.cq.testing.client.assets.Util

public class Util extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkContentDisposition(org.apache.sling.testing.clients.SlingHttpResponse response, String expected)
    Check if the content disposition header of the response is equal to the given value
    static void
    checkContentLength(org.apache.sling.testing.clients.SlingHttpResponse response, long expected)
    Check if the content length of the response is equal to the given value
    static com.fasterxml.jackson.databind.JsonNode
    getJsonChildNode(com.fasterxml.jackson.databind.JsonNode parent, String... children)
    Retrieve a child node
    static long
    getJsonLongValue(com.fasterxml.jackson.databind.JsonNode parent, String fieldName)
    Retrieve the long value of a field
    static long
    getResourceSize(String resourcePath)
    Retrieve the size of a resource.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getResourceSize

      public static long getResourceSize(String resourcePath) throws org.apache.sling.testing.clients.ClientException
      Retrieve the size of a resource. Could be optimized by checking the URL and if it's a file on disk to get the file size directly. The code tries to be general though, and the assets uploaded should be small.
      Parameters:
      resourcePath - Path to the resource available to the class loader
      Returns:
      Size of the resource
      Throws:
      org.apache.sling.testing.clients.ClientException - Thrown if the size of the resource can't be calculated
    • checkContentLength

      public static void checkContentLength(org.apache.sling.testing.clients.SlingHttpResponse response, long expected) throws org.apache.sling.testing.clients.ClientException
      Check if the content length of the response is equal to the given value
      Parameters:
      response - HTTP response
      expected - Expected content length
      Throws:
      org.apache.sling.testing.clients.ClientException - Thrown if the content-length of the HTTP response doesn't match expected
    • checkContentDisposition

      public static void checkContentDisposition(org.apache.sling.testing.clients.SlingHttpResponse response, String expected) throws org.apache.sling.testing.clients.ClientException
      Check if the content disposition header of the response is equal to the given value
      Parameters:
      response - HTTP response
      expected - Expected content disposition
      Throws:
      org.apache.sling.testing.clients.ClientException - Thrown if the content-disposition of the HTTP response doesn't match expected
    • getJsonChildNode

      public static com.fasterxml.jackson.databind.JsonNode getJsonChildNode(com.fasterxml.jackson.databind.JsonNode parent, String... children)
      Retrieve a child node
      Parameters:
      parent - Parent node
      children - Each child goes down one level, e.g. (root, a, b) will go to root/a/b
      Returns:
      Child node or null if the node doesn't exist
    • getJsonLongValue

      public static long getJsonLongValue(com.fasterxml.jackson.databind.JsonNode parent, String fieldName)
      Retrieve the long value of a field
      Parameters:
      parent - Parent node
      fieldName - Field to retrieve
      Returns:
      Long value in field or 0 if the field doesn't exist