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
public abstract class AbstractComponent extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<String,String[]>changePropertiesStores the currently set of edited property valuesprotected ComponentClientclientReference to theFoundationClientthat created this instanceprotected StringcomponentPathThe complete path to this component in the repository.static StringDEFAULT_LOCATIONDeprecated.- use the component'sgetLocation()method as this value is not applicable to all websitesprotected com.fasterxml.jackson.databind.JsonNodejsonNodecontains the Json Structure as it is currently saved on the serverprotected Stringlocationrelative location inside the pageprotected StringpagePathPath to the CQ page that contains this component
-
Constructor Summary
Constructors Constructor Description AbstractComponent(ComponentClient client, String pagePath, String location, String nameHint)The constructor stores all the component path information like parentPage, name etc.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description org.apache.sling.testing.clients.SlingHttpResponsecreate(String order, int... expectedStatus)Creates the component on the server by sending the http request.ComponentClientgetClient()Returns the client that created this component.com.fasterxml.jackson.databind.JsonNodegetComponentNode()Returns the root node of the component node as a JsonNodeStringgetComponentPath()The complete path to the component.org.apache.sling.testing.clients.util.FormEntityBuildergetCreateFormEntity(String order)Returns the FormEntityBuilder used for the create request increate(String,int...).<T extends AbstractComponent>
TgetFirstChild()returns the first child node that is a component or null if not found.StringgetLocation()returns the relative path inside the pageStringgetName()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.StringgetNextNodePath()Returns the component path for the following sibling or null if this component is already the last one.StringgetPagePath()returns the path to the page that contains the componentStringgetParentPath()Path to the parent node of the component<T extends AbstractComponent>
TgetPrevious()Returns the component wrapper instance for the previous sibling or null if this component is already the first one.StringgetPreviousNodePath()Returns the component path for the previous sibling or null if this component is already the last one.com.fasterxml.jackson.databind.JsonNodegetProperty(String propName)returns a components property as JsonNode.StringgetPropertyAsString(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 StringgetResourceType()The resource type for the component, e.g.org.apache.sling.testing.clients.SlingHttpResponsereorder(String order, int... expectedStatus)Allows reordering of a component in relation to its siblings.org.apache.sling.testing.clients.SlingHttpResponsesave(int... expectedStatus)Submits all editable values to the server.voidsetProperty(String name, int value)sets a integer to be saved.voidsetProperty(String name, String... value)sets a string or multiple string property to be saved.
-
-
-
Field Detail
-
changeProperties
protected HashMap<String,String[]> changeProperties
Stores the currently set of edited property values
-
DEFAULT_LOCATION
@Deprecated public static final String 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:
- Constant Field Values
-
client
protected ComponentClient client
Reference to theFoundationClientthat created this instance
-
componentPath
protected String componentPath
The complete path to this component in the repository.
-
pagePath
protected String pagePath
Path to the CQ page that contains this component
-
location
protected String location
relative location inside the page
-
jsonNode
protected com.fasterxml.jackson.databind.JsonNode jsonNode
contains the Json Structure as it is currently saved on the server
-
-
Constructor Detail
-
AbstractComponent
public AbstractComponent(ComponentClient client, String pagePath, String location, String nameHint)
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 Detail
-
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
public org.apache.sling.testing.clients.util.FormEntityBuilder getCreateFormEntity(String order)
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:resourceTypeand:nameHintset.
-
save
public org.apache.sling.testing.clients.SlingHttpResponse save(int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionSubmits all editable values to the server. Same as pressing theOKbutton 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
public void setProperty(String name, String... value)
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
public void setProperty(String name, int value)
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
public String getPropertyAsString(String propName)
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
nullif no such property has been saved yet.
-
getPropertyAsStringArray
public String[] getPropertyAsStringArray(String propName)
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
nullif no such property has been saved yet.
-
getProperty
public com.fasterxml.jackson.databind.JsonNode getProperty(String propName)
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
public String 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
public String getParentPath()
Path to the parent node of the component- Returns:
- Node path
-
getComponentPath
public String getComponentPath()
The complete path to the component.- Returns:
- node path
-
getPagePath
public String getPagePath()
returns the path to the page that contains the component- Returns:
- page path
-
getLocation
public String getLocation()
returns the relative path inside the page- Returns:
- relative node path
-
getResourceType
public abstract String getResourceType()
The resource type for the component, e.g. foundation/components/text. this will be set in thesling:resourceTypeproperty of the node.- Returns:
- the resource type
-
getClient
public ComponentClient 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, InterruptedException
Returns 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, InterruptedException
Returns 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, InterruptedException
returns 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, InterruptedException
Returns 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, InterruptedException
Returns 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
-
-