PageRenderTime 72ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 98 lines | 56 code | 20 blank | 22 comment | 0 complexity | f36f6c687daa5a9d57af54224c2e4494 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /*************************************************************
  2. * (C) Copyright 2011, 2012 James Talbut.
  3. * jim-emitters@spudsoft.co.uk
  4. *
  5. * This file is part of The SpudSoft BIRT Excel Emitters.
  6. * The SpudSoft BIRT Excel Emitters are free software: you can
  7. * redistribute them and/or modify them under the terms of the
  8. * GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * The SpudSoft BIRT Excel Emitters are distributed in the hope
  13. * that they will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with the SpudSoft BIRT Excel Emitters.
  20. * If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. *************************************************************/
  23. package uk.co.spudsoft.birt.emitters.excel.tests;
  24. import static org.junit.Assert.assertEquals;
  25. import static org.junit.Assert.assertNotNull;
  26. import java.io.IOException;
  27. import java.io.InputStream;
  28. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  29. import org.apache.poi.ss.usermodel.CellStyle;
  30. import org.apache.poi.ss.usermodel.DataFormatter;
  31. import org.apache.poi.ss.usermodel.Sheet;
  32. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  33. import org.eclipse.birt.core.exception.BirtException;
  34. import org.junit.Test;
  35. public class GridsTests extends ReportRunner {
  36. @Test
  37. public void testRunReportXlsx() throws BirtException, IOException {
  38. InputStream inputStream = runAndRenderReport("CombinedGrid.rptdesign", "xlsx");
  39. assertNotNull(inputStream);
  40. try {
  41. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  42. assertNotNull(workbook);
  43. assertEquals( 1, workbook.getNumberOfSheets() );
  44. assertEquals( "Combined Grid Report", workbook.getSheetAt(0).getSheetName());
  45. Sheet sheet = workbook.getSheetAt(0);
  46. assertEquals( 3, this.firstNullRow(sheet));
  47. DataFormatter formatter = new DataFormatter();
  48. 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)));
  49. assertEquals( CellStyle.ALIGN_GENERAL, sheet.getRow(0).getCell(1).getCellStyle().getAlignment() );
  50. assertEquals( 14, sheet.getRow(0).getCell(1).getRichStringCellValue().numFormattingRuns() );
  51. assertEquals( "Hello", formatter.formatCellValue(sheet.getRow(1).getCell(0)));
  52. assertEquals( "End", formatter.formatCellValue(sheet.getRow(2).getCell(0)));
  53. } finally {
  54. inputStream.close();
  55. }
  56. }
  57. @Test
  58. public void testRunReportXls() throws BirtException, IOException {
  59. InputStream inputStream = runAndRenderReport("CombinedGrid.rptdesign", "xls");
  60. assertNotNull(inputStream);
  61. try {
  62. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  63. assertNotNull(workbook);
  64. assertEquals( 1, workbook.getNumberOfSheets() );
  65. assertEquals( "Combined Grid Report", workbook.getSheetAt(0).getSheetName());
  66. Sheet sheet = workbook.getSheetAt(0);
  67. assertEquals( 3, this.firstNullRow(sheet));
  68. DataFormatter formatter = new DataFormatter();
  69. 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)));
  70. assertEquals( CellStyle.ALIGN_GENERAL, sheet.getRow(0).getCell(1).getCellStyle().getAlignment() );
  71. assertEquals( 13, sheet.getRow(0).getCell(1).getRichStringCellValue().numFormattingRuns() );
  72. assertEquals( "Hello", formatter.formatCellValue(sheet.getRow(1).getCell(0)));
  73. assertEquals( "End", formatter.formatCellValue(sheet.getRow(2).getCell(0)));
  74. } finally {
  75. inputStream.close();
  76. }
  77. }
  78. }