PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 94 lines | 66 code | 16 blank | 12 comment | 6 complexity | 3e465fb74acc6862bcc47e514ec7c094 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 Issue85Formulae extends ReportRunner {
  25. @Test
  26. public void testRunReport() throws BirtException, IOException {
  27. debug = false;
  28. InputStream inputStream = runAndRenderReport("Issue85Formulae.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(4, this.firstNullRow(sheet));
  37. assertEquals( 3035, sheet.getColumnWidth( 0 ) );
  38. assertEquals( 2157, 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( "B2+B3", formatter.formatCellValue(sheet.getRow(3).getCell(1)));
  73. assertEquals( "D2+D3", formatter.formatCellValue(sheet.getRow(3).getCell(3)));
  74. } finally {
  75. inputStream.close();
  76. }
  77. }
  78. }