Class MockJcr
- java.lang.Object
-
- org.apache.sling.testing.mock.jcr.MockJcr
-
@ConsumerType public final class MockJcr extends Object
Factory for mock JCR objects.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_USER_IDDefault user idstatic StringDEFAULT_WORKSPACEDefault workspace name
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddQueryResultHandler(@NotNull javax.jcr.query.QueryManager queryManager, @NotNull MockQueryResultHandler resultHandler)Adds a query result handler for the given query manager which may return query results for certain queries that are executed.static voidaddQueryResultHandler(@NotNull javax.jcr.Session session, @NotNull MockQueryResultHandler resultHandler)Adds a query result handler for the given query manager which may return query results for certain queries that are executed.static @NotNull javax.jcr.RepositorynewRepository()Create a new mocked in-memory JCR repository.static @NotNull javax.jcr.SessionnewSession()Create a new mocked in-memory JCR session.static @NotNull javax.jcr.SessionnewSession(@Nullable String userId, @Nullable String workspaceName)Create a new mocked in-memory JCR session.static voidsetQueryResult(@NotNull javax.jcr.query.QueryManager queryManager, @NotNull String statement, @NotNull String language, @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries with the given statement executed with the given query manager.static voidsetQueryResult(@NotNull javax.jcr.query.QueryManager queryManager, @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries executed with the given query manager.static voidsetQueryResult(@NotNull javax.jcr.Session session, @NotNull String statement, @NotNull String language, @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries with the given statement executed with the given query manager.static voidsetQueryResult(@NotNull javax.jcr.Session session, @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries executed with the given query manager.
-
-
-
Field Detail
-
DEFAULT_WORKSPACE
public static final String DEFAULT_WORKSPACE
Default workspace name- See Also:
- Constant Field Values
-
DEFAULT_USER_ID
public static final String DEFAULT_USER_ID
Default user id- See Also:
- Constant Field Values
-
-
Method Detail
-
newRepository
@NotNull public static @NotNull javax.jcr.Repository newRepository()
Create a new mocked in-memory JCR repository. Beware: each session has its own data store.- Returns:
- JCR repository
-
newSession
@NotNull public static @NotNull javax.jcr.Session newSession()
Create a new mocked in-memory JCR session. It contains only the root node. All data of the session is thrown away if it gets garbage collected.- Returns:
- JCR session
-
newSession
@NotNull public static @NotNull javax.jcr.Session newSession(@Nullable @Nullable String userId, @Nullable @Nullable String workspaceName)Create a new mocked in-memory JCR session. It contains only the root node. All data of the session is thrown away if it gets garbage collected.- Parameters:
userId- User id for the mock environment. If null a dummy value is used.workspaceName- Workspace name for the mock environment. If null a dummy value is used.- Returns:
- JCR session
-
setQueryResult
public static void setQueryResult(@NotNull @NotNull javax.jcr.Session session, @NotNull @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries executed with the given query manager.- Parameters:
session- JCR sessionresultList- Result list
-
setQueryResult
public static void setQueryResult(@NotNull @NotNull javax.jcr.query.QueryManager queryManager, @NotNull @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries executed with the given query manager.- Parameters:
queryManager- Mocked query managerresultList- Result list
-
setQueryResult
public static void setQueryResult(@NotNull @NotNull javax.jcr.Session session, @NotNull @NotNull String statement, @NotNull @NotNull String language, @NotNull @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries with the given statement executed with the given query manager.- Parameters:
session- JCR sessionstatement- Query statementlanguage- Query languageresultList- Result list
-
setQueryResult
public static void setQueryResult(@NotNull @NotNull javax.jcr.query.QueryManager queryManager, @NotNull @NotNull String statement, @NotNull @NotNull String language, @NotNull @NotNull List<javax.jcr.Node> resultList)Sets the expected result list for all queries with the given statement executed with the given query manager.- Parameters:
queryManager- Mocked query managerstatement- Query statementlanguage- Query languageresultList- Result list
-
addQueryResultHandler
public static void addQueryResultHandler(@NotNull @NotNull javax.jcr.Session session, @NotNull @NotNull MockQueryResultHandler resultHandler)Adds a query result handler for the given query manager which may return query results for certain queries that are executed.- Parameters:
session- JCR sessionresultHandler- Mock query result handler
-
addQueryResultHandler
public static void addQueryResultHandler(@NotNull @NotNull javax.jcr.query.QueryManager queryManager, @NotNull @NotNull MockQueryResultHandler resultHandler)Adds a query result handler for the given query manager which may return query results for certain queries that are executed.- Parameters:
queryManager- Mocked query managerresultHandler- Mock query result handler
-
-