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);
}
Solved! Go to Solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
MOre info on AEM and MOCK - Usage | AEM Mocks
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Views
Likes
Replies