PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 80 lines | 44 code | 14 blank | 22 comment | 0 complexity | 54e9cc6533d3f8e0e9f1700079c76a76 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 static org.junit.Assert.assertThat;
  27. import static org.hamcrest.Matchers.*;
  28. import java.io.IOException;
  29. import java.io.InputStream;
  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 AutoColWidthsTest extends ReportRunner {
  36. @Test
  37. public void testRunReport() throws BirtException, IOException {
  38. InputStream inputStream = runAndRenderReport("AutoColWidths.rptdesign", "xlsx");
  39. assertNotNull(inputStream);
  40. try {
  41. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  42. assertNotNull(workbook);
  43. assertEquals( 1, workbook.getNumberOfSheets() );
  44. assertEquals( "AutoColWidths Test Report", workbook.getSheetAt(0).getSheetName());
  45. Sheet sheet = workbook.getSheetAt(0);
  46. assertEquals(23, this.firstNullRow(sheet));
  47. assertEquals( 6127, sheet.getColumnWidth( 0 ) );
  48. assertEquals( 2048, sheet.getColumnWidth( 1 ) );
  49. assertEquals( 4999, sheet.getColumnWidth( 2 ) );
  50. assertEquals( 3812, sheet.getColumnWidth( 3 ) );
  51. assertEquals( 3812, sheet.getColumnWidth( 4 ) );
  52. assertEquals( 2048, sheet.getColumnWidth( 5 ) );
  53. assertThat( sheet.getColumnWidth( 6 ), both( greaterThan( 3000 ) ).and( lessThan( 3200 ) ) );
  54. assertThat( sheet.getColumnWidth( 7 ), both( greaterThan( 2100 ) ).and( lessThan( 2900 ) ) );
  55. assertEquals( 2048, sheet.getColumnWidth( 8 ) );
  56. DataFormatter formatter = new DataFormatter();
  57. assertEquals( "1", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  58. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(2).getCell(2)));
  59. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(2).getCell(3)));
  60. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(2).getCell(4)));
  61. assertEquals( "false", formatter.formatCellValue(sheet.getRow(2).getCell(5)));
  62. } finally {
  63. inputStream.close();
  64. }
  65. }
  66. }