PageRenderTime 841ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/SpudSoft BIRT Excel Emitters Tests/src/uk/co/spudsoft/birt/emitters/excel/tests/GridsTests.java

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 89 lines | 56 code | 21 blank | 12 comment | 0 complexity | c32feb0f744686115859362f23d53565 MD5 | raw file
Possible License(s): EPL-1.0
  1. /*************************************************************************************
  2. * Copyright (c) 2011, 2012, 2013 James Talbut.
  3. * jim-emitters@spudsoft.co.uk
  4. *
  5. * All rights reserved. This program and the accompanying materials
  6. * are made available under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution, and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * James Talbut - Initial implementation.
  12. ************************************************************************************/
  13. package uk.co.spudsoft.birt.emitters.excel.tests;
  14. import static org.junit.Assert.assertEquals;
  15. import static org.junit.Assert.assertNotNull;
  16. import java.io.IOException;
  17. import java.io.InputStream;
  18. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  19. import org.apache.poi.ss.usermodel.CellStyle;
  20. import org.apache.poi.ss.usermodel.DataFormatter;
  21. import org.apache.poi.ss.usermodel.Sheet;
  22. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  23. import org.eclipse.birt.core.exception.BirtException;
  24. import org.junit.Test;
  25. public class GridsTests extends ReportRunner {
  26. @Test
  27. public void testRunReportXlsx() throws BirtException, IOException {
  28. InputStream inputStream = runAndRenderReport("CombinedGrid.rptdesign", "xlsx");
  29. assertNotNull(inputStream);
  30. try {
  31. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  32. assertNotNull(workbook);
  33. assertEquals( 1, workbook.getNumberOfSheets() );
  34. assertEquals( "Combined Grid Report", workbook.getSheetAt(0).getSheetName());
  35. Sheet sheet = workbook.getSheetAt(0);
  36. assertEquals( 3, this.firstNullRow(sheet));
  37. DataFormatter formatter = new DataFormatter();
  38. assertEquals( "This is a label\nHeading 1\nThis is text\nHeading 2\nStyles\nBold, Italic, Bold and italic and finally Underline.\n• Oh\n• Dear\nIsle of Mann\nPlain text.\nAnd this is a label", formatter.formatCellValue(sheet.getRow(0).getCell(1)));
  39. assertEquals( CellStyle.ALIGN_GENERAL, sheet.getRow(0).getCell(1).getCellStyle().getAlignment() );
  40. assertEquals( 14, sheet.getRow(0).getCell(1).getRichStringCellValue().numFormattingRuns() );
  41. assertEquals( "Hello", formatter.formatCellValue(sheet.getRow(1).getCell(0)));
  42. assertEquals( "End", formatter.formatCellValue(sheet.getRow(2).getCell(0)));
  43. } finally {
  44. inputStream.close();
  45. }
  46. }
  47. @Test
  48. public void testRunReportXls() throws BirtException, IOException {
  49. InputStream inputStream = runAndRenderReport("CombinedGrid.rptdesign", "xls");
  50. assertNotNull(inputStream);
  51. try {
  52. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  53. assertNotNull(workbook);
  54. assertEquals( 1, workbook.getNumberOfSheets() );
  55. assertEquals( "Combined Grid Report", workbook.getSheetAt(0).getSheetName());
  56. Sheet sheet = workbook.getSheetAt(0);
  57. assertEquals( 3, this.firstNullRow(sheet));
  58. DataFormatter formatter = new DataFormatter();
  59. assertEquals( "This is a label\nHeading 1\nThis is text\nHeading 2\nStyles\nBold, Italic, Bold and italic and finally Underline.\n• Oh\n• Dear\nIsle of Mann\nPlain text.\nAnd this is a label", formatter.formatCellValue(sheet.getRow(0).getCell(1)));
  60. assertEquals( CellStyle.ALIGN_GENERAL, sheet.getRow(0).getCell(1).getCellStyle().getAlignment() );
  61. assertEquals( 13, sheet.getRow(0).getCell(1).getRichStringCellValue().numFormattingRuns() );
  62. assertEquals( "Hello", formatter.formatCellValue(sheet.getRow(1).getCell(0)));
  63. assertEquals( "End", formatter.formatCellValue(sheet.getRow(2).getCell(0)));
  64. } finally {
  65. inputStream.close();
  66. }
  67. }
  68. }