### Question:
GenericReportExcelServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { GenericReport report = request.getResource().adaptTo(GenericReport.class); if (report != null) { String title = report.getName(); String fileName = JcrUtil.createValidName(title) + ".xlsx"; Workbook workbook = createSpreadsheet(report); response.setContentType("application/vnd.ms-excel"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); try (ServletOutputStream out = response.getOutputStream()) { workbook.write(out); out.flush(); } catch (Exception ex) { LOG.error("Error generating excel export for "+request.getResource().getPath(), ex); throw ex; } } else { String msg = String.format("Unable to process report stored at %s", request.getResource().getPath()); throw new ServletException(msg); } }    }### Answer:
@Test public void testReport() throws Exception { int numRows = 10; String reportPath = "/var/acs-commons/mcp/instances/junit/jcr:content/report"; ResourceBuilder rb = slingContext.build() .resource(reportPath, "columns", new String[]{"ColumnA", "ColumnB"}, "name", "report", "sling:resourceType", "acs-commons/components/utilities/process-instance/process-generic-report") .resource("rows"); rb.siblingsMode(); for (int i = 1; i <= numRows; i++) { rb.resource("row-" + i, "ColumnA", "abcdef-" + i, "ColumnB", "qwerty-" + i); } MockSlingHttpServletRequest request = slingContext.request(); request.setResource(slingContext.resourceResolver().getResource(reportPath)); MockSlingHttpServletResponse response = slingContext.response(); slingContext.addModelsForClasses(GenericReport.class); GenericReportExcelServlet servlet = new GenericReportExcelServlet(); servlet.doGet(request, response); assertEquals("application/vnd.ms-excel", response.getContentType()); Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(response.getOutput())); Sheet sh = wb.getSheetAt(0); assertEquals(numRows, sh.getLastRowNum()); Row header = sh.getRow(0); assertEquals("Column A", header.getCell(0).getStringCellValue()); assertEquals("Column B", header.getCell(1).getStringCellValue()); for (int i = 1; i <= numRows; i++) { Row row = sh.getRow(i); assertEquals("abcdef-" + i, row.getCell(0).getStringCellValue()); assertEquals("qwerty-" + i, row.getCell(1).getStringCellValue()); } }