PageRenderTime 56ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 95 lines | 53 code | 20 blank | 22 comment | 0 complexity | d51a3fd735f2796e5b0c7306cf4d491b 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.DataFormatter;
  30. import org.apache.poi.ss.usermodel.Sheet;
  31. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  32. import org.eclipse.birt.core.exception.BirtException;
  33. import org.junit.Test;
  34. public class CurrencyFormatsTest extends ReportRunner {
  35. @Test
  36. public void testRunReportXls() throws BirtException, IOException {
  37. InputStream inputStream = runAndRenderReport("CurrencyFormats.rptdesign", "xls");
  38. assertNotNull(inputStream);
  39. try {
  40. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  41. assertNotNull(workbook);
  42. assertEquals( 1, workbook.getNumberOfSheets() );
  43. assertEquals( "Currency Formats Test Report", workbook.getSheetAt(0).getSheetName());
  44. Sheet sheet = workbook.getSheetAt(0);
  45. assertEquals(5, this.firstNullRow(sheet));
  46. DataFormatter formatter = new DataFormatter();
  47. assertEquals( "£3141.59", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  48. assertEquals( "$3141.59", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  49. assertEquals( "¥3141.59", formatter.formatCellValue(sheet.getRow(3).getCell(1)));
  50. assertEquals( "€3141.59", formatter.formatCellValue(sheet.getRow(4).getCell(1)));
  51. } finally {
  52. inputStream.close();
  53. }
  54. }
  55. @Test
  56. public void testRunReportXlsx() throws BirtException, IOException {
  57. InputStream inputStream = runAndRenderReport("CurrencyFormats.rptdesign", "xlsx");
  58. assertNotNull(inputStream);
  59. try {
  60. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  61. assertNotNull(workbook);
  62. assertEquals( 1, workbook.getNumberOfSheets() );
  63. assertEquals( "Currency Formats Test Report", workbook.getSheetAt(0).getSheetName());
  64. Sheet sheet = workbook.getSheetAt(0);
  65. assertEquals( 5, this.firstNullRow(sheet));
  66. DataFormatter formatter = new DataFormatter();
  67. assertEquals( "£3141.59", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  68. assertEquals( "$3141.59", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  69. assertEquals( "¥3141.59", formatter.formatCellValue(sheet.getRow(3).getCell(1)));
  70. assertEquals( "€3141.59", formatter.formatCellValue(sheet.getRow(4).getCell(1)));
  71. } finally {
  72. inputStream.close();
  73. }
  74. }
  75. }