Class AbstractComponent

    • 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's getLocation() method as this value is not applicable to all websites
        The default location inside a CQ page where the component gets added
        See Also:
        Constant Field Values
      • 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. The getName() 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 are first, 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 cycle
        InterruptedException - 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 in create(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 are first, 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 the OK 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 cycle
        InterruptedException - 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 are first, 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 fails
        InterruptedException - 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 null if 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 null if 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,
                                                                        InterruptedException
        Returns 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 request
        InterruptedException - 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 the sling:resourceType property 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 (see ComponentClient.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 (see ComponentClient.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
      • 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