Class UniqueRoot
java.lang.Object
org.apache.sling.testing.mock.sling.context.UniqueRoot
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull String
apps()
Gets (and creates if required) a unique path at/apps/xxx
.protected void
cleanUp()
Cleanup is called when the unit test rule completes a unit test run.final @NotNull String
content()
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 typefinal @NotNull String
libs()
Gets (and creates if required) a unique path at/libs/xxx
.
-
Field Details
-
uniquePathPart
Unique path part
-
-
Constructor Details
-
UniqueRoot
- 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
- PathprimaryType
- JCR primary type- Returns:
- Resource (never null)
-
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
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
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
-