Package com.adobe.cq.testing.client
Class CQClient
- java.lang.Object
-
- org.apache.sling.testing.clients.AbstractSlingClient
-
- org.apache.sling.testing.clients.SlingClient
-
- com.adobe.cq.testing.client.CQClient
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.client.HttpClient
- Direct Known Subclasses:
BulkEditorClient,CommunityClient,ComponentClient,CQAssetsClient,CQConfigManagerClient,ExperienceFragmentsClient,FormClient,JobsClient,JsonClient,MSMClient,NotificationClient,OffloadingBrowserClient,OffloadingClient,PackageManagerClient,ReplicationClient,SecurityClient,TagClient,TemplateEditorManagerClient,TogglesClient,TopologyClient,VersioningClient,WorkflowClient
@Immutable public class CQClient extends org.apache.sling.testing.clients.SlingClientBase client for all CQ related clients. It provides a core set of commonly used website and page functions e.g. creating/deleting/moving pages, versioning, activation/deactivation, restore tree etc.
It extends from
SlingClientwhich in turn provides functions for manipulating repository nodes directly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCQClient.Builderstatic classCQClient.InternalBuilder<T extends CQClient>
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.LoggerLOGprotected static StringSTATISTICS_ROOTPath where statistics are storedprotected WCMCommandswcmCommandsWCMCommands object that encapsulates all available WCM commands
-
Constructor Summary
Constructors Constructor Description CQClient(URI url, String user, String password)Handy constructor easy to use in simple tests.CQClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config)Constructor used by Builders and adaptTo().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.sling.testing.clients.SlingHttpResponsecopyLanguages(String sitePath, List<org.apache.http.message.BasicNameValuePair> relPaths, int... expectedStatus)Creates language copies af a master site.org.apache.sling.testing.clients.SlingHttpResponsecopyPage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, int... expectedStatus)Copies one or more CQ pages to a specified location in the repository.org.apache.sling.testing.clients.SlingHttpResponsecreatePage(String pageName, String pageTitle, String parentPath, String templatePath, int... expectedStatus)Creates a CQ page in the repository.org.apache.sling.testing.clients.SlingHttpResponsecreatePageWithRetry(String pageName, String pageTitle, String parentPath, String templatePath, long timeout, long delay, int... expectedStatus)Tries to create a CQ page until the request succeeds or timeout is reachedorg.apache.sling.testing.clients.SlingHttpResponsecreateVersion(String pagePath, String comment, String label, int... expectedStatus)Creates a Version for a CQ page.org.apache.sling.testing.clients.SlingHttpResponsedeletePage(String[] pagePaths, boolean force, boolean shallow, int... expectedStatus)Deletes an array of pages.org.apache.sling.testing.clients.SlingHttpResponsedeletePageWithRetry(String pagePath, boolean force, boolean shallow, long timeout, long delay, int... expectedStatus)Tries to deletes a CQ page multiple times if the request failsorg.apache.sling.testing.clients.SlingHttpResponsegetAuthorSitesPage(String pagePath, int... expectedStatus)Get a CQ Page (.html extension)org.apache.sling.testing.clients.SlingHttpResponselockPage(String path, int... expectedStatus)Locks a CQ page so it can only be edited by the person who locked it.org.apache.sling.testing.clients.SlingHttpResponsemovePage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, boolean integrity, String[] adjusts, int... expectedStatus)Moves one or more CQ pages to a specified location.
Settingintegrityto false and list of referrers inadjuststo null equals a drag'n'drop move in the site admin.org.apache.sling.testing.clients.SlingHttpResponsemovePage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, boolean integrity, String[] adjusts, String[] publishes, int... expectedStatus)Moves one or more CQ pages to a specified location.
Settingintegrityto false and list of referrers inadjuststo null equals a drag'n'drop move in the site admin.booleanpageExists(String pagePath)Returns whether a CQ page exists or notbooleanpageExistsWithRetry(String pagePath)Polls on whether a CQ page exists or not after 1 secondbooleanpageExistsWithRetry(String pagePath, int timeout)Polls on whether a CQ page exists or notvoidresetPageStatistics(String pagePath)Deletes existing statistics (page impressions) of a page.org.apache.sling.testing.clients.SlingHttpResponserestoreTree(String path, Date date, boolean preserveNVP, int... expectedStatus)Restores a sub page in path to the version that existed at the given date.org.apache.sling.testing.clients.SlingHttpResponserestoreVersion(String[] versionIds, String pagePath, int... expectedStatus)Restores a specified version of a CQ page.org.apache.sling.testing.clients.SlingHttpResponserolloutPage(String srcPath, String[] targetPaths, boolean deep, boolean reset, boolean useBackgroundJob, int... expectedStatus)Rolls out changes to the livecopyvoidsearchAndReplaceInPages(String startPath, String searchQuery, String replace, boolean caseSensitive, boolean wholeWordOnly)Requests a search and replaces the content of a path.com.fasterxml.jackson.databind.JsonNodesearchInPages(String startPath, String searchQuery, boolean caseSensitive, boolean wholeWordOnly)Requests a text search on the content of a path and returns the pages matching the criteria.org.apache.sling.testing.clients.SlingHttpResponsesetPageProperties(String pagePath, List<org.apache.http.NameValuePair> props, int... expectedStatus)Sets multiple page properties on a CQ page with one request.org.apache.sling.testing.clients.SlingHttpResponsesetPageProperty(String pagePath, String propName, String propValue, int... expectedStatus)Sets a single page property on a CQ page.org.apache.sling.testing.clients.SlingHttpResponsesetPagePropertyImage(String pagePath, String mimeType, String fileName, String resourcePath, int... expectedStatus)Sets the teaser image of a content page.org.apache.sling.testing.clients.SlingHttpResponseunlockPage(String path, int... expectedStatus)Unlocks a previously locked CQ page.org.apache.sling.testing.clients.SlingHttpResponseuploadFileCQStyle(String fileName, String resourcePath, String mimeType, String parentPath, int... expectedStatus)Uploads an File to the repository.-
Methods inherited from class org.apache.sling.testing.clients.SlingClient
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, endImpersonation, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUser, getUUId, getUUID, impersonate, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
-
Methods inherited from class org.apache.sling.testing.clients.AbstractSlingClient
adaptTo, addValue, close, doDelete, doGet, doGet, doGet, doHead, doPatch, doPost, doPost, doPut, doRawRequest, doRequest, doStreamGet, doStreamPost, doStreamRequest, execute, execute, execute, execute, execute, execute, execute, execute, getClientId, getConnectionManager, getCookieStore, getCredentialsProvider, getParams, getPassword, getPath, getPath, getUrl, getUrl, getUrl, getValue, getValues, hasValue
-
-
-
-
Field Detail
-
LOG
public static org.slf4j.Logger LOG
-
STATISTICS_ROOT
protected static final String STATISTICS_ROOT
Path where statistics are stored- See Also:
- Constant Field Values
-
wcmCommands
protected final WCMCommands wcmCommands
WCMCommands object that encapsulates all available WCM commands
-
-
Constructor Detail
-
CQClient
public CQClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config) throws org.apache.sling.testing.clients.ClientExceptionConstructor used by Builders and adaptTo(). Should never be called directly from the code. See AbstractSlingClient#AbstractSlingClient(CloseableHttpClient, SlingClientConfig)- Parameters:
http- the underlying HttpClient to be usedconfig- sling specific configs- Throws:
org.apache.sling.testing.clients.ClientException- if the client could not be created
-
CQClient
public CQClient(URI url, String user, String password) throws org.apache.sling.testing.clients.ClientException
Handy constructor easy to use in simple tests. Creates a client that uses basic authentication.
For constructing clients with complex configurations, use a
CQClient.InternalBuilderFor constructing clients with the same configuration, but a different class, use
AbstractSlingClient.adaptTo(Class)- Parameters:
url- url of the server (including context path)user- username for basic authenticationpassword- password for basic authentication- Throws:
org.apache.sling.testing.clients.ClientException- never, kept for uniformity with the other constructors
-
-
Method Detail
-
createPage
public org.apache.sling.testing.clients.SlingHttpResponse createPage(String pageName, String pageTitle, String parentPath, String templatePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Creates a CQ page in the repository.- Parameters:
pageName- name of the pagepageTitle- title of the pageparentPath- path to the parent pagetemplatePath- path to the templateexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- a
SlingHttpResponse - Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
createPageWithRetry
public org.apache.sling.testing.clients.SlingHttpResponse createPageWithRetry(String pageName, String pageTitle, String parentPath, String templatePath, long timeout, long delay, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException
Tries to create a CQ page until the request succeeds or timeout is reached- Parameters:
pageName- name of the pagepageTitle- title of the pageparentPath- path to the parent pagetemplatePath- path to the template definitiontimeout- max execution time, in millisecondsdelay- time to wait between retries, in millisecondsexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- a
SlingHttpResponse - Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycleInterruptedException- to mark this method as waiting
-
deletePage
public org.apache.sling.testing.clients.SlingHttpResponse deletePage(String[] pagePaths, boolean force, boolean shallow, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Deletes an array of pages.
The caller must ensure that the paths can be deleted
- Parameters:
pagePaths- array of paths to be deletedforce- force param passed to wcmCommandsshallow- shallow param passed to wcmCommandsexpectedStatus- list of expected HTTP status to be returned- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if one of the pages fails to delete
-
deletePageWithRetry
public org.apache.sling.testing.clients.SlingHttpResponse deletePageWithRetry(String pagePath, boolean force, boolean shallow, long timeout, long delay, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException
Tries to deletes a CQ page multiple times if the request fails- Parameters:
pagePath- the path to deleteforce- passed to wcmCommandsshallow- passed to wcmCommandsexpectedStatus- list of expected HTTP status to be returnedtimeout- max execution time, in millisecondsdelay- time to wait between retries, in milliseconds- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if the page(s) wre not deletedInterruptedException- if the method was interrupted
-
pageExists
public boolean pageExists(String pagePath) throws org.apache.sling.testing.clients.ClientException
Returns whether a CQ page exists or not- Parameters:
pagePath- The path of the page- Returns:
- whether the CQ page exists
- Throws:
org.apache.sling.testing.clients.ClientException- If the request failed
-
pageExistsWithRetry
public boolean pageExistsWithRetry(String pagePath, int timeout) throws InterruptedException
Polls on whether a CQ page exists or not- Parameters:
pagePath- The path of the pagetimeout- Timeout in milliseconds for the poller- Returns:
- whether the CQ page exists
- Throws:
InterruptedException- if interrupted
-
pageExistsWithRetry
public boolean pageExistsWithRetry(String pagePath) throws InterruptedException
Polls on whether a CQ page exists or not after 1 second- Parameters:
pagePath- The path of the page- Returns:
- whether the CQ page exists
- Throws:
InterruptedException- if interrupted
-
getAuthorSitesPage
public org.apache.sling.testing.clients.SlingHttpResponse getAuthorSitesPage(String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Get a CQ Page (.html extension)- Parameters:
pagePath- The path of the pageexpectedStatus- An array of expected HTTP status codes for the response- Returns:
- the http response
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failed
-
copyPage
public org.apache.sling.testing.clients.SlingHttpResponse copyPage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Copies one or more CQ pages to a specified location in the repository.- Parameters:
srcPaths- list of pages to copydestName- name given to the copied page at new location. Only works for single page copy, otherwise the operation fails.destPath- destination of copy operation. Can be used instead of destParentPath + destName. Works only for single page copy, otherwise the operation fails.destParentPath- target location of the copy operationbefore- if true, the copied page will be ordered before the page with this label (Name)shallow- if true, the only the page itself gets copiedexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the http response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
movePage
public org.apache.sling.testing.clients.SlingHttpResponse movePage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, boolean integrity, String[] adjusts, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Moves one or more CQ pages to a specified location.
Settingintegrityto false and list of referrers inadjuststo null equals a drag'n'drop move in the site admin. The server then performs an auto adjustment on referring pages.
Passing a list of referrers and setting integrity flag totrueis the same as theMove...command in the site admin.- Parameters:
srcPaths- list of pages to copydestName- name given to the moved page at new location. Only works for single page copy, otherwise the operation fails.destPath- destination of copy operation. Can be used instead of destParentPath + destName. Only works for single page copy, otherwise the operation fails.destParentPath- target location of the move operationbefore- if true, the copied page will be ordered before the page with this label (Name)shallow- if true, the only the page itself gets copiedintegrity- if true, no auto adjustment of referred pages will be doneadjusts- List of referrer page paths that need adjustingexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
movePage
public org.apache.sling.testing.clients.SlingHttpResponse movePage(String[] srcPaths, String destName, String destPath, String destParentPath, String before, boolean shallow, boolean integrity, String[] adjusts, String[] publishes, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Moves one or more CQ pages to a specified location.
Settingintegrityto false and list of referrers inadjuststo null equals a drag'n'drop move in the site admin. The server then performs an auto adjustment on referring pages.
Passing a list of referrers and setting integrity flag totrueis the same as theMove...command in the site admin.- Parameters:
srcPaths- list of pages to copydestName- name given to the moved page at new location. Only works for single page copy, otherwise the operation fails.destPath- destination of copy operation. Can be used instead of destParentPath + destName. Only works for single page copy, otherwise the operation fails.destParentPath- target location of the move operationbefore- if true, the copied page will be ordered before the page with this label (Name)shallow- if true, the only the page itself gets copiedintegrity- if true, no auto adjustment of referred pages will be doneadjusts- list of referrer page paths that need adjustingpublishes- list of page paths that need to be publishedexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
lockPage
public org.apache.sling.testing.clients.SlingHttpResponse lockPage(String path, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Locks a CQ page so it can only be edited by the person who locked it.- Parameters:
path- path of the page to lockexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
unlockPage
public org.apache.sling.testing.clients.SlingHttpResponse unlockPage(String path, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Unlocks a previously locked CQ page.- Parameters:
path- path of the page to unlockexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
setPageProperty
public org.apache.sling.testing.clients.SlingHttpResponse setPageProperty(String pagePath, String propName, String propValue, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Sets a single page property on a CQ page.- Parameters:
pagePath- path of the page to be editedpropName- name of the property to be editedpropValue- value to be setexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
setPageProperties
public org.apache.sling.testing.clients.SlingHttpResponse setPageProperties(String pagePath, List<org.apache.http.NameValuePair> props, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Sets multiple page properties on a CQ page with one request.- Parameters:
pagePath- path of the page to be editedprops- list of name/value string pairs to be setexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
setPagePropertyImage
public org.apache.sling.testing.clients.SlingHttpResponse setPagePropertyImage(String pagePath, String mimeType, String fileName, String resourcePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Sets the teaser image of a content page.- Parameters:
pagePath- path to the page to be editedmimeType- MIME type of the image getting uploadedfileName- file name of the imageresourcePath- defines the path to the resourceexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
uploadFileCQStyle
public org.apache.sling.testing.clients.SlingHttpResponse uploadFileCQStyle(String fileName, String resourcePath, String mimeType, String parentPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Uploads an File to the repository. Same as usingNew File...in the Site Admin outside of theDigital Assetsfolder.
This will create a folder with the file name and upload the file below it in a node typednt:file.
To upload a file that is to be handled as an Asset useCQAssetsClient.uploadAsset(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int...)instead.
To upload a file directly using sling useupload.- Parameters:
fileName- file name. The file name will become part of the URL to the file.resourcePath- defines the path to the resourcemimeType- MIME type of the image getting uploadedparentPath- parent page (folder) that will contain the fileexpectedStatus- list of expected HTTP Status to be returned, if not set, 201 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
createVersion
public org.apache.sling.testing.clients.SlingHttpResponse createVersion(String pagePath, String comment, String label, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Creates a Version for a CQ page. SeeVersiontab in the sidekick of a page when opened on an author instance.- Parameters:
pagePath- path of the page we want to create a version ofcomment- comment to be set for this versionlabel- Version label to be setexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
restoreVersion
public org.apache.sling.testing.clients.SlingHttpResponse restoreVersion(String[] versionIds, String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Restores a specified version of a CQ page. SeeVersiontab in the sidekick of a page when opened on an author instance.- Parameters:
versionIds- version Id of the current page and/or version ids of sub pages ofpagePathpagePath- path to the page we want to restore the versionexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
restoreTree
public org.apache.sling.testing.clients.SlingHttpResponse restoreTree(String path, Date date, boolean preserveNVP, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Restores a sub page in path to the version that existed at the given date.- Parameters:
path- path of the root page of the treedate- the date to restorepreserveNVP- whether to preserve NVP or notexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
copyLanguages
public org.apache.sling.testing.clients.SlingHttpResponse copyLanguages(String sitePath, List<org.apache.http.message.BasicNameValuePair> relPaths, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Creates language copies af a master site.- Parameters:
sitePath- path to the site with the master contentrelPaths- list of string pairs, first being the relative path to be created, second the language shortcut to be copied from e.g. {fr/products/circle,en}expectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
rolloutPage
public org.apache.sling.testing.clients.SlingHttpResponse rolloutPage(String srcPath, String[] targetPaths, boolean deep, boolean reset, boolean useBackgroundJob, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Rolls out changes to the livecopy- Parameters:
srcPath- the blue print pathtargetPaths- the live copy pathsdeep- if set to false, page is the fallbackreset- resetuseBackgroundJob- if set to true background jobs are used for rolloutexpectedStatus- list of expected HTTP Status to be returned, if not set, 200 is assumed- Returns:
- Sling response
- Throws:
org.apache.sling.testing.clients.ClientException- If something fails during request/response cycle
-
searchInPages
public com.fasterxml.jackson.databind.JsonNode searchInPages(String startPath, String searchQuery, boolean caseSensitive, boolean wholeWordOnly) throws Exception
Requests a text search on the content of a path and returns the pages matching the criteria.- Parameters:
startPath- Path to look atsearchQuery- The text to search forcaseSensitive- Do a "case-sensitive" search or notwholeWordOnly- Do a "whole word" search or not- Returns:
- The list of pages matching the search criteria
- Throws:
Exception- If something fails during the request/response cycle
-
searchAndReplaceInPages
public void searchAndReplaceInPages(String startPath, String searchQuery, String replace, boolean caseSensitive, boolean wholeWordOnly) throws Exception
Requests a search and replaces the content of a path.- Parameters:
startPath- Path to look atsearchQuery- The text to search forreplace- The text to replace withcaseSensitive- Do a "case-sensitive" search or notwholeWordOnly- Do a "whole word" search or not- Throws:
Exception- If something fails during the request/response cycle
-
resetPageStatistics
public void resetPageStatistics(String pagePath) throws org.apache.sling.testing.clients.ClientException
Deletes existing statistics (page impressions) of a page.- Parameters:
pagePath- path of the page to delete the statistics for.- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
-