java.lang.Object
org.apache.sling.testing.mock.sling.context.UniqueRoot

@ConsumerType public class UniqueRoot extends Object
Manages unique root paths in JCR repository. This is important for resource resolver types like JCR_JACKRABBIT where the repository is not cleaned for each test run. This class provides unique root paths for each run, and cleans them up when done.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    Unique path part
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    UniqueRoot(@NotNull SlingContextImpl context)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final @NotNull String
    Gets (and creates if required) a unique path at /apps/xxx.
    protected void
    Cleanup is called when the unit test rule completes a unit test run.
    final @NotNull String
    Gets (and creates if required) a unique path at /content/xxx.
    protected final void
    deleteResources(@Nullable org.apache.sling.api.resource.Resource @NotNull ... resources)
    Deletes the given set of resources and commits afterwards.
    protected final org.apache.sling.api.resource.Resource
    getOrCreateResource(@NotNull String path, @NotNull String primaryType)
    Get or create resource with given JCR primary type
    final @NotNull String
    Gets (and creates if required) a unique path at /libs/xxx.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • uniquePathPart

      protected final String uniquePathPart
      Unique path part
  • Constructor Details

    • UniqueRoot

      protected UniqueRoot(@NotNull @NotNull SlingContextImpl context)
      Parameters:
      context - Sling context
  • Method Details

    • getOrCreateResource

      protected final org.apache.sling.api.resource.Resource getOrCreateResource(@NotNull @NotNull String path, @NotNull @NotNull String primaryType)
      Get or create resource with given JCR primary type
      Parameters:
      path - Path
      primaryType - JCR primary type
      Returns:
      Resource (never null)
    • content

      @NotNull public final @NotNull String content()
      Gets (and creates if required) a unique path at /content/xxx. The path (incl. all children) is automatically removed when the unit test completes.
      Returns:
      Unique content path
    • apps

      @NotNull public final @NotNull String apps()
      Gets (and creates if required) a unique path at /apps/xxx. The path (incl. all children) is automatically removed when the unit test completes.
      Returns:
      Unique content path
    • libs

      @NotNull public final @NotNull String libs()
      Gets (and creates if required) a unique path at /libs/xxx. The path (incl. all children) is automatically removed when the unit test completes.
      Returns:
      Unique content path
    • cleanUp

      protected void cleanUp()
      Cleanup is called when the unit test rule completes a unit test run. All resources created have to be removed.
    • deleteResources

      protected final void deleteResources(@Nullable @Nullable org.apache.sling.api.resource.Resource @NotNull ... resources)
      Deletes the given set of resources and commits afterwards.
      Parameters:
      resources - Resources to be deleted