Mocking AEM Asset Manager using WCM IO
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);
}