Class MockHelper


  • public class MockHelper
    extends Object
    Helper class to create resources: MockHelper.create(resolver).resource("/libs").p("prop", "value") .resource("sub").p("sub", "hello") .resource(".sameLevel") .resource("/apps").p("foo", "baa").commit()
    • Method Detail

      • create

        @NotNull
        public static @NotNull MockHelper create​(@NotNull
                                                 @NotNull org.apache.sling.api.resource.ResourceResolver resolver)
        Create a new helper
        Parameters:
        resolver - Resource resolver
        Returns:
        this
      • resource

        @NotNull
        public @NotNull MockHelper resource​(@NotNull
                                            @NotNull String path)
        Add a new resource. If the path is relative, this resource is added as a child to the previous resource. If the path is relative and starts with a dot, this resource is added as a peer to the previous resource.
        Parameters:
        path - Resource path
        Returns:
        this
      • p

        @NotNull
        public @NotNull MockHelper p​(@NotNull
                                     @NotNull String name,
                                     @Nullable
                                     @Nullable Object value)
        Add a property to the current resource
        Parameters:
        name - Property name
        value - Property value
        Returns:
        this
      • add

        public void add()
                 throws org.apache.sling.api.resource.PersistenceException
        Finish building and add all resources to the resource tree.
        Throws:
        org.apache.sling.api.resource.PersistenceException - Persistence exception
      • commit

        public void commit()
                    throws org.apache.sling.api.resource.PersistenceException
        Finish building, add all resources to the resource tree and commit changes.
        Throws:
        org.apache.sling.api.resource.PersistenceException - Persistence exception