Hi @All,
Team In my Actual class holds Input Stream, XSSFWorkbook, and am iterating all the Excel column values and getting it via this snippet 'row.getCell(columnNames.get("path")).toString().trim()' code is working fine as expected. When I come to Junits I couldn't able to cover the junits for the complete class. Can anyone help here please. How to write the junits for Excel reading class in AEM?
Thanks,
Imad
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Check below code
private static final String CONTENT_PAGES_PATH = "/content/pages";
protected static final String SHEET_NAME = "Page Meta Data";
protected static final String PATH = "path";
@BeforeEach
public void beforeEach() throws Exception {
ctx.load().json("/com/project/company/export/page-structure.json", CONTENT_PAGES_PATH);
ctx.request().setParameterMap(ImmutableMap.of("paths", new String[]{CONTENT_PAGES_PATH}));
//For reading service user, we created a util
ctx.registerService(Util.class, util);
metaDataExporterService = ctx.registerInjectActivateService(new MetaDataExporterService());
when(util.getSysUserResourceResolver()).thenReturn(ctx.resourceResolver().clone(new HashMap<>()));
}
@test
public void testExcelExportIsCreated() throws Exception {
XSSFWorkbook metaDataWorkbookFromPage =
metaDataExporterService.createMetaDataWorkbookFromPage(CONTENT_PAGES_PATH);
XSSFSheet sheet = metaDataWorkbookFromPage.getSheet(SHEET_NAME);
assertNotNull(sheet);
XSSFRow row = sheet.getRow(0);
assertEquals(PATH, row.getCell(0).toString());
XSSFRow row1 = sheet.getRow(1);
assertEquals("/content/pages/jcr:content", row1.getCell(0).toString());
}
page-structure.json - will have json of /content/pages - dummy pages with jcr:content node for every page.
Hi,
Check below code
private static final String CONTENT_PAGES_PATH = "/content/pages";
protected static final String SHEET_NAME = "Page Meta Data";
protected static final String PATH = "path";
@BeforeEach
public void beforeEach() throws Exception {
ctx.load().json("/com/project/company/export/page-structure.json", CONTENT_PAGES_PATH);
ctx.request().setParameterMap(ImmutableMap.of("paths", new String[]{CONTENT_PAGES_PATH}));
//For reading service user, we created a util
ctx.registerService(Util.class, util);
metaDataExporterService = ctx.registerInjectActivateService(new MetaDataExporterService());
when(util.getSysUserResourceResolver()).thenReturn(ctx.resourceResolver().clone(new HashMap<>()));
}
@test
public void testExcelExportIsCreated() throws Exception {
XSSFWorkbook metaDataWorkbookFromPage =
metaDataExporterService.createMetaDataWorkbookFromPage(CONTENT_PAGES_PATH);
XSSFSheet sheet = metaDataWorkbookFromPage.getSheet(SHEET_NAME);
assertNotNull(sheet);
XSSFRow row = sheet.getRow(0);
assertEquals(PATH, row.getCell(0).toString());
XSSFRow row1 = sheet.getRow(1);
assertEquals("/content/pages/jcr:content", row1.getCell(0).toString());
}
page-structure.json - will have json of /content/pages - dummy pages with jcr:content node for every page.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies