Class AbstractComponent
java.lang.Object
com.adobe.cq.testing.client.components.AbstractComponent
- Direct Known Subclasses:
AbstractFormFieldComponent
,AbstractFoundationComponent
,End
,ExperienceFragmentCmp
,Product
,ProfileAvatarPhoto
,ProfileDetailedName
,ProfileDisplayName
,ProfileEmail
,ProfileGender
,ProfileGeneralText
,ProfilePrimaryPhone
,ProfilePrimaryURL
,Ratings
,ShoppingCart
,Start
,TagCloud
-
Field Summary
Modifier and TypeFieldDescriptionStores the currently set of edited property valuesprotected ComponentClient
Reference to theFoundationClient
that created this instanceprotected String
The complete path to this component in the repository.static final String
Deprecated.protected com.fasterxml.jackson.databind.JsonNode
contains the Json Structure as it is currently saved on the serverprotected String
relative location inside the pageprotected String
Path to the CQ page that contains this component -
Constructor Summary
ConstructorDescriptionAbstractComponent
(ComponentClient client, String pagePath, String location, String nameHint) The constructor stores all the component path information like parentPage, name etc. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.sling.testing.clients.SlingHttpResponse
Creates the component on the server by sending the http request.Returns the client that created this component.com.fasterxml.jackson.databind.JsonNode
Returns the root node of the component node as a JsonNodeThe complete path to the component.org.apache.sling.testing.clients.util.FormEntityBuilder
getCreateFormEntity
(String order) Returns the FormEntityBuilder used for the create request increate(String,int...)
.<T extends AbstractComponent>
Treturns the first child node that is a component or null if not found.returns the relative path inside the pagegetName()
Returns the name of the component node.<T extends AbstractComponent>
TgetNext()
Returns the component wrapper instance for the following sibling or null if this component is already the last one.Returns the component path for the following sibling or null if this component is already the last one.returns the path to the page that contains the componentPath to the parent node of the component<T extends AbstractComponent>
TReturns the component wrapper instance for the previous sibling or null if this component is already the first one.Returns the component path for the previous sibling or null if this component is already the last one.com.fasterxml.jackson.databind.JsonNode
getProperty
(String propName) returns a components property as JsonNode.getPropertyAsString
(String propName) Returns the property value as string, as it is saved at the moment on the server.String[]
getPropertyAsStringArray
(String propName) Returns the property value as string array, as it is saved at the moment on the server.abstract String
The resource type for the component, e.g.org.apache.sling.testing.clients.SlingHttpResponse
Allows reordering of a component in relation to its siblings.org.apache.sling.testing.clients.SlingHttpResponse
save
(int... expectedStatus) Submits all editable values to the server.void
setProperty
(String name, int value) sets a integer to be saved.void
setProperty
(String name, String... value) sets a string or multiple string property to be saved.
-
Field Details
-
changeProperties
Stores the currently set of edited property values -
DEFAULT_LOCATION
Deprecated.- use the component'sgetLocation()
method as this value is not applicable to all websitesThe default location inside a CQ page where the component gets added- See Also:
-
client
Reference to theFoundationClient
that created this instance -
componentPath
The complete path to this component in the repository. -
pagePath
Path to the CQ page that contains this component -
location
relative location inside the page -
jsonNode
protected com.fasterxml.jackson.databind.JsonNode jsonNodecontains the Json Structure as it is currently saved on the server
-
-
Constructor Details
-
AbstractComponent
The constructor stores all the component path information like parentPage, name etc.- Parameters:
client
- The ComponentClient that will be used for sending the requests.pagePath
- path to the page that will contain the component.location
- relative location to the parent node inside the page that will contain the component node.nameHint
- name to be used for the component node. Might get altered by the server if a naming conflict occurs. ThegetName()
method will return the correct name after(order,int...)
has been called.
-
-
Method Details
-
create
public org.apache.sling.testing.clients.SlingHttpResponse create(String order, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException Creates the component on the server by sending the http request.- Parameters:
order
- Defines where the component should be added in relation to its siblings. Possible values arefirst
,last
,before [nodeName]
,after [nodeName]
.expectedStatus
- list of expected HTTP Status to be returned, if not set, 201 is assumed.- Returns:
- Sling response
- Throws:
org.apache.sling.testing.clients.ClientException
- if something fails during the request/response cycleInterruptedException
- to mark this method as waiting
-
getCreateFormEntity
Returns the FormEntityBuilder used for the create request increate(String,int...)
. This method can be overridden in a subclass to extend the parameters that need to sent with the creation request.- Parameters:
order
- Defines where the component should be added in relation to its siblings. Possible values arefirst
,last
,before [nodeName]
,after [nodeName]
.- Returns:
- An FormEntityBuilder with
_charset_
,./sling:resourceType
and:nameHint
set.
-
save
public org.apache.sling.testing.clients.SlingHttpResponse save(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException Submits all editable values to the server. Same as pressing theOK
button on the edit dialog of a component.- Parameters:
expectedStatus
- list of allowed HTTP Status to be returned. if not set, status 200 is assumed- Returns:
- Sling response
- Throws:
org.apache.sling.testing.clients.ClientException
- If something fails during request/response cycleInterruptedException
- to mark this method as waiting
-
reorder
public org.apache.sling.testing.clients.SlingHttpResponse reorder(String order, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException Allows reordering of a component in relation to its siblings.- Parameters:
order
- Defines where the component should be added in relation to its siblings. Possible values arefirst
,last
,before [nodeName]
,after [nodeName]
.expectedStatus
- list of allowed HTTP Status to be returned. if not set, status 200 is assumed- Returns:
- Sling response
- Throws:
org.apache.sling.testing.clients.ClientException
- if posting the reorder failsInterruptedException
- to mark this method as waiting
-
setProperty
sets a string or multiple string property to be saved.- Parameters:
name
- name of the property to set e.g. ./text.value
- the value(s) to be set.
-
setProperty
sets a integer to be saved.- Parameters:
name
- name of the property to set e.g../width
.value
- the value(s) to be set.
-
getPropertyAsString
Returns the property value as string, as it is saved at the moment on the server.- Parameters:
propName
- name of the property- Returns:
- prop value on server or
null
if no such property has been saved yet.
-
getPropertyAsStringArray
Returns the property value as string array, as it is saved at the moment on the server.- Parameters:
propName
- name of the property- Returns:
- value on server or
null
if no such property has been saved yet.
-
getProperty
returns a components property as JsonNode.- Parameters:
propName
- the property to get- Returns:
- jsonNode of the property stored
-
getComponentNode
public com.fasterxml.jackson.databind.JsonNode getComponentNode() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the root node of the component node as a JsonNode- Returns:
- a JsonNode of the component node
- Throws:
org.apache.sling.testing.clients.ClientException
- if something fails during requestInterruptedException
- to mark this method as waiting
-
getName
Returns the name of the component node. Gets preset with the nameHint passed in the constructor and updated if required after the create() request.- Returns:
- Component node name
-
getParentPath
Path to the parent node of the component- Returns:
- Node path
-
getComponentPath
The complete path to the component.- Returns:
- node path
-
getPagePath
returns the path to the page that contains the component- Returns:
- page path
-
getLocation
returns the relative path inside the page- Returns:
- relative node path
-
getResourceType
The resource type for the component, e.g. foundation/components/text. this will be set in thesling:resourceType
property of the node.- Returns:
- the resource type
-
getClient
Returns the client that created this component.- Returns:
- the Component Client
-
getNext
public <T extends AbstractComponent> T getNext() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the component wrapper instance for the following sibling or null if this component is already the last one. It looks for the sling:resourceType property an tries to find a matching component wrapper that has been registered with the ComponentClient (seeComponentClient.registerComponent(String, Class)
)- Type Parameters:
T
- component type- Returns:
- A component wrapper instance or null if the node has no or an unknown resource type.
- Throws:
org.apache.sling.testing.clients.ClientException
- if something goes wrong during request/response of json.InterruptedException
- to mark this method as waiting
-
getNextNodePath
public String getNextNodePath() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the component path for the following sibling or null if this component is already the last one.- Returns:
- The component path to the following sibling.
- Throws:
org.apache.sling.testing.clients.ClientException
- if something goes wrong during request/response of json.InterruptedException
- to mark this method as waiting
-
getFirstChild
public <T extends AbstractComponent> T getFirstChild() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionreturns the first child node that is a component or null if not found.- Type Parameters:
T
- a subclass of AbstractComponent- Returns:
- an Component wrapper or null if it has no child components or the component type is unknown
- Throws:
org.apache.sling.testing.clients.ClientException
- if requesting json fails.InterruptedException
- to mark this method as waiting
-
getPrevious
public <T extends AbstractComponent> T getPrevious() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the component wrapper instance for the previous sibling or null if this component is already the first one. It looks for the sling:resourceType property an tries to find a matching component wrapper that has been registered with the ComponentClient (seeComponentClient.registerComponent(String, Class)
)- Type Parameters:
T
- component type- Returns:
- A component wrapper instance or null if the node has no or an unknown resource type.
- Throws:
org.apache.sling.testing.clients.ClientException
- if something goes wrong during request/response of jsonInterruptedException
- to mark this method as waiting
-
getPreviousNodePath
public String getPreviousNodePath() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the component path for the previous sibling or null if this component is already the last one.- Returns:
- The component path to the following sibling.
- Throws:
org.apache.sling.testing.clients.ClientException
- if something goes wrong during request/response of json.InterruptedException
- to mark this method as waiting
-
getLocation()
method as this value is not applicable to all websites