Class ContentBuilder


  • @ProviderType
    public final class ContentBuilder
    extends org.apache.sling.testing.mock.sling.builder.ContentBuilder
    Helper class for building test content in the resource hierarchy with as less boilerplate code as possible.
    • Field Summary

      • Fields inherited from class org.apache.sling.testing.mock.sling.builder.ContentBuilder

        resourceResolver
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.day.cq.dam.api.Asset asset​(@NotNull String path, long width, long height, @NotNull String mimeType)
      Create DAM asset with a generated dummy image.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, long width, long height, @NotNull String mimeType, @NotNull Object @NotNull ... metadata)
      Create DAM asset with a generated dummy image.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, long width, long height, @NotNull String mimeType, @Nullable Map<String,​Object> metadata)
      Create DAM asset with a generated dummy image.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull InputStream inputStream, @NotNull String mimeType)
      Create DAM asset.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull InputStream inputStream, @NotNull String mimeType, @NotNull Object @NotNull ... metadata)
      Create DAM asset.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull InputStream inputStream, @NotNull String mimeType, @Nullable Map<String,​Object> metadata)
      Create DAM asset.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull String classpathResource, @NotNull String mimeType)
      Create DAM asset.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull String classpathResource, @NotNull String mimeType, @NotNull Object @NotNull ... metadata)
      Create DAM asset.
      com.day.cq.dam.api.Asset asset​(@NotNull String path, @NotNull String classpathResource, @NotNull String mimeType, @Nullable Map<String,​Object> metadata)
      Create DAM asset.
      com.day.cq.dam.api.Rendition assetRendition​(@NotNull com.day.cq.dam.api.Asset asset, @NotNull String name, long width, long height, @NotNull String mimeType)
      Adds a rendition with a generated dummy image to DAM asset.
      com.day.cq.dam.api.Rendition assetRendition​(@NotNull com.day.cq.dam.api.Asset asset, @NotNull String name, @NotNull String classpathResource, @NotNull String mimeType)
      Adds a rendition to DAM asset.
      com.day.cq.dam.api.Rendition assetRendition​(@NotNull com.day.cq.dam.api.Asset asset, String name, @NotNull InputStream inputStream, @NotNull String mimeType)
      Adds a rendition to DAM asset.
      com.day.cq.dam.api.Rendition assetRenditionWebEnabled​(@NotNull com.day.cq.dam.api.Asset asset)
      Adds a web-enabled rendition to DAM asset.
      com.day.cq.dam.api.Rendition assetRenditionWebEnabled​(@NotNull com.day.cq.dam.api.Asset asset, long maxWidth, long maxHeight)
      Adds a web-enabled rendition to DAM asset.
      com.adobe.cq.dam.cfm.ContentFragment contentFragmentStructured​(@NotNull String path, @NotNull Object @NotNull ... data)
      Create DAM content fragment.
      com.adobe.cq.dam.cfm.ContentFragment contentFragmentStructured​(@NotNull String path, @Nullable Map<String,​Object> data)
      Create DAM content fragment.
      com.adobe.cq.dam.cfm.ContentFragment contentFragmentText​(@NotNull String path, @NotNull String text, @NotNull String mimeType)
      Create DAM content fragment.
      static @NotNull InputStream createDummyImage​(long width, long height, String mimeType)
      Create dummy image
      com.day.cq.wcm.api.Page page​(@NotNull com.day.cq.wcm.api.Page parentPage, @NotNull String name)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull com.day.cq.wcm.api.Page parentPage, @NotNull String name, @Nullable String template)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull com.day.cq.wcm.api.Page parentPage, @NotNull String name, @Nullable String template, @NotNull Object @NotNull ... pageProperties)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull com.day.cq.wcm.api.Page parentPage, @NotNull String name, @Nullable String template, @NotNull String title)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull com.day.cq.wcm.api.Page parentPage, @NotNull String name, @Nullable String template, @NotNull Map<String,​Object> pageProperties)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull String path)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull String path, @Nullable String template)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull String path, @Nullable String template, @NotNull Object @NotNull ... pageProperties)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull String path, @Nullable String template, @NotNull String title)
      Create content page.
      com.day.cq.wcm.api.Page page​(@NotNull String path, @Nullable String template, @NotNull Map<String,​Object> pageProperties)
      Create content page.
      @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull com.day.cq.wcm.api.Page page, @NotNull String name)
      Create child resource below the page's jcr:content resource.
      @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull com.day.cq.wcm.api.Page page, @NotNull String name, @NotNull Object @NotNull ... properties)
      Create child resource below the page's jcr:content resource.
      @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull com.day.cq.wcm.api.Page page, @NotNull String name, @NotNull Map<String,​Object> properties)
      Create child resource below the page's jcr:content resource.
      com.day.cq.tagging.Tag tag​(@NotNull String tagId)
      Adds a tag definition.
      • Methods inherited from class org.apache.sling.testing.mock.sling.builder.ContentBuilder

        ensureResourceExists, resource, resource, resource, resource, resource, resource
    • Constructor Detail

      • ContentBuilder

        public ContentBuilder​(@NotNull
                              @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
        Parameters:
        resourceResolver - Resource resolver
      • ContentBuilder

        public ContentBuilder​(@NotNull
                              @NotNull AemContextImpl context)
        Parameters:
        context - Context
    • Method Detail

      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull String path)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        path - Page path
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull String path,
                                            @Nullable
                                            @Nullable String template)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        path - Page path
        template - Template
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull String path,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull String title)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        path - Page path
        template - Template
        title - Page title
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull String path,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull Map<String,​Object> pageProperties)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        path - Page path
        template - Template
        pageProperties - Properties for jcr:content node.
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull String path,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull Object @NotNull ... pageProperties)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        path - Page path
        template - Template
        pageProperties - Properties for jcr:content node.
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull com.day.cq.wcm.api.Page parentPage,
                                            @NotNull
                                            @NotNull String name)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        parentPage - Parent page of the newp age
        name - Child page name
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull com.day.cq.wcm.api.Page parentPage,
                                            @NotNull
                                            @NotNull String name,
                                            @Nullable
                                            @Nullable String template)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        parentPage - Parent page of the newp age
        name - Child page name
        template - Template
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull com.day.cq.wcm.api.Page parentPage,
                                            @NotNull
                                            @NotNull String name,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull String title)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        parentPage - Parent page of the newp age
        name - Child page name
        template - Template
        title - Page title
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull com.day.cq.wcm.api.Page parentPage,
                                            @NotNull
                                            @NotNull String name,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull Map<String,​Object> pageProperties)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        parentPage - Parent page of the newp age
        name - Child page name
        template - Template
        pageProperties - Properties for jcr:content node.
        Returns:
        Page object
      • page

        public com.day.cq.wcm.api.Page page​(@NotNull
                                            @NotNull com.day.cq.wcm.api.Page parentPage,
                                            @NotNull
                                            @NotNull String name,
                                            @Nullable
                                            @Nullable String template,
                                            @NotNull
                                            @NotNull Object @NotNull ... pageProperties)
        Create content page. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        parentPage - Parent page of the newp age
        name - Child page name
        template - Template
        pageProperties - Properties for jcr:content node.
        Returns:
        Page object
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull String classpathResource,
                                              @NotNull
                                              @NotNull String mimeType)
        Create DAM asset.
        Parameters:
        path - Asset path
        classpathResource - Classpath resource URL for binary file.
        mimeType - Mime type
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull String classpathResource,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @Nullable
                                              @Nullable Map<String,​Object> metadata)
        Create DAM asset.
        Parameters:
        path - Asset path
        classpathResource - Classpath resource URL for binary file.
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull String classpathResource,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @NotNull
                                              @NotNull Object @NotNull ... metadata)
        Create DAM asset.
        Parameters:
        path - Asset path
        classpathResource - Classpath resource URL for binary file.
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              long width,
                                              long height,
                                              @NotNull
                                              @NotNull String mimeType)
        Create DAM asset with a generated dummy image. The image is empty.
        Parameters:
        path - Asset path
        width - Dummy image width
        height - Dummy image height
        mimeType - Mime type
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              long width,
                                              long height,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @Nullable
                                              @Nullable Map<String,​Object> metadata)
        Create DAM asset with a generated dummy image. The image is empty.
        Parameters:
        path - Asset path
        width - Dummy image width
        height - Dummy image height
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              long width,
                                              long height,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @NotNull
                                              @NotNull Object @NotNull ... metadata)
        Create DAM asset with a generated dummy image. The image is empty.
        Parameters:
        path - Asset path
        width - Dummy image width
        height - Dummy image height
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull InputStream inputStream,
                                              @NotNull
                                              @NotNull String mimeType)
        Create DAM asset.
        Parameters:
        path - Asset path
        inputStream - Binary data for original rendition
        mimeType - Mime type
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull InputStream inputStream,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @Nullable
                                              @Nullable Map<String,​Object> metadata)
        Create DAM asset.
        Parameters:
        path - Asset path
        inputStream - Binary data for original rendition
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • asset

        public com.day.cq.dam.api.Asset asset​(@NotNull
                                              @NotNull String path,
                                              @NotNull
                                              @NotNull InputStream inputStream,
                                              @NotNull
                                              @NotNull String mimeType,
                                              @NotNull
                                              @NotNull Object @NotNull ... metadata)
        Create DAM asset.
        Parameters:
        path - Asset path
        inputStream - Binary data for original rendition
        mimeType - Mime type
        metadata - Asset metadata properties
        Returns:
        Asset
      • createDummyImage

        @NotNull
        public static @NotNull InputStream createDummyImage​(long width,
                                                            long height,
                                                            String mimeType)
        Create dummy image
        Parameters:
        width - Width
        height - height
        mimeType - Mime type
        Returns:
        Input stream
      • assetRendition

        public com.day.cq.dam.api.Rendition assetRendition​(@NotNull
                                                           @NotNull com.day.cq.dam.api.Asset asset,
                                                           @NotNull
                                                           @NotNull String name,
                                                           @NotNull
                                                           @NotNull String classpathResource,
                                                           @NotNull
                                                           @NotNull String mimeType)
        Adds a rendition to DAM asset.
        Parameters:
        asset - DAM asset
        name - Rendition name
        classpathResource - Classpath resource URL for binary file.
        mimeType - Mime type
        Returns:
        Rendition
      • assetRendition

        public com.day.cq.dam.api.Rendition assetRendition​(@NotNull
                                                           @NotNull com.day.cq.dam.api.Asset asset,
                                                           @NotNull
                                                           @NotNull String name,
                                                           long width,
                                                           long height,
                                                           @NotNull
                                                           @NotNull String mimeType)
        Adds a rendition with a generated dummy image to DAM asset. The image is empty.
        Parameters:
        asset - DAM asset
        name - Rendition name
        width - Dummy image width
        height - Dummy image height
        mimeType - Mime type
        Returns:
        Rendition
      • assetRendition

        public com.day.cq.dam.api.Rendition assetRendition​(@NotNull
                                                           @NotNull com.day.cq.dam.api.Asset asset,
                                                           String name,
                                                           @NotNull
                                                           @NotNull InputStream inputStream,
                                                           @NotNull
                                                           @NotNull String mimeType)
        Adds a rendition to DAM asset.
        Parameters:
        asset - DAM asset
        name - Rendition name
        inputStream - Binary data for original rendition
        mimeType - Mime type
        Returns:
        Rendition
      • assetRenditionWebEnabled

        public com.day.cq.dam.api.Rendition assetRenditionWebEnabled​(@NotNull
                                                                     @NotNull com.day.cq.dam.api.Asset asset)
        Adds a web-enabled rendition to DAM asset. The rendition has max a width/height of 1280px, but is never bigger then the original rendition.
        Parameters:
        asset - DAM asset
        Returns:
        Rendition
      • assetRenditionWebEnabled

        public com.day.cq.dam.api.Rendition assetRenditionWebEnabled​(@NotNull
                                                                     @NotNull com.day.cq.dam.api.Asset asset,
                                                                     long maxWidth,
                                                                     long maxHeight)
        Adds a web-enabled rendition to DAM asset. The rendition has max the given width/height, but is never bigger then the original rendition.
        Parameters:
        asset - DAM asset
        maxWidth - Max. width
        maxHeight - Max. width
        Returns:
        Rendition
      • contentFragmentStructured

        public com.adobe.cq.dam.cfm.ContentFragment contentFragmentStructured​(@NotNull
                                                                              @NotNull String path,
                                                                              @Nullable
                                                                              @Nullable Map<String,​Object> data)
        Create DAM content fragment.
        Parameters:
        path - Content fragment asset path
        data - Content fragment structured data
        Returns:
        Content fragment
      • contentFragmentStructured

        public com.adobe.cq.dam.cfm.ContentFragment contentFragmentStructured​(@NotNull
                                                                              @NotNull String path,
                                                                              @NotNull
                                                                              @NotNull Object @NotNull ... data)
        Create DAM content fragment.
        Parameters:
        path - Content fragment asset path
        data - Content fragment structured data
        Returns:
        Content fragment
      • contentFragmentText

        public com.adobe.cq.dam.cfm.ContentFragment contentFragmentText​(@NotNull
                                                                        @NotNull String path,
                                                                        @NotNull
                                                                        @NotNull String text,
                                                                        @NotNull
                                                                        @NotNull String mimeType)
        Create DAM content fragment.
        Parameters:
        path - Content fragment asset path
        text - Text value
        mimeType - Mime type of the value
        Returns:
        Content fragment
      • tag

        public com.day.cq.tagging.Tag tag​(@NotNull
                                          @NotNull String tagId)
        Adds a tag definition.
        Parameters:
        tagId - Tag ID. May include namespace (separated by ":"). May include nested levels (separated by "/").
        Returns:
        Tag
      • resource

        @NotNull
        public @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull
                                                                        @NotNull com.day.cq.wcm.api.Page page,
                                                                        @NotNull
                                                                        @NotNull String name)
        Create child resource below the page's jcr:content resource. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        page - Page to create resource in
        name - Child resource name
        Returns:
        Resource object
      • resource

        @NotNull
        public @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull
                                                                        @NotNull com.day.cq.wcm.api.Page page,
                                                                        @NotNull
                                                                        @NotNull String name,
                                                                        @NotNull
                                                                        @NotNull Map<String,​Object> properties)
        Create child resource below the page's jcr:content resource. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        page - Page to create resource in
        name - Child resource name
        properties - Properties for resource.
        Returns:
        Resource object
      • resource

        @NotNull
        public @NotNull org.apache.sling.api.resource.Resource resource​(@NotNull
                                                                        @NotNull com.day.cq.wcm.api.Page page,
                                                                        @NotNull
                                                                        @NotNull String name,
                                                                        @NotNull
                                                                        @NotNull Object @NotNull ... properties)
        Create child resource below the page's jcr:content resource. If parent resource(s) do not exist they are created automatically using nt:unstructured nodes.
        Parameters:
        page - Page to create resource in
        name - Child resource name
        properties - Properties for resource.
        Returns:
        Resource object