[
https://issues.apache.org/jira/browse/SLING-12001?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Stefan Seifert closed SLING-12001.
----------------------------------
> Can't use MockFindQueryResources when making use of getServiceResourceResolver
> ------------------------------------------------------------------------------
>
> Key: SLING-12001
> URL: https://issues.apache.org/jira/browse/SLING-12001
> Project: Sling
> Issue Type: Bug
> Components: Testing
> Affects Versions: Testing ResourceResolver Mock 1.4.2
> Reporter: Robin Brouns
> Assignee: Stefan Seifert
> Priority: Major
> Fix For: Testing ResourceResolver Mock 1.4.4
>
>
> I want to mock resourceResolver.findResources and found that there is a way
> to do this via
> [https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/blob/master/src/main/java/org/apache/sling/testing/resourceresolver/MockFindQueryResources.java#L43]
>
> {code:java}
> MockFindQueryResources.addFindResourceHandler(...) {code}
> This works as long as the Sling Context its Resource Resolver
> (context.resourceResolver()) is used. But we have a piece of code, which uses
> a Service Resource Resolver:
> {code:java}
> private ResourceResolver getServiceResolver() throws LoginException {
> return resourceResolverFactory.getServiceResourceResolver(
> Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
> CLEAN_UP_SERVICE_NAME)
> );
> }{code}
> We can't mock the findResources method for this Service Resource Resolver, as
> the ResourceResolverFactory *always* internally creates a new
> MockResourceResolver object (see
> [https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/blob/master/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolverFactory.java#L102)].
>
> This means that *all* of the in memory changes like
> * findResourcesHandlers
> * queryResourcesHandlers
> * ...
> are lost, so MockFindQueryResources can't be used, because we can't get the
> service resolver from the context (because it is always a new object).
> Same holds true for
> MockResourceResolverFactory.getAdministrativeResourceResolver(...).
> Is it maybe an idea to add functionality to register the Resource Handlers on
> the MockResourceResolverFactory, which is able to pass them down to the
> MockResourceResolver on creation?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)