Hi Stefan,

Thanks so much. The JCR_OAK resolver type works brilliantly except for one 
thing. The production code retrieves the ResourceResolver from the 
ResourceResolverFactory explicitly and then closes it explicitly. In practice, 
this causes no problems. Up until now, it caused no problems in our testing 
either, but now it seems the SlingContext is attempting to close an already 
closed ResourceResolver when it cleans up after the test:

java.lang.IllegalStateException: Resource resolver is already closed.

        at 
org.apache.sling.resourceresolver.impl.ResourceResolverImpl.checkClosed(ResourceResolverImpl.java:202)
        at 
org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:826)
        at 
org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:211)

Should we not be closing the ResourceResolver explicitly? Or is there some way 
we can tell sling not to close an already closed resource? Or some other 
solution?

Thanks!

John Kramer 
Manager, AEM Engineer
E-Commerce Web Team
e: john.kra...@panerabread.com <mailto:john.kra...@panera.com>
m: 314-435-2370

On 3/5/20, 12:12, "Stefan Seifert" <sseif...@pro-vision.de> wrote:

    Warning:  This email originated from outside of Panera. Beware of clicking 
links and attachments.
     
    
    if you want to test queries with a real query processor and an oak 
repository underneath you can use sling mocks [1]
    with resource resolver type [2] set to      JCR_OAK.
    
    alternatively you can use sling mocks with one of the "cheaper" resource 
resolver types RESOURCERESOLVER_MOCK, JCR_MOCK and use the methods of MockJcr 
[3] to pass in a query result you expect. in this case the query string itself 
is not evaluated and tested, but you can still test the code that processes the 
result (you are giving in the unit test context).
    
    stefan
    
    
    [1] https://sling.apache.org/documentation/development/sling-mock.html
    [2] 
https://sling.apache.org/documentation/development/sling-mock.html#resource-resolver-types
    [3] 
https://www.javadoc.io/doc/org.apache.sling/org.apache.sling.testing.jcr-mock/latest/org/apache/sling/testing/mock/jcr/MockJcr.html
    
    
    >-----Original Message-----
    >From: John Kramer <john.kra...@panerabread.com>
    >Sent: Thursday, March 5, 2020 6:59 PM
    >To: users@sling.apache.org
    >Subject: MockResourceResolver does not support queries
    >
    >Hey guys,
    >
    >I’m attempting to write a unit test and just found out that
    >org.apache.sling.testing.resourceresolver.MockResourceResolver does not
    >support queries. findResources(String query, String language) throws an
    >UnsupportedOperationException.
    >
    >Is there another mocking utility that does support queries? Have you
    >considered adding support for this?
    >
    >John Kramer
    >Manager, AEM Engineer
    >E-Commerce Web Team
    >e: john.kra...@panerabread.com<mailto:john.kra...@panera.com>
    >m: 314-435-2370
    

Reply via email to