Class 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 Detail

      • uniquePathPart

        protected final String uniquePathPart
    • Constructor Detail

      • UniqueRoot

        protected UniqueRoot​(@NotNull
                             @NotNull SlingContextImpl context)
    • Method Detail

      • 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