@Immutable
public class CQClient
extends org.apache.sling.testing.clients.SlingClient
Base 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 SlingClient
which in turn provides functions for
manipulating repository nodes directly.
Modifier and Type | Class and Description |
---|---|
static class |
CQClient.Builder |
static class |
CQClient.InternalBuilder<T extends CQClient> |
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
LOG |
protected static String |
STATISTICS_ROOT
Path where statistics are stored
|
protected WCMCommands |
wcmCommands
WCMCommands object that encapsulates all available WCM commands
|
Constructor and Description |
---|
CQClient(org.apache.http.impl.client.CloseableHttpClient http,
org.apache.sling.testing.clients.SlingClientConfig config)
Constructor used by Builders and adaptTo().
|
CQClient(URI url,
String user,
String password)
Handy constructor easy to use in simple tests.
|
Modifier and Type | Method and Description |
---|---|
org.apache.sling.testing.clients.SlingHttpResponse |
copyLanguages(String sitePath,
List<org.apache.http.message.BasicNameValuePair> relPaths,
int... expectedStatus)
Creates language copies af a master site.
|
org.apache.sling.testing.clients.SlingHttpResponse |
copyPage(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.SlingHttpResponse |
createPage(String pageName,
String pageTitle,
String parentPath,
String templatePath,
int... expectedStatus)
Creates a CQ page in the repository.
|
org.apache.sling.testing.clients.SlingHttpResponse |
createPageWithRetry(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 reached
|
org.apache.sling.testing.clients.SlingHttpResponse |
createVersion(String pagePath,
String comment,
String label,
int... expectedStatus)
Creates a Version for a CQ page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
deletePage(String[] pagePaths,
boolean force,
boolean shallow,
int... expectedStatus)
Deletes an array of pages.
|
org.apache.sling.testing.clients.SlingHttpResponse |
deletePageWithRetry(String pagePath,
boolean force,
boolean shallow,
long timeout,
long delay,
int... expectedStatus)
Tries to deletes a CQ page multiple times if the request fails
|
org.apache.sling.testing.clients.SlingHttpResponse |
lockPage(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.SlingHttpResponse |
movePage(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.
Setting integrity to false and list of referrers in adjusts to null equals
a drag'n'drop move in the site admin. |
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)
Moves one or more CQ pages to a specified location.
Setting integrity to false and list of referrers in adjusts to null equals
a drag'n'drop move in the site admin. |
void |
resetPageStatistics(String pagePath)
Deletes existing statistics (page impressions) of a page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
restoreTree(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.SlingHttpResponse |
restoreVersion(String[] versionIds,
String pagePath,
int... expectedStatus)
Restores a specified version of a CQ page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
rolloutPage(String srcPath,
String[] targetPaths,
boolean deep,
boolean reset,
boolean useBackgroundJob,
int... expectedStatus)
Rolls out changes to the livecopy
|
void |
searchAndReplaceInPages(String startPath,
String searchQuery,
String replace,
boolean caseSensitive,
boolean wholeWordOnly)
Requests a search and replaces the content of a path.
|
org.codehaus.jackson.JsonNode |
searchInPages(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.SlingHttpResponse |
setPageProperties(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.SlingHttpResponse |
setPageProperty(String pagePath,
String propName,
String propValue,
int... expectedStatus)
Sets a single page property on a CQ page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
setPagePropertyImage(String pagePath,
String mimeType,
String fileName,
String resourcePath,
int... expectedStatus)
Sets the teaser image of a content page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
unlockPage(String path,
int... expectedStatus)
Unlocks a previously locked CQ page.
|
org.apache.sling.testing.clients.SlingHttpResponse |
uploadAsset(String fileName,
String resourcePath,
String mimeType,
String parentPath,
int... expectedStatus)
Uploads an Asset to the repository.
|
org.apache.sling.testing.clients.SlingHttpResponse |
uploadFileCQStyle(String fileName,
String resourcePath,
String mimeType,
String parentPath,
int... expectedStatus)
Uploads an File to the repository.
|
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUUId, getUUID, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
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, getUser, getValue, getValues, hasValue
public static org.slf4j.Logger LOG
protected static final String STATISTICS_ROOT
protected final WCMCommands wcmCommands
public CQClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config) throws org.apache.sling.testing.clients.ClientException
http
- the underlying HttpClient to be usedconfig
- sling specific configsorg.apache.sling.testing.clients.ClientException
- if the client could not be createdAbstractSlingClient.AbstractSlingClient(CloseableHttpClient, SlingClientConfig)
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.InternalBuilder
For constructing clients with the same configuration, but a different class, use AbstractSlingClient.adaptTo(Class)
url
- url of the server (including context path)user
- username for basic authenticationpassword
- password for basic authenticationorg.apache.sling.testing.clients.ClientException
- never, kept for uniformity with the other constructorspublic org.apache.sling.testing.clients.SlingHttpResponse createPage(String pageName, String pageTitle, String parentPath, String templatePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
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.SlingHttpResponse
org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic 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
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.SlingHttpResponse
org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cycleInterruptedException
- to mark this method as waitingpublic 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
pagePaths
- array of paths to be deletedforce
- force param passed to wcmCommandsshallow
- shallow param passed to wcmCommandsexpectedStatus
- list of expected HTTP status to be returnedorg.apache.sling.testing.clients.ClientException
- if one of the pages fails to deletepublic 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
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 millisecondsorg.apache.sling.testing.clients.ClientException
- if the page(s) wre not deletedInterruptedException
- if the method was interruptedpublic 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
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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic 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
integrity
to false and list of referrers in adjusts
to null equals
a drag'n'drop move in the site admin. The server then performs an auto adjustment on referring pages.true
is the same as the
Move...
command in the site admin.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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic 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
integrity
to false and list of referrers in adjusts
to null equals
a drag'n'drop move in the site admin. The server then performs an auto adjustment on referring pages.true
is the same as the
Move...
command in the site admin.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 assumedorg.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse lockPage(String path, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
path
- path of the page to lockexpectedStatus
- list of expected HTTP Status to be returned, if not set, 200 is assumed.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse unlockPage(String path, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
path
- path of the page to unlockexpectedStatus
- list of expected HTTP Status to be returned, if not set, 200 is assumed.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse setPageProperty(String pagePath, String propName, String propValue, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse setPageProperties(String pagePath, List<org.apache.http.NameValuePair> props, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse setPagePropertyImage(String pagePath, String mimeType, String fileName, String resourcePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse uploadAsset(String fileName, String resourcePath, String mimeType, String parentPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
New File...
in the DAM admin or when
uploading a file below Digital Assets
in the Site Admin.dam:Asset
. This will trigger all
DAM related workflows for generating rendition nodes, extract metadata etc.uploadFileCQStyle(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int...)
instead.SlingClient.upload(java.io.File, String, String, boolean, int...)
.fileName
- file nameresourcePath
- 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, 200 is assumed.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse uploadFileCQStyle(String fileName, String resourcePath, String mimeType, String parentPath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
New File...
in the Site Admin outside of the
Digital Assets
folder.nt:file
.uploadAsset(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int...)
instead.upload
.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.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse createVersion(String pagePath, String comment, String label, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Version
tab in the sidekick of a page when opened on
an author instance.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 assumedorg.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse restoreVersion(String[] versionIds, String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Version
tab in the sidekick of a page when opened
on an author instance.versionIds
- version Id of the current page and/or version ids of sub pages of pagePath
pagePath
- path to the page we want to restore the versionexpectedStatus
- list of expected HTTP Status to be returned, if not set, 200 is assumedorg.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic org.apache.sling.testing.clients.SlingHttpResponse restoreTree(String path, Date date, boolean preserveNVP, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
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 assumedorg.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic 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
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 assumedorg.apache.sling.testing.clients.ClientException
- if something fails during the request/response cyclepublic 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
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 assumedorg.apache.sling.testing.clients.ClientException
- If something fails during request/response cyclepublic org.codehaus.jackson.JsonNode searchInPages(String startPath, String searchQuery, boolean caseSensitive, boolean wholeWordOnly) throws Exception
startPath
- Path to look atsearchQuery
- The text to search forcaseSensitive
- Do a "case-sensitive" search or notwholeWordOnly
- Do a "whole word" search or notException
- If something fails during the request/response cyclepublic void searchAndReplaceInPages(String startPath, String searchQuery, String replace, boolean caseSensitive, boolean wholeWordOnly) throws Exception
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 notException
- If something fails during the request/response cyclepublic void resetPageStatistics(String pagePath) throws org.apache.sling.testing.clients.ClientException
pagePath
- path of the page to delete the statistics for.org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cycleCopyright © 2018. All rights reserved.