PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 159 lines | 116 code | 21 blank | 22 comment | 18 complexity | 29f44bfc289bd21c31adcdc77cc2c67c 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 java.util.Locale;
  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 NumberFormatsTest extends ReportRunner {
  35. @Test
  36. public void testRunReport() throws BirtException, IOException {
  37. debug = false;
  38. InputStream inputStream = runAndRenderReport("NumberFormats.rptdesign", "xlsx");
  39. assertNotNull(inputStream);
  40. try {
  41. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  42. assertNotNull(workbook);
  43. assertEquals( 1, workbook.getNumberOfSheets() );
  44. assertEquals( "Number Formats Test Report", workbook.getSheetAt(0).getSheetName());
  45. Sheet sheet = workbook.getSheetAt(0);
  46. assertEquals(22, this.firstNullRow(sheet));
  47. assertEquals( 3035, sheet.getColumnWidth( 0 ) );
  48. assertEquals( 3913, sheet.getColumnWidth( 1 ) );
  49. assertEquals( 7021, sheet.getColumnWidth( 2 ) );
  50. assertEquals( 4205, sheet.getColumnWidth( 3 ) );
  51. assertEquals( 3474, sheet.getColumnWidth( 4 ) );
  52. assertEquals( 2852, sheet.getColumnWidth( 5 ) );
  53. assertEquals( 3510, sheet.getColumnWidth( 6 ) );
  54. assertEquals( 2889, sheet.getColumnWidth( 7 ) );
  55. assertEquals( 2048, sheet.getColumnWidth( 8 ) );
  56. DataFormatter formatter = new DataFormatter();
  57. Locale locale = Locale.getDefault();
  58. assertEquals( "1", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  59. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(2)));
  60. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(3)));
  61. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(4)));
  62. assertEquals( "false", formatter.formatCellValue(sheet.getRow(1).getCell(5)));
  63. if( locale.getDisplayName().equals( "en-US" ) ) {
  64. assertEquals( "Oct 11, 2019", formatter.formatCellValue(sheet.getRow(1).getCell(6)));
  65. assertEquals( "1:18:46 PM", formatter.formatCellValue(sheet.getRow(1).getCell(7)));
  66. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  67. assertEquals( "11-Oct-2019", formatter.formatCellValue(sheet.getRow(1).getCell(6)));
  68. assertEquals( "13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(7)));
  69. }
  70. assertEquals( "2", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  71. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(2).getCell(2)));
  72. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(2).getCell(3)));
  73. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(2).getCell(4)));
  74. assertEquals( "true", formatter.formatCellValue(sheet.getRow(2).getCell(5)));
  75. if( locale.getDisplayName().equals( "en-US" ) ) {
  76. assertEquals( "Oct 11, 2019", formatter.formatCellValue(sheet.getRow(1).getCell(6)));
  77. assertEquals( "1:18:46 PM", formatter.formatCellValue(sheet.getRow(1).getCell(7)));
  78. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  79. assertEquals( "11-Oct-2019", formatter.formatCellValue(sheet.getRow(1).getCell(6)));
  80. assertEquals( "13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(7)));
  81. }
  82. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(5).getCell(1)));
  83. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(5).getCell(2)));
  84. assertEquals( "£3.14", formatter.formatCellValue(sheet.getRow(5).getCell(3)));
  85. assertEquals( "3.14", formatter.formatCellValue(sheet.getRow(5).getCell(4)));
  86. assertEquals( "314.16%", formatter.formatCellValue(sheet.getRow(5).getCell(5)));
  87. assertEquals( "3.14E00", formatter.formatCellValue(sheet.getRow(5).getCell(6)));
  88. assertEquals( "3.14E00", formatter.formatCellValue(sheet.getRow(5).getCell(7)));
  89. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(6).getCell(1)));
  90. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(6).getCell(2)));
  91. assertEquals( "£6.28", formatter.formatCellValue(sheet.getRow(6).getCell(3)));
  92. assertEquals( "6.28", formatter.formatCellValue(sheet.getRow(6).getCell(4)));
  93. assertEquals( "628.32%", formatter.formatCellValue(sheet.getRow(6).getCell(5)));
  94. assertEquals( "6.28E00", formatter.formatCellValue(sheet.getRow(6).getCell(6)));
  95. assertEquals( "6.28E00", formatter.formatCellValue(sheet.getRow(6).getCell(7)));
  96. assertEquals( "1", formatter.formatCellValue(sheet.getRow(9).getCell(1)));
  97. if( locale.getDisplayName().equals( "en-US" ) ) {
  98. assertEquals( "October 11, 2019 1:18:46 PM", formatter.formatCellValue(sheet.getRow(9).getCell(2)));
  99. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  100. assertEquals( "11 October 2019 13:18:46", formatter.formatCellValue(sheet.getRow(9).getCell(2)));
  101. }
  102. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(9).getCell(3)));
  103. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(9).getCell(4)));
  104. assertEquals( "false", formatter.formatCellValue(sheet.getRow(9).getCell(5)));
  105. if( locale.getDisplayName().equals( "en-US" ) ) {
  106. assertEquals( "10/11/19", formatter.formatCellValue(sheet.getRow(9).getCell(6)));
  107. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  108. assertEquals( "11/10/19", formatter.formatCellValue(sheet.getRow(9).getCell(6)));
  109. }
  110. assertEquals( "13:18", formatter.formatCellValue(sheet.getRow(9).getCell(7)));
  111. assertEquals( "2", formatter.formatCellValue(sheet.getRow(10).getCell(1)));
  112. if( locale.getDisplayName().equals( "en-US" ) ) {
  113. assertEquals( "October 11, 2019 1:18:46 PM", formatter.formatCellValue(sheet.getRow(9).getCell(2)));
  114. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  115. assertEquals( "11 October 2019 13:18:46", formatter.formatCellValue(sheet.getRow(9).getCell(2)));
  116. }
  117. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(10).getCell(3)));
  118. assertEquals( "6.2831853072", formatter.formatCellValue(sheet.getRow(10).getCell(4)));
  119. assertEquals( "true", formatter.formatCellValue(sheet.getRow(10).getCell(5)));
  120. if( locale.getDisplayName().equals( "en-US" ) ) {
  121. assertEquals( "10/11/19", formatter.formatCellValue(sheet.getRow(9).getCell(6)));
  122. } else if( locale.getDisplayName().equals( "en-GB" ) ) {
  123. assertEquals( "11/10/19", formatter.formatCellValue(sheet.getRow(9).getCell(6)));
  124. }
  125. assertEquals( "13:18", formatter.formatCellValue(sheet.getRow(10).getCell(7)));
  126. assertEquals( "MSRP $3.14", formatter.formatCellValue(sheet.getRow(15).getCell(1)));
  127. assertEquals( "_-£* #,##0.00_-;-£* #,##0.00_-;_-£* \"-\"??_-;_-@_-", sheet.getRow(19).getCell(1).getCellStyle().getDataFormatString());
  128. assertEquals( sheet.getRow(18).getCell(2).getStringCellValue(), sheet.getRow(19).getCell(2).getCellStyle().getDataFormatString());
  129. assertEquals( sheet.getRow(18).getCell(3).getStringCellValue(), sheet.getRow(19).getCell(3).getCellStyle().getDataFormatString());
  130. assertEquals( sheet.getRow(18).getCell(4).getStringCellValue(), sheet.getRow(19).getCell(4).getCellStyle().getDataFormatString());
  131. assertEquals( sheet.getRow(18).getCell(5).getStringCellValue(), sheet.getRow(19).getCell(5).getCellStyle().getDataFormatString());
  132. assertEquals( sheet.getRow(18).getCell(6).getStringCellValue(), sheet.getRow(19).getCell(6).getCellStyle().getDataFormatString());
  133. assertEquals( sheet.getRow(18).getCell(7).getStringCellValue(), sheet.getRow(19).getCell(7).getCellStyle().getDataFormatString());
  134. } finally {
  135. inputStream.close();
  136. }
  137. }
  138. }