Mocking AEM Asset Manager using WCM IO | Community
Skip to main content
New Participant
November 4, 2018
Solved

Mocking AEM Asset Manager using WCM IO

  • November 4, 2018
  • 3 replies
  • 2959 views

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);
}
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

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

Reference:- MockAssetManager xref

3 replies

rohit_wAuthor
New Participant
November 6, 2018

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.

smacdonald2008
New Participant
November 5, 2018

MOre info on AEM and MOCK - Usage | AEM Mocks

kautuk_sahni
kautuk_sahniAccepted solution
Employee
November 5, 2018

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

Reference:- MockAssetManager xref

Kautuk Sahni