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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Mocking AEM Asset Manager using WCM IO

Avatar

Level 2

I am creating a sling model which fetched a excel file from the file to read and display data in an AEM component.

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) 
public class OnlineCoursesModel { 
     @Self
     private SlingHttpServletRequest request; 

     @ValueMapValue
     private String filePath; 

     private List<OnlineCourseDTO> onlineCourses; 

     @PostConstruct
     public void init() {
          AssetManager assetManager = request.getResourceResolver().adaptTo(AssetManager.class);
          Asset asset = assetManager.getAsset(filePath); 

          /** Do Something With the Asset **/ 
     }

}

In AEM its working fine, but when I try to use it with the wcm io AEM mocking framework, the assetManager is returning null.

@Test
public void checkIfFileIsRead() {
  context.load().binaryFile(COURSES_EXCEL_FILE, EXCEL_RESOURCE_PATH);
  context.load().json(ONLINE_COURSE_LISTING_AUTHORED, TEST_CONTENT_ROOT);
  resource = context.request();
  undertest = resource.adaptTo(OnlineCoursesModel.class);

  System.out.println(undertest);
}
1 Accepted Solution

Avatar

Correct answer by
Administrator

Seems like this is more of tthe issue of WCM IO.

Reference:- MockAssetManager xref

View solution in original post

3 Replies

Avatar

Correct answer by
Administrator

Seems like this is more of tthe issue of WCM IO.

Reference:- MockAssetManager xref

Avatar

Level 2

Hi kautuksahni

Thanks for the help. Seems you are right.

There is an issue adapting the MockHttpServletRequest provided by the wcm io to com.adobe.granite.asset.api.AssetManager.