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