Class TestContentBuilder


  • public final class TestContentBuilder
    extends java.lang.Object
    Helper to build TestContent structure mainly. - /conf/{someprefix}_[randomSuffix]/....(*) - /content/{someprefix}_[randomSuffix]/ (as folder) - /content/dam/{someprefix}_[randomSuffix]/ (as folder) - /content/cq:tag/{someprefix}_[randomSuffix] - /home/groups/{someprefix}_[randomSuffix]/... (as intermediate path) - /home/users/{someprefix}_[randomSuffix]/... (as intermediate path) (*) **Note**: /conf can include a default page template, content fragment structure model, and content fragment template. Call the related **enable** methods. A [TestContentBuilder.dispose()](#dispose--) method is used to cleanup all those paths, as well as the associated /var/audit/... .
    • Constructor Detail

      • TestContentBuilder

        public TestContentBuilder​(com.adobe.cq.testing.client.CQClient cqClient,
                                  java.lang.String prefix)
        Parameters:
        cqClient - used to perform all operations, make sure it has all permissions to perform necessary operations (i.e administrator).
        prefix - used to prefix a randomSmallText() for generated path.
    • Method Detail

      • getLabel

        public java.lang.String getLabel()
        Returns:
        the generated initial {prefix}_[randomSuffix] value.
      • getParentTag

        public java.lang.String getParentTag()
      • getConfigPath

        public java.lang.String getConfigPath()
      • getDefaultPageTemplatePath

        public java.lang.String getDefaultPageTemplatePath()
      • getTopLevelComponentPath

        public java.lang.String getTopLevelComponentPath()
      • getDamRootPath

        public java.lang.String getDamRootPath()
      • getContentRootPath

        public java.lang.String getContentRootPath()
        Returns:
        /content/{someprefix}_[randomSuffix]/
      • withConfigCapabilities

        public TestContentBuilder withConfigCapabilities​(com.adobe.cq.testing.client.CQConfigManagerClient.CQConfigCapability... capabilities)
      • withPageTemplateTitle

        public TestContentBuilder withPageTemplateTitle​(java.lang.String title)
      • withPageTemplateDescription

        public TestContentBuilder withPageTemplateDescription​(java.lang.String description)
      • withUser

        public TestContentBuilder withUser​(java.lang.String password,
                                           java.util.List<java.lang.String> groups)
      • withImpersonator

        public TestContentBuilder withImpersonator​(java.lang.String impersonator)
      • dispose

        public void dispose()
                     throws TestContentBuilder.TestContentBuilderException
        - To be called when test content is no longer required. Usually in an after test handler. See also [TestContentExtension](../junit5/extension/TestContentExtension.html). - It will clean from all the root paths created, and it will also include the related /var/audits/... . To make sure it doesn't leave garbages there as well.
        Throws:
        TestContentBuilder.TestContentBuilderException - in case of any issues while disposing of content.
      • cleanupAudit

        public void cleanupAudit​(java.lang.String path)
      • build

        public void build()
                   throws org.apache.sling.testing.clients.ClientException,
                          java.lang.InterruptedException,
                          java.io.IOException,
                          java.util.concurrent.TimeoutException
        Perform the write operations to the AEM instance via provided CQClient to build up the **TestContent**. See constructor [TestContentBuilder](#TestContentBuilder-com.adobe.cq.testing.client.CQClient-java.lang.String-).
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        java.lang.InterruptedException - if waiting was interrupted
        java.io.IOException - if json parsing fails
        java.util.concurrent.TimeoutException
      • createUniqueUser

        public com.adobe.cq.testing.client.security.User createUniqueUser​(java.lang.String username,
                                                                          java.lang.String password,
                                                                          java.lang.String... groups)
                                                                   throws org.apache.sling.testing.clients.ClientException,
                                                                          java.lang.InterruptedException
        Throws:
        org.apache.sling.testing.clients.ClientException
        java.lang.InterruptedException
      • randomSmallText

        public static java.lang.String randomSmallText()
      • randomSmallTextSearch

        public static java.lang.String randomSmallTextSearch()
      • randomSmallTestLabel

        public static java.lang.String randomSmallTestLabel()
      • randomSmallTestTitle

        public static java.lang.String randomSmallTestTitle()
      • getUser

        public com.adobe.cq.testing.client.security.User getUser()
        Returns:
        generated user authorizable.
      • getUserName

        public java.lang.String getUserName()
        Returns:
        authorizable ID of the generated user.
      • getUserHomePath

        public java.lang.String getUserHomePath()
        Returns:
        authorizable path of the generated user in the repository.
      • createGroup

        public com.adobe.cq.testing.client.security.Group createGroup​(java.lang.String groupPrefix)
                                                               throws org.apache.sling.testing.clients.ClientException,
                                                                      java.lang.InterruptedException
        Throws:
        org.apache.sling.testing.clients.ClientException
        java.lang.InterruptedException
      • deleteUser

        public void deleteUser​(com.adobe.cq.testing.client.security.User user,
                               java.lang.String... groups)
                        throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
      • getClient

        public com.adobe.cq.testing.client.CQClient getClient()
        See constructor [TestContentBuilder](#TestContentBuilder-com.adobe.cq.testing.client.CQClient-java.lang.String-).
        Returns:
        original constructor client.
      • getDefaultUserClient

        public com.adobe.cq.testing.client.CQClient getDefaultUserClient()
                                                                  throws org.apache.sling.testing.clients.ClientException
        Returns:
        client based on the generated authorizable. See also [withUser](#withUser-java.lang.String-java.util.List-).
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
      • getUserClient

        public com.adobe.cq.testing.client.CQClient getUserClient​(com.adobe.cq.testing.client.security.User user,
                                                                  java.lang.String password)
                                                           throws org.apache.sling.testing.clients.ClientException
        Parameters:
        user - User instance for the user for which CQClient needs to be generated
        password - password for the user
        Returns:
        client based on the generated authorizable. See also [withUser](#withUser-java.lang.String-java.util.List-).
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
      • getAffinityCookie

        public org.apache.http.cookie.Cookie getAffinityCookie()
        Returns:
        the current affinity cookie if available on client, null otherwise.
      • getAffinity

        public java.lang.String getAffinity()
        Returns:
        the current affinity value if available on client, null otherwise.
      • getCqSecurityClient

        public com.adobe.cq.testing.client.CQSecurityClient getCqSecurityClient()
                                                                         throws org.apache.sling.testing.clients.ClientException
        Returns:
        client based on the constructor CQClient.
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails