Expand my Community achievements bar.

Elevate your expertise and be recognized as a true influencer! Nominations for the exclusive Adobe Community Advisor program 2023 are now OPEN.
SOLVED

local repository access with sling resource resolver

Avatar

Not applicable

I like to create test classes which can be started on local system connecting to an AEM repository. To be able to use same code as running inside repository, I need to have a proper ResourceResolver initialized. Of course, inside a running AEM instance, I just get it from the SlingHttpServletRequest. How can I get a ResourceResolver from local test class?

 

Sample code:

ResourceResolver resResolver = ????

PageManager pageMgr = resResolver.adaptTo(PageManager.class);

....

1 Accepted Solution

Avatar

Correct answer by
Level 3

There can be two approach to solve your problem

a) Considering the test class resides inside OSGI, you can inject a reference to this service [1]

b) If you still need a slingRequest Object(from current user session), you can make a rest end point(write all ur test class code in jsp) and hit this rest end point. For this you can refer [2] [3]

[1] http://docs.adobe.com/docs/en/cq/5-5/javadoc/org/apache/sling/api/resource/ResourceResolverFactory.h...

[2] http://sling.apache.org/documentation/development/sling-testing-tools.html

[3] https://svn.apache.org/repos/asf/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/to....

Let me know if you still face any problem.

1 Reply

Avatar

Correct answer by
Level 3

There can be two approach to solve your problem

a) Considering the test class resides inside OSGI, you can inject a reference to this service [1]

b) If you still need a slingRequest Object(from current user session), you can make a rest end point(write all ur test class code in jsp) and hit this rest end point. For this you can refer [2] [3]

[1] http://docs.adobe.com/docs/en/cq/5-5/javadoc/org/apache/sling/api/resource/ResourceResolverFactory.h...

[2] http://sling.apache.org/documentation/development/sling-testing-tools.html

[3] https://svn.apache.org/repos/asf/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/to....

Let me know if you still face any problem.