PageRenderTime 86ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 86 lines | 53 code | 21 blank | 12 comment | 0 complexity | 72fcbaa936c7a80ef4eed72efeebc351 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 org.apache.poi.hssf.usermodel.HSSFWorkbook;
  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 CurrencyFormatsTest extends ReportRunner {
  25. @Test
  26. public void testRunReportXls() throws BirtException, IOException {
  27. InputStream inputStream = runAndRenderReport("CurrencyFormats.rptdesign", "xls");
  28. assertNotNull(inputStream);
  29. try {
  30. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  31. assertNotNull(workbook);
  32. assertEquals( 1, workbook.getNumberOfSheets() );
  33. assertEquals( "Currency Formats Test Report", workbook.getSheetAt(0).getSheetName());
  34. Sheet sheet = workbook.getSheetAt(0);
  35. assertEquals(5, this.firstNullRow(sheet));
  36. DataFormatter formatter = new DataFormatter();
  37. assertEquals( "Ł3141.59", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  38. assertEquals( "$3141.59", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  39. assertEquals( "Ľ3141.59", formatter.formatCellValue(sheet.getRow(3).getCell(1)));
  40. assertEquals( "€3141.59", formatter.formatCellValue(sheet.getRow(4).getCell(1)));
  41. } finally {
  42. inputStream.close();
  43. }
  44. }
  45. @Test
  46. public void testRunReportXlsx() throws BirtException, IOException {
  47. InputStream inputStream = runAndRenderReport("CurrencyFormats.rptdesign", "xlsx");
  48. assertNotNull(inputStream);
  49. try {
  50. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  51. assertNotNull(workbook);
  52. assertEquals( 1, workbook.getNumberOfSheets() );
  53. assertEquals( "Currency Formats Test Report", workbook.getSheetAt(0).getSheetName());
  54. Sheet sheet = workbook.getSheetAt(0);
  55. assertEquals( 5, this.firstNullRow(sheet));
  56. DataFormatter formatter = new DataFormatter();
  57. assertEquals( "Ł3141.59", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  58. assertEquals( "$3141.59", formatter.formatCellValue(sheet.getRow(2).getCell(1)));
  59. assertEquals( "Ľ3141.59", formatter.formatCellValue(sheet.getRow(3).getCell(1)));
  60. assertEquals( "€3141.59", formatter.formatCellValue(sheet.getRow(4).getCell(1)));
  61. } finally {
  62. inputStream.close();
  63. }
  64. }
  65. }