Class WorkflowClient

java.lang.Object
org.apache.sling.testing.clients.AbstractSlingClient
org.apache.sling.testing.clients.SlingClient
com.adobe.cq.testing.client.CQClient
com.adobe.cq.testing.client.WorkflowClient
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.http.client.HttpClient
Direct Known Subclasses:
CQWorkflowClient

public class WorkflowClient extends CQClient
Implements the Workflow REST API calls
ModelID = handle to the model Node
  • Field Details

    • MANAGE_WF_INSTANCES_PATH

      public static final String MANAGE_WF_INSTANCES_PATH
      Request Path to manage workflow instances
      See Also:
    • MANAGE_WF_MODELS_PATH

      public static final String MANAGE_WF_MODELS_PATH
      Request Path to manage workflow models
      See Also:
    • MANAGE_WF_INBOX_PATH

      public static final String MANAGE_WF_INBOX_PATH
      Request Path to manage users workflow inbox
      See Also:
    • MANAGE_WF_ENGINE_PATH

      public static final String MANAGE_WF_ENGINE_PATH
      Request Path to manage workflow engine
      See Also:
    • MODEL_LIST_TYPE_ID

      public static final String MODEL_LIST_TYPE_ID
      Type of model list to return, model id = model node handle
      See Also:
    • MODEL_LIST_TYPE_URI

      public static final String MODEL_LIST_TYPE_URI
      Type of models list to return, uri = root context + model id
      See Also:
    • MODEL_DESCR_TYPE_JSON

      public static final String MODEL_DESCR_TYPE_JSON
      Defines what type of model definition gets passed, currently only JSON format is implemented
      See Also:
    • PAYLOAD_TYPE_JCR

      public static final String PAYLOAD_TYPE_JCR
      Type of payload referencing used when starting a workflow, in this case a JCR Path
      See Also:
    • PAYLOAD_TYPE_URL

      public static final String PAYLOAD_TYPE_URL
      Type of payload referencing used when starting a workflow, in this case a URL Path
      See Also:
  • Constructor Details

    • WorkflowClient

      public WorkflowClient(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
    • WorkflowClient

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

    • deployModel

      public String deployModel(String modelSourcePath, String modelType, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, IOException
      Creates a new workflow model in the repository by sending a model definition.

      Handled by:

      granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\ModelsServlet.java
      Parameters:
      modelSourcePath - path to model
      modelType - if null or MODEL_DESCR_TYPE_JSON, the model description should be in JSON format.
      expectedStatus - list of allowed HTTP Status to be returned. if not set, http status 201 (CREATED) is assumed.
      Returns:
      the path to the newly created model, equals to the models ID
      Throws:
      org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      IOException - if access to to the JSON resource fails
    • deployModel

      public String deployModel(String modelSourcePath, String modelType, List<org.apache.http.NameValuePair> replaces, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, IOException
      same as deployModel(String, String, int...), but with a list of strings to replace in the model
      Parameters:
      modelSourcePath - resource path of the model
      modelType - model type
      replaces - list of strings pairs to replace
      expectedStatus - expected status of the http response
      Returns:
      model id
      Throws:
      org.apache.sling.testing.clients.ClientException - of the request failed
      IOException - if the model cannot be read
    • advanceWorkItem

      public org.apache.sling.testing.clients.SlingHttpResponse advanceWorkItem(String workItemId, String routeId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Advances a workflow item trough the next step. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InboxServlet.java
      Parameters:
      workItemId - the work item to advance
      routeId - the route it should take
      expectedStatus - The HTTP status that should be returned, otherwise 200 is assumed.
      Returns:
      The request executor if access to response is needed.
      Throws:
      org.apache.sling.testing.clients.ClientException - if HTTP request fails for any reason.
    • chooseRouteAndAdvance

      public List<org.apache.sling.testing.clients.SlingHttpResponse> chooseRouteAndAdvance(String workflowInstancePath, int chooseRoute) throws org.apache.sling.testing.clients.ClientException
      Choose the route and advance with it
      Parameters:
      workflowInstancePath - the source of the workflow instance
      chooseRoute - based on the model at the expected step, the route that should be used (0, 1, 2, etc..)
      Returns:
      The request executor as list if access to response is needed for each of the workitems (in case more than one was found).
      Throws:
      org.apache.sling.testing.clients.ClientException - if HTTP request fails for any reason.
    • stepBackWorkItem

      public org.apache.sling.testing.clients.SlingHttpResponse stepBackWorkItem(String workItemId, String backrouteId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Advances a workflow item back to a previous step. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InboxServlet.java
      Parameters:
      workItemId - the work item to advance
      backrouteId - the route it should take
      expectedStatus - The HTTP status that should be returned, otherwise 200 is assumed.
      Returns:
      The request executor if access to response is needed.
      Throws:
      org.apache.sling.testing.clients.ClientException - if HTTP request fails for any reason.
    • delegateWorkItem

      public org.apache.sling.testing.clients.SlingHttpResponse delegateWorkItem(String workItemId, String delegatee, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Delegates a workflow item to an other user Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InboxServlet.java
      Parameters:
      workItemId - the work item to delegate
      delegatee - the user/group this work item gets delegated to
      expectedStatus - The HTTP status that should be returned, otherwise 200 is assumed.
      Returns:
      The request executor if access to response is needed.
      Throws:
      org.apache.sling.testing.clients.ClientException - if HTTP request fails for any reason.
    • approveAndAdvanceWorkItem

      public org.apache.sling.testing.clients.SlingHttpResponse approveAndAdvanceWorkItem(WorkItem workItem, String routeId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Approves a workflow item and advanced to another node. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InboxServlet.java
      Parameters:
      workItem - the work item to delegate
      routeId - the user/group this work item gets delegated to
      expectedStatus - The HTTP status that should be returned, otherwise 200 is assumed.
      Returns:
      The request executor if access to response is needed.
      Throws:
      org.apache.sling.testing.clients.ClientException - if HTTP request fails for any reason.
    • approveComment

      public org.apache.sling.testing.clients.SlingHttpResponse approveComment(String workItemId, String routeId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getInboxItems

      public Map<String,InboxItem> getInboxItems(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns the list of work item that are currently in the inbox of this client's user. The returned map is using the work items uri as key. handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InboxServlet.java
      Parameters:
      expectedStatus - The HTTP status that should returned, othewise 200 is assumed.
      Returns:
      A map where key ist the uri of the stored work item
      Throws:
      org.apache.sling.testing.clients.ClientException - if requesting the JSON fails
    • getWorkItemByURI

      public WorkItem getWorkItemByURI(String uri, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns all available information about a work item.
      Parameters:
      uri - the URI pointing to the work item node
      expectedStatus - the HTTP status that should be returned, otherwise 200 is assumed
      Returns:
      the Work item wrapper
      Throws:
      org.apache.sling.testing.clients.ClientException - if requesting the JSON fails for any reason
    • getWorkItemBackRouteIds

      public List<String> getWorkItemBackRouteIds(String uri, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • deleteModel

      public org.apache.sling.testing.clients.SlingHttpResponse deleteModel(String modelId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Deletes a workflow model definition. Note that the model node does not get removed. It only gets a property set in its Metadata sub node named 'deleted' with a value of true.

      In order to solve firewall/proxy issues a POST that contains a X-HTTP-Method-Override header entry with value DELETE is sent instead of the proper HTTP DELETE.

      Handled by:

      granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\ModelServlet.java
      Parameters:
      modelId - the id of the model to delete
      expectedStatus - HTTP status to be returned, otherwise 20 (NO CONTENT) is assumed
      Returns:
      the request executor containing the response object and content.
      Throws:
      org.apache.sling.testing.clients.ClientException - if POST request fails for any reason
    • abortWorkflow

      public org.apache.sling.testing.clients.SlingHttpResponse abortWorkflow(String instanceId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Aborts/Terminates a running workflow instance.
      Parameters:
      instanceId - instanceId (nodepath) of the running workflow instance
      expectedStatus - if not set it defaults to 200
      Returns:
      the request executor containing the repsone object and content
      Throws:
      org.apache.sling.testing.clients.ClientException - if POST fails for any reasons
    • updateModel

      public org.apache.sling.testing.clients.SlingHttpResponse updateModel(String modelSourcePath, String modelType, String modelId, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, IOException
      updates an existing workflow model in the repository by sending a updated model definition.

      Handled by:

      granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\ModelServlet.java
      Parameters:
      modelSourcePath - path to model
      modelType - if null or MODEL_DESCR_TYPE_JSON, the model description should bE in JSON format.
      modelId - the model to be updated
      expectedStatus - list of allowed HTTP Status to be returned. if not set, http status 200 (ok) is assumed.
      Returns:
      The request executor used to send the request
      Throws:
      org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      IOException - if access to to the JSON resource fails
    • getWorkflowEngineInfo

      public WorkflowEngine getWorkflowEngineInfo(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Gets the workflow engine info from "/etc/workflow".

      Handled by:

      granite\bundles\workflow\content\src\main\content\jcr_root \libs\cq\workflow\components\engine\json.jsp
      Parameters:
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      the Workflow Engine wrapper
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request for the JSON data fails.
    • stopWorkflowEngine

      public org.apache.sling.testing.clients.SlingHttpResponse stopWorkflowEngine(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Stops the Workflow Engine, equals to stopping the Workflow service. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\EngineServlet.java
      Parameters:
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      returns the request executor, if more info from the response is required.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails.
    • startWorkflowEngine

      public org.apache.sling.testing.clients.SlingHttpResponse startWorkflowEngine(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Starts the Workflow Engine, equals to starting the Workflow service. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\EngineServlet.java
      Parameters:
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      returns the request executor, if more info from the response is required.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails.
    • isWorkflowEngineActive

      public boolean isWorkflowEngineActive() throws org.apache.sling.testing.clients.ClientException
      Checks if the workflow engine is in an active state (actually its the workflow OSGi service that gets tested).
      Returns:
      true if the Workflow Engine is active otherwise false.
      Throws:
      org.apache.sling.testing.clients.ClientException - if requesting Workflow Info fails
    • startWorkflow

      public String startWorkflow(String modelId, String payload, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Convenience function for the most common case , using JCR path to reference the payload.
      Parameters:
      modelId - the workflow model id to be used.
      payload - the payload JCR path to be set.
      expectedStatus - The HTTP Status to be returned otherwise 201 is assumed
      Returns:
      the id of the new workflowInstance
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails
    • startWorkflow

      public String startWorkflow(String modelId, String payloadType, String payload, Map<String,String> metaData, String title, String comment, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Starts a new workflow using the given model id, with the payload specified. Handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite\workflow \console\servlet\InstancesServlet.java
      Parameters:
      modelId - The workflow model Id to be used.
      payloadType - The type of payload referencing, either PAYLOAD_TYPE_JCR or PAYLOAD_TYPE_URL . if set to null , {#PAYLOAD_TYPE_JCR} is used as default
      payload - the JCR path(s) or URL(s) pointing to the server resource that act as payload. each payload entry will start a new workflow instance
      metaData - any meta data that needs to be passed when starting the workflow
      title - title to be set for this workflow instance
      comment - comment to be set when starting the workflow
      expectedStatus - The HTTP Status to be returned otherwise 201 is assumed
      Returns:
      the id of the new workflowInstance
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails
    • updateWfInstanceComment

      public org.apache.sling.testing.clients.SlingHttpResponse updateWfInstanceComment(String instanceURI, String comment, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Convenience functions to update/set the comment in the workflow instance metadata.
      Parameters:
      instanceURI - the workflow instance to be updated
      comment - the comment of the workflow instance to be set
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      the request executor containing the response object and content.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails.
    • updateWfInstanceTitle

      public org.apache.sling.testing.clients.SlingHttpResponse updateWfInstanceTitle(String instanceURI, String title, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Convenience function to set edit/set the title of a workflow instance in its meta data.
      Parameters:
      instanceURI - the workflow instance to be updated
      title - the title of the workflow instance to be set
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      the request executor containing the response object and content.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails.
    • updateWfInstanceMetaData

      public org.apache.sling.testing.clients.SlingHttpResponse updateWfInstanceMetaData(String instanceURI, Map<String,String> metaData, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Sends an update request to a workflow instance to update/add metadata
      Parameters:
      instanceURI - the workflow instance to be updated
      metaData - the metadata to be added /updated
      expectedStatus - The HTTP Status to be returned otherwise 200 is assumed
      Returns:
      the request executor containing the response object and content.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the POST request fails.
    • getWorkflowInstanceURLs

      public List<URI> getWorkflowInstanceURLs(WorkflowClient.Status wfStatus, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns a list of workflow instance URI's that are visible for the user. Can be filtered by the instance status.

      Handled by :

      granite\bundles\workflow\content\src\main\content\jcr_root\libs\cq\ workflow\components\instances\json.jsp
      Parameters:
      wfStatus - Only returns workflows that are in one of the possible States ( WorkflowClient.Status.RUNNING, WorkflowClient.Status.ABORTED, WorkflowClient.Status.COMPLETED or WorkflowClient.Status.SUSPENDED), or, if set to null, returns all workflow instances.
      expectedStatus - HTTP Status to check for or, if not set, 200 is assumed
      Returns:
      A String List containing all workflow instance handles visible to this user according to the filter set in wfStatus.
      Throws:
      org.apache.sling.testing.clients.ClientException - if the call to the backend requesting the JSON fails
    • getWorkflowModels

      public ArrayList<String> getWorkflowModels(String listType, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns a list of all available workflow models for this user. Handled by: granite\bundles\workflow\content\src\main\content\jcr_root\libs\cq\ workflow\components\models\json.jsp
      Parameters:
      listType - if set to MODEL_LIST_TYPE_ID , a list of model ID's gets returned (model ID = model Handle) if set to null or MODEL_LIST_TYPE_URI, a list of model URI's gets returned (URI = context path + model ID)
      expectedStatus - HTTP Status to check for or, if not set, 200 is assumed
      Returns:
      A String array containing a list of all workflow model visible to this user
      Throws:
      org.apache.sling.testing.clients.ClientException - if requesting the JSON fails for any reason
    • getWorkflowModelAsJSON

      public String getWorkflowModelAsJSON(String modelId, String version, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns the model definition (metadata, nodes, transitions,title ,description etc) handled by: \granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\ModelServlet.java
      Parameters:
      modelId - the model id to request
      version - the version to retrieve. Either 'HEAD' or null to get the latest version or in the format major.minor e.g. '1.2'.
      expectedStatus - the expected HTTP Status, if not set 200 is assumed
      Returns:
      the requested version of the model definition in JSON format
      Throws:
      org.apache.sling.testing.clients.ClientException - If requesting the JSON fails for any reason
    • getWorkflowModel

      public WorkflowModel getWorkflowModel(String modelId, String version, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns the model definition (metadata, nodes, transitions,title ,description etc) in a wrapper class. handled by: \granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\ModelServlet.java
      Parameters:
      modelId - the model id to request
      version - the version to retrieve. Either 'HEAD' or null to get the latest version or in the format major.minor e.g. '1.2'.
      expectedStatus - the expected HTTP Status, if not set 200 is assumed
      Returns:
      the requested version of the model definition in JSON format
      Throws:
      org.apache.sling.testing.clients.ClientException - If requesting the JSON fails for any reason
    • getWorkflowInstance

      public WorkflowInstance getWorkflowInstance(String instanceURI, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Returns all the information about a workflow instance in JSON format. Handled by: granite\bundles\workflow\content\src\main\content\jcr_root\libs\cq\ workflow\components\instance\json.jsp
      Parameters:
      instanceURI - the path to the workflow instance
      expectedStatus - the expected HTTP status, otherwise 200 is assumed
      Returns:
      A WorkflowInstance that wraps the JSON response.
      Throws:
      org.apache.sling.testing.clients.ClientException - if requesting the JSON fails
    • getWorkflowInstances

      public List<WorkflowInstance> getWorkflowInstances(WorkflowClient.Status wfStatus, String model, String payload, org.joda.time.DateTime startTimeLimit, org.joda.time.DateTime endTimeLimit) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getWorkflowInstances

      public List<WorkflowInstance> getWorkflowInstances(WorkflowClient.Status wfStatus) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getWorkflowInstances

      public List<WorkflowInstance> getWorkflowInstances(WorkflowClient.Status wfStatus, org.joda.time.DateTime startTimeLimit, org.joda.time.DateTime endTimeLimit) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getWorkflowInstances

      public List<WorkflowInstance> getWorkflowInstances() throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • getWorkflowInstanceHistory

      public List<HistoryItem> getWorkflowInstanceHistory(String instanceURI, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Retrieve the workflow history of a specific workflow instance
      Parameters:
      instanceURI - the workflow instance uri
      expectedStatus - provide the status code that is expected, default is 200 OK.
      Returns:
      the history items as a list
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request failed
    • setWorkflowInstanceStatus

      public org.apache.sling.testing.clients.SlingHttpResponse setWorkflowInstanceStatus(String instanceURI, WorkflowClient.Status status, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Set the status of an running workflow instance. handled by: granite\bundles\workflow\console\src\main\java\com\adobe\granite \workflow\console\servlet\InstanceServlet.java
      Parameters:
      instanceURI - path to the instance url
      status - status to be set, either WorkflowClient.Status.ABORTED, WorkflowClient.Status.RUNNING or WorkflowClient.Status.SUSPENDED
      expectedStatus - Expected HTTP status, otherwise 200 is assumed
      Returns:
      the request executor if more info from response is required.
      Throws:
      org.apache.sling.testing.clients.ClientException - if POST request has problems
    • parseJSONDate

      public static Date parseJSONDate(String date)
      Turns a string date returned by JSON into a Date object.
      Parameters:
      date - the string to parse
      Returns:
      the parsed Date object or null if parsing cannot be done