Class CommerceClient

java.lang.Object
org.apache.sling.testing.clients.AbstractSlingClient
org.apache.sling.testing.clients.SlingClient
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.http.client.HttpClient

public class CommerceClient extends FormClient
The base client for all commerce-related tests. It provides a core set of commonly used commerce functions such as getting carts and orders, etc.

It extends from FormClient which in turn provides a core set of commonly used website, page and form functionality.
  • Field Details

  • Constructor Details

    • CommerceClient

      public CommerceClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • CommerceClient

      public CommerceClient(URI serverUrl, String user, String password) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
  • Method Details

    • doCommercePost

      public org.apache.sling.testing.clients.SlingHttpResponse doCommercePost(String path, String cookieText, Map<String,String> parameters) throws org.apache.sling.testing.clients.ClientException
      Execute a commerce-oriented POST request. Similar to adminAuthor.doPost(), but allows for the setting of a session cookie.
      Parameters:
      path - request path
      cookieText - cookie to be added
      parameters - list of parameters
      Returns:
      the http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • doCommerceGet

      public org.apache.sling.testing.clients.SlingHttpResponse doCommerceGet(String path, String cookieText) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getCart

      public com.fasterxml.jackson.databind.JsonNode getCart(String homePath) throws org.apache.sling.testing.clients.ClientException
      Return the user's shopping cart. NOTE: carts are no longer stored in the users' homes. See getCookieText() to get the cart.
      Parameters:
      homePath - home path
      Returns:
      the cart as json node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • getOrders

      public com.fasterxml.jackson.databind.JsonNode getOrders() throws org.apache.sling.testing.clients.ClientException
      Retrieves the committed orders.
      Returns:
      the orders as a json node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • getCommerceCookieText

      public String getCommerceCookieText(org.apache.http.HttpResponse resp)
      Return the cookie values concatenated into a single string. The cart and order details will be contained in the result.
      Parameters:
      resp - http response
      Returns:
      the cookie text
    • clearCommerceContext

      public void clearCommerceContext(String homePath) throws org.apache.sling.testing.clients.ClientException
      Clear out the commerce context from the user's home directory.
      Parameters:
      homePath - home path
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • createCatalog

      public org.apache.sling.testing.clients.SlingHttpResponse createCatalog(String source, String dest, String label, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Creates a catalog from a blueprint
      Parameters:
      source - path to the blueprint
      dest - destination path to the catalog
      label - label of the catalog
      title - title of the catalog
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • rolloutSection

      public org.apache.sling.testing.clients.SlingHttpResponse rolloutSection(String source, String dest, boolean force, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Rolls out a section
      Parameters:
      source - path to blueprint
      dest - destination path to the catalog
      force - whether the rollout should be forced
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • createClassification

      public org.apache.sling.testing.clients.SlingHttpResponse createClassification(String managementPath, String parentPath, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Creates a classification
      Parameters:
      managementPath - path to which the request should be sent
      parentPath - path to the parent node
      title - name of the classification
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • removeClassification

      public org.apache.sling.testing.clients.SlingHttpResponse removeClassification(String managementPath, String classificationPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Removes a classification
      Parameters:
      managementPath - path to which the request should be sent
      classificationPath - path to the classification
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addRootCategory

      public org.apache.sling.testing.clients.SlingHttpResponse addRootCategory(String managementPath, String classificationPath, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Adds a root category
      Parameters:
      managementPath - path to which the request should be sent
      classificationPath - path to the classification
      title - name of the category
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addCategory

      public org.apache.sling.testing.clients.SlingHttpResponse addCategory(String managementPath, String parentCategoryPath, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Adds a category
      Parameters:
      managementPath - path to which the request should be sent
      parentCategoryPath - path to the parent category
      title - name of the category
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • removeCategory

      public org.apache.sling.testing.clients.SlingHttpResponse removeCategory(String managementPath, String categoryPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Removes a category
      Parameters:
      managementPath - path to which the request should be sent
      categoryPath - path to the category
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • updateCategory

      public org.apache.sling.testing.clients.SlingHttpResponse updateCategory(String managementPath, String categoryPath, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Update the attributes of a category
      Parameters:
      managementPath - path to which the request should be sent
      categoryPath - path to the category
      title - name of the category
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addAttribute

      public org.apache.sling.testing.clients.SlingHttpResponse addAttribute(String managementPath, String categoryPath, String title, String attrName, String attrUnit, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Adds an attribute
      Parameters:
      managementPath - path to which the request should be sent
      categoryPath - path to the category
      title - attribute title
      attrName - attribute name
      attrUnit - attribute unit
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • createCollection

      public org.apache.sling.testing.clients.SlingHttpResponse createCollection(String managementPath, String parentPath, String title, String type, String search, String searchType, String[] referencePaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Creates a collection
      Parameters:
      managementPath - path to which the request should be sent
      parentPath - path to the parent node
      title - name of the collection
      type - type of the collection
      search - search
      searchType - search type of the collection
      referencePaths - reference paths
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • createCollection

      public org.apache.sling.testing.clients.SlingHttpResponse createCollection(String managementPath, String parentPath, String title, String type, String[] referencePaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Creates a collection
      Parameters:
      managementPath - path to which the request should be sent
      parentPath - path to the parent node
      title - title of the collection
      type - type of the collection
      referencePaths - reference paths
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • updateCollection

      public org.apache.sling.testing.clients.SlingHttpResponse updateCollection(String managementPath, String collectionPath, String title, String[] referencePaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Updates the properties of a collection
      Parameters:
      managementPath - path to which the request should be sent
      collectionPath - path to the collection
      title - name of the collection
      referencePaths - reference paths
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • removeCollection

      public org.apache.sling.testing.clients.SlingHttpResponse removeCollection(String managementPath, String collectionPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Removes a collection
      Parameters:
      managementPath - path to which the request should be sent
      collectionPath - path to the collection
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addReferences

      public org.apache.sling.testing.clients.SlingHttpResponse addReferences(String managementPath, String collectionPath, String[] referencePaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Adds one or multiple references to a collection
      Parameters:
      managementPath - path to which the request should be sent
      collectionPath - path to the collection
      referencePaths - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • removeReferences

      public org.apache.sling.testing.clients.SlingHttpResponse removeReferences(String managementPath, String collectionPath, String[] referencePaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Removes one or multiple references from a collection
      Parameters:
      managementPath - path to which the request should be sent
      collectionPath - path tp the collection
      referencePaths - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • createSmartList

      public org.apache.sling.testing.clients.SlingHttpResponse createSmartList(String managementPath, String title, boolean defaultList, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Creates a smartlist
      Parameters:
      managementPath - path to which the request should be sent
      title - name of the smartlist
      defaultList - should the created list be a default list?
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • manageSmartListsDelete

      public org.apache.sling.testing.clients.SlingHttpResponse manageSmartListsDelete(String managementPath, String title, String[] delete, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Delete one or multiple smartlists
      Parameters:
      managementPath - path to which the request should be sent
      title - name of the smartlist
      delete - one or multiple smartlists to delete
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • manageSmartListsDefault

      public org.apache.sling.testing.clients.SlingHttpResponse manageSmartListsDefault(String managementPath, String title, String[] defaultList, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Manage the default setting of a smartlist
      Parameters:
      managementPath - path to which the request should be sent
      title - name of the smartlist
      defaultList - one or multiple smartlists that should be a default list
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • editSmartList

      public org.apache.sling.testing.clients.SlingHttpResponse editSmartList(String managementPath, String listPath, String redirect, String title, String description, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Edits the properties of a smartlist
      Parameters:
      managementPath - path to which the request should be sent
      listPath - path to the smartlist
      redirect - redirection path
      title - name of the smartlist
      description - description of the smartlist
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addToSmartList

      public org.apache.sling.testing.clients.SlingHttpResponse addToSmartList(String managementPath, String productPath, String listName, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Adds an entry to a smartlist.
      Parameters:
      managementPath - path to which the request should be sent
      productPath - path to the product
      listName - name of the smartlist
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • deleteSmartListEntry

      public org.apache.sling.testing.clients.SlingHttpResponse deleteSmartListEntry(String managementPath, String productPath, String listName, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Deletes an entry form a smartlist
      Parameters:
      managementPath - path to which the request should be sent
      productPath - path to the product
      listName - name of the smartlist
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • modifyQuantitySmartListEntry

      public org.apache.sling.testing.clients.SlingHttpResponse modifyQuantitySmartListEntry(String managementPath, String productPath, String listPath, String redirect, String quantity, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Modifies the quantity of an entry on a smartlist
      Parameters:
      managementPath - path to which the request should be sent
      productPath - path to the product
      listPath - path to the smartlist
      redirect - redirection path
      quantity - new quantity
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • addToCart

      public org.apache.sling.testing.clients.SlingHttpResponse addToCart(String managementPath, String productPath, String listPath, boolean delete, String redirect, List<org.apache.http.Header> headers, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Add a product to the cart
      Parameters:
      managementPath - path to which the request should be sent
      productPath - path to the product
      listPath - path to the smartlist
      delete - should the product be deleted from its smartlist?
      redirect - redirection path
      headers - list of HTTP headers
      expectedStatus - expected HTTP response status code
      Returns:
      the sling http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request could not be executed
    • configureProductComponent

      public org.apache.sling.testing.clients.SlingHttpResponse configureProductComponent(String productPagePath, String productPath) throws org.apache.sling.testing.clients.ClientException
      Update the product component on a page to point to the given product and generate the product hierarchy.
      Parameters:
      productPagePath - Path to product page
      productPath - Path to the product
      Returns:
      the http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addProduct

      public org.apache.sling.testing.clients.SlingHttpResponse addProduct(String parent, String title, double price) throws org.apache.sling.testing.clients.ClientException
      Create a new product.
      Parameters:
      parent - Parent folder
      title - Name
      price - Price
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addProduct

      public org.apache.sling.testing.clients.SlingHttpResponse addProduct(String parent, String title, double price, String description, String sku, String color, String size) throws org.apache.sling.testing.clients.ClientException
      Create a new product.
      Parameters:
      parent - Parent folder
      title - Name
      price - Price
      description - Description
      sku - SKU identifier
      color - Color
      size - Size
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addTagToProduct

      public org.apache.sling.testing.clients.SlingHttpResponse addTagToProduct(String tagPath, String productPath) throws org.apache.sling.testing.clients.ClientException
      Assign a tag to a product.
      Parameters:
      tagPath - Path to the tag.
      productPath - Path to the product.
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addProductAsset

      public org.apache.sling.testing.clients.SlingHttpResponse addProductAsset(String product, String asset) throws org.apache.sling.testing.clients.ClientException
      Add an asset to a product.
      Parameters:
      product - Path to product
      asset - Path to asset
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • updateProductAsset

      public org.apache.sling.testing.clients.SlingHttpResponse updateProductAsset(String productAssetPath, String newAsset) throws org.apache.sling.testing.clients.ClientException
      Update an existing asset of a product.
      Parameters:
      productAssetPath - Path to the product's asset (e.g. ProductPath + "/assets/asset0")
      newAsset - Path to new asset
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • deleteProductAsset

      public org.apache.sling.testing.clients.SlingHttpResponse deleteProductAsset(String productAssetPath) throws org.apache.sling.testing.clients.ClientException
      Deletes an asset from a product.
      Parameters:
      productAssetPath - Path to the product's asset (e.g. ProductPath + "/assets/asset0")
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addProductVariant

      public org.apache.sling.testing.clients.SlingHttpResponse addProductVariant(String parentProduct, String title, double price, String description, String sku, String color, String size) throws org.apache.sling.testing.clients.ClientException
      Add a product variant.
      Parameters:
      parentProduct - Path of parent product
      title - Title
      price - Price
      description - Description
      sku - SKU identifier
      color - Color
      size - Size
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • createBlueprint

      public org.apache.sling.testing.clients.SlingHttpResponse createBlueprint(String title, String description, String parentPath, String catalogTemplate, String sectionTemplate, String productTemplate, boolean proxyPages) throws org.apache.sling.testing.clients.ClientException
      Create a new blueprint.
      Parameters:
      title - Title
      description - Description
      parentPath - Path under which the blueprint should be created
      catalogTemplate - Path to catalog page template
      sectionTemplate - Path to section page template
      productTemplate - Path to product page template
      proxyPages - Whether proxy pages should be generated
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • createBlueprintSection

      public org.apache.sling.testing.clients.SlingHttpResponse createBlueprintSection(String name, String description, String parentPath, boolean proxyPages) throws org.apache.sling.testing.clients.ClientException
      Create a new blueprint section.
      Parameters:
      name - Name
      description - Description
      parentPath - Path of the parent blueprint or blueprint section
      proxyPages - Whether proxy pages should be generated
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • isProductPage

      public boolean isProductPage(String productPage) throws org.apache.sling.testing.clients.ClientException
      Check if a product page is a regular product page based on its resource type.
      Parameters:
      productPage - Path to product page
      Returns:
      true if the page is a product page
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • isProxyPage

      public boolean isProxyPage(String productPage) throws org.apache.sling.testing.clients.ClientException
      Check if a product page is a proxy product page based on its resource type.
      Parameters:
      productPage - Path to product page
      Returns:
      true if the page is a proxy
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addTagFilter

      public org.apache.sling.testing.clients.SlingHttpResponse addTagFilter(String blueprintPath, String productFolder, String tag) throws org.apache.sling.testing.clients.ClientException
      Set the product filter of a blueprint or blueprint section using a product base path and a tag.
      Parameters:
      blueprintPath - Blueprint or blueprint section path
      productFolder - Product Folder
      tag - Tag
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addSQL2QueryFilter

      public org.apache.sling.testing.clients.SlingHttpResponse addSQL2QueryFilter(String blueprintPath, String query) throws org.apache.sling.testing.clients.ClientException
      Set the product filter of a blueprint or blueprint section using a JCR-SQL2 query.
      Parameters:
      blueprintPath - Blueprint or blueprint section path
      query - JCQ-SQL2 query
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • addXPathQueryFilter

      public org.apache.sling.testing.clients.SlingHttpResponse addXPathQueryFilter(String blueprintPath, String query) throws org.apache.sling.testing.clients.ClientException
      Set the product filter of a blueprint or blueprint section using an XPath query.
      Parameters:
      blueprintPath - Blueprint or blueprint section path
      query - XPath query
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • clearShoppingCart

      public org.apache.sling.testing.clients.SlingHttpResponse clearShoppingCart(String page) throws org.apache.sling.testing.clients.ClientException
      Clears the shopping cart using the ContextHub. Works only on the client side.
      Parameters:
      page - Content page that can be used to call the ContextHub
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • setCommerceProvider

      public org.apache.sling.testing.clients.SlingHttpResponse setCommerceProvider(String url, String commerceProvider) throws org.apache.sling.testing.clients.ClientException
      Adds or updates the cq:commerceProvider property to a JCR node at a given url.
      Parameters:
      url - URL of the node
      commerceProvider - commerce provider identifier
      Returns:
      SlingHttpResponse object
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails