Class ComponentClient

    • Constructor Detail

      • ComponentClient

        public ComponentClient​(org.apache.http.impl.client.CloseableHttpClient http,
                               org.apache.sling.testing.clients.SlingClientConfig config)
                        throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
      • ComponentClient

        public ComponentClient​(URI serverUrl,
                               String user,
                               String password)
                        throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
    • Method Detail

      • addComponent

        public <T extends AbstractComponent> T addComponent​(Class<T> componentClass,
                                                            String pagePath,
                                                            int... expectedStatus)
                                                     throws org.apache.sling.testing.clients.ClientException,
                                                            InterruptedException
        Adds a new, empty component to a CQ page. The component is added at the default location in the page inside the page.
        Type Parameters:
        T - A subclass of AbstractComponent
        Parameters:
        componentClass - the AbstractComponent subclass to be created
        pagePath - path to the page where the component gets added
        expectedStatus - list of expected HTTP Status to be returned, if not set, 200 is assumed.
        Returns:
        A instance of the class passed in componentClass
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • addComponent

        public <T extends AbstractComponent> T addComponent​(Class<T> componentClass,
                                                            String pagePath,
                                                            String order,
                                                            int... expectedStatus)
                                                     throws org.apache.sling.testing.clients.ClientException,
                                                            InterruptedException
        Adds a new, empty component to a CQ page. The component is added at the default location in the page inside the page.
        Type Parameters:
        T - A subclass of AbstractComponent
        Parameters:
        componentClass - the AbstractComponent subclass to be created
        pagePath - path to the page where the component gets added
        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, 200 is assumed.
        Returns:
        A instance of the class passed in componentClass
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • addComponent

        public <T extends AbstractComponent> T addComponent​(Class<T> componentClass,
                                                            String pagePath,
                                                            String location,
                                                            String nameHint,
                                                            String order,
                                                            int... expectedStatus)
                                                     throws org.apache.sling.testing.clients.ClientException,
                                                            InterruptedException
        Adds a new, empty component to a CQ page.
        Type Parameters:
        T - A subclass of AbstractComponent
        Parameters:
        componentClass - the AbstractComponent subclass to be created
        pagePath - path to the page where the component gets added
        location - relative path inside the page where the component gets added
        nameHint - proposed node for the new component node. Might get altered if the name if there is already a node with the same name on the same level. AbstractComponent.getName() returns the name as is it is really set.
        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, 200 is assumed.
        Returns:
        An instance of the class passed in componentClass
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • getComponent

        public <T extends AbstractComponent> T getComponent​(String componentPath,
                                                            Class<T> compClass)
                                                     throws org.apache.sling.testing.clients.ClientException
        Initializes an AbstractComponent subclass against an existing foundation component node.
        Type Parameters:
        T - A subclass of AbstractComponent
        Parameters:
        componentPath - complete path to the the repository node that forms the root node of a component. Must contain a property named sling:resourceType referencing a valid component.
        compClass - The component wrapper class to be initialized
        Returns:
        A instance of the class passed in componentClass
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
      • getComponent

        public <T extends AbstractComponent> T getComponent​(String componentPath)
                                                     throws org.apache.sling.testing.clients.ClientException
        Initializes an AbstractComponent subclass against an existing foundation component node. t looks for the sling:resourceType property an tries to find a matching component wrapper that has been registered with the ComponentClient (see registerComponent(String, Class))
        Type Parameters:
        T - A subclass of AbstractComponent
        Parameters:
        componentPath - complete path to the the repository node that forms the root node of a component. Must contain a property named sling:resourceType referencing a valid component.
        Returns:
        A instance of the class passed in componentClass
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
      • registerComponent

        public void registerComponent​(String resourceType,
                                      Class<? extends AbstractComponent> c)
        Use this method to register additional component wrappers with the client. All wrappers from the framework are registered by default. The registered components are used by getComponent(String) to return the correct wrapper for a given component path, and by the AbstractComponent.getNext() and AbstractComponent.getPrevious() to return the next/previous component
        Parameters:
        resourceType - the resource type to register
        c - the corresponding component wrapper class
      • getCompClassByResourceType

        public Class<? extends AbstractComponent> getCompClassByResourceType​(String resourceType)
        Returns the component wrapper class, that has been registered with this resourceType or null if no such resourceType is known. you can register additional component wrappers using registerComponent(String, Class)}.
        Parameters:
        resourceType - resource type to look up
        Returns:
        the corresponding component wrapper class or null if not fund
      • deleteComponent

        public void deleteComponent​(AbstractComponent delComp)
                             throws org.apache.sling.testing.clients.ClientException
        Deletes a component.
        Parameters:
        delComp - The component to delete
        Throws:
        org.apache.sling.testing.clients.ClientException - If the delete request fails
      • deleteComponent

        public void deleteComponent​(String componentPath)
                             throws org.apache.sling.testing.clients.ClientException
        Deletes a component.
        Parameters:
        componentPath - the path to the components node
        Throws:
        org.apache.sling.testing.clients.ClientException - If the delete request fails
      • getDefaultComponentRelativeLocation

        public String getDefaultComponentRelativeLocation()
        Returns:
        the value of the component's default relative location, possibly null
      • setDefaultComponentRelativeLocation

        public void setDefaultComponentRelativeLocation​(String defaultComponentRelativeLocation)
        Sets a new value for the component's default relative location
        Parameters:
        defaultComponentRelativeLocation - the new value for the default component relative location