Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Unable to fetch Resource from AemContext : Mockito

Avatar

Avatar
Validate 1
Level 1
smrithig4775845
Level 1

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
smrithig4775845
Level 1

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
smrithig4775845
Level 1

22-09-2017

Hi,

I am new to Mockito. I am trying to write test case for one of the model class.

Here I am using AemContext (io.wcm.testing.mock.aem.junit.AemContext) for initializing the resourceResolver finally fetching the resource.

I am able to get the resource resolver object from AemContext, but then unable to create a test resource using the below code.

private ResourceResolver resResolver;

@Rule

public final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);

resResolver = context.resourceResolver(); //output : org.apache.sling.testing.resourceresolver.MockResourceResolver@4923ab24

resResolver.create(resResolver.getResource("/tmp"), "testpage", Collections.<String, Object> emptyMap()); // throws null pointer exception.

Can someone please guide me how to create resource for unit test cases.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

22-09-2017

See this GEMS session and PDF - it touches on this subject -- From Unit Testing to Integration Test of an AEM Application

Answers (0)