PageRenderTime 34ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

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