PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 123 lines | 78 code | 24 blank | 21 comment | 0 complexity | e23fdaaf309119075bbf8875b622c6a3 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.hssf.util.HSSFColor;
  20. import org.apache.poi.ss.usermodel.DataFormatter;
  21. import org.apache.poi.ss.usermodel.Sheet;
  22. import org.apache.poi.xssf.usermodel.XSSFColor;
  23. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  24. import org.eclipse.birt.core.exception.BirtException;
  25. import org.junit.Test;
  26. public class BackgroundFormatsTests extends ReportRunner {
  27. @Test
  28. public void testRunReportXlsx() throws BirtException, IOException {
  29. InputStream inputStream = runAndRenderReport("BackgroundColours.rptdesign", "xlsx");
  30. assertNotNull(inputStream);
  31. try {
  32. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  33. assertNotNull(workbook);
  34. assertEquals( 1, workbook.getNumberOfSheets() );
  35. assertEquals( "Background Colours Report", workbook.getSheetAt(0).getSheetName());
  36. Sheet sheet = workbook.getSheetAt(0);
  37. assertEquals( 3, this.firstNullRow(sheet));
  38. DataFormatter formatter = new DataFormatter();
  39. assertEquals( "1", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  40. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(2)));
  41. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(3)));
  42. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(4)));
  43. assertEquals( "false", formatter.formatCellValue(sheet.getRow(1).getCell(5)));
  44. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(0).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  45. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  46. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(2).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  47. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(3).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  48. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(4).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  49. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(5).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  50. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(0).getCell(6).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  51. /*
  52. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(0).getCellStyle().getFillForegroundColorColor()));
  53. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColorColor()));
  54. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(2).getCellStyle().getFillForegroundColorColor()));
  55. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(3).getCellStyle().getFillForegroundColorColor()));
  56. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(4).getCellStyle().getFillForegroundColorColor()));
  57. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(5).getCellStyle().getFillForegroundColorColor()));
  58. assertEquals( null, ((XSSFColor)sheet.getRow(0).getCell(6).getCellStyle().getFillForegroundColorColor()));
  59. */
  60. assertEquals( "FFFF0000", ((XSSFColor)sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  61. assertEquals( "FFFFA500", ((XSSFColor)sheet.getRow(1).getCell(2).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  62. assertEquals( "FFFFFF00", ((XSSFColor)sheet.getRow(1).getCell(3).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  63. assertEquals( "FF008000", ((XSSFColor)sheet.getRow(1).getCell(4).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  64. assertEquals( "FF0000FF", ((XSSFColor)sheet.getRow(1).getCell(5).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  65. assertEquals( "FF800080", ((XSSFColor)sheet.getRow(1).getCell(6).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  66. assertEquals( "FF000000", ((XSSFColor)sheet.getRow(1).getCell(7).getCellStyle().getFillForegroundColorColor()).getARGBHex());
  67. } finally {
  68. inputStream.close();
  69. }
  70. }
  71. @Test
  72. public void testRunReportXls() throws BirtException, IOException {
  73. InputStream inputStream = runAndRenderReport("BackgroundColours.rptdesign", "xls");
  74. assertNotNull(inputStream);
  75. try {
  76. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  77. assertNotNull(workbook);
  78. assertEquals( 1, workbook.getNumberOfSheets() );
  79. assertEquals( "Background Colours Report", workbook.getSheetAt(0).getSheetName());
  80. Sheet sheet = workbook.getSheetAt(0);
  81. assertEquals( 3, this.firstNullRow(sheet));
  82. DataFormatter formatter = new DataFormatter();
  83. assertEquals( "1", formatter.formatCellValue(sheet.getRow(1).getCell(1)));
  84. assertEquals( "2019-10-11 13:18:46", formatter.formatCellValue(sheet.getRow(1).getCell(2)));
  85. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(3)));
  86. assertEquals( "3.1415926536", formatter.formatCellValue(sheet.getRow(1).getCell(4)));
  87. assertEquals( "false", formatter.formatCellValue(sheet.getRow(1).getCell(5)));
  88. assertEquals( "FFFF:0:0", ((HSSFColor)sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColorColor()).getHexString());
  89. assertEquals( "FFFF:A5A5:0", ((HSSFColor)sheet.getRow(1).getCell(2).getCellStyle().getFillForegroundColorColor()).getHexString());
  90. assertEquals( "FFFF:FFFF:0", ((HSSFColor)sheet.getRow(1).getCell(3).getCellStyle().getFillForegroundColorColor()).getHexString());
  91. assertEquals( "0:8080:0", ((HSSFColor)sheet.getRow(1).getCell(4).getCellStyle().getFillForegroundColorColor()).getHexString());
  92. assertEquals( "0:0:FFFF", ((HSSFColor)sheet.getRow(1).getCell(5).getCellStyle().getFillForegroundColorColor()).getHexString());
  93. assertEquals( "8080:0:8080", ((HSSFColor)sheet.getRow(1).getCell(6).getCellStyle().getFillForegroundColorColor()).getHexString());
  94. assertEquals( "0:0:0", ((HSSFColor)sheet.getRow(1).getCell(7).getCellStyle().getFillForegroundColorColor()).getHexString());
  95. } finally {
  96. inputStream.close();
  97. }
  98. }
  99. }