local repository access with sling resource resolver

Avatar

Avatar
Validate 1
Level 1
Oliver-2012
Level 1

Like

1 like

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Oliver-2012
Level 1

Like

1 like

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Oliver-2012
Level 1

15-10-2015

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);

....

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 25
Level 6
Mshajiahmed
Level 6

Likes

15 likes

Total Posts

331 posts

Correct reply

126 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Ignite 5
Ignite 3
View profile

Avatar
Validate 25
Level 6
Mshajiahmed
Level 6

Likes

15 likes

Total Posts

331 posts

Correct reply

126 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Ignite 5
Ignite 3
View profile
Mshajiahmed
Level 6

15-10-2015

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 1
Oliver-2012
Level 1

Like

1 like

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Oliver-2012
Level 1

Like

1 like

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Oliver-2012
Level 1

15-10-2015

thanks for the reply.

I want to run the code outside of the Repository instance (outside of AEM). I don't want to run any tests remotely, i.e. like in a JSP that still resides on the AEM itself.

My goal is just to open a connection to the repository like I can do with JcrUtils.getRepository(). This way I still can connect and operate to any JCR nodes directly. But I like to use the Sling Features (i.e. adaptTo).

Avatar

Avatar
Boost 1
Level 2
rishim22446870
Level 2

Likes

2 likes

Total Posts

32 posts

Correct reply

12 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 10
Affirm 1
View profile

Avatar
Boost 1
Level 2
rishim22446870
Level 2

Likes

2 likes

Total Posts

32 posts

Correct reply

12 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 10
Affirm 1
View profile
rishim22446870
Level 2

15-10-2015

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.