PageRenderTime 75ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/ravisanthu0/spudsoft-birt-excel-emitters1
Java | 107 lines | 66 code | 19 blank | 22 comment | 0 complexity | 9559ecafe56daa8125cc84846d3b364c MD5 | raw file
Possible License(s): GPL-3.0
  1. /********************************************************************************
  2. * (C) Copyright 2011, by James Talbut.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  18. * in the United States and other countries.]
  19. ********************************************************************************/
  20. package uk.co.spudsoft.birt.emitters.excel.tests;
  21. import static org.junit.Assert.assertEquals;
  22. import static org.junit.Assert.assertNotNull;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import org.apache.poi.hssf.usermodel.HSSFCell;
  26. import org.apache.poi.hssf.usermodel.HSSFRichTextString;
  27. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  28. import org.apache.poi.ss.usermodel.Sheet;
  29. import org.apache.poi.xssf.usermodel.XSSFCell;
  30. import org.apache.poi.xssf.usermodel.XSSFColor;
  31. import org.apache.poi.xssf.usermodel.XSSFRichTextString;
  32. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  33. import org.eclipse.birt.core.exception.BirtException;
  34. import org.junit.Test;
  35. public class NestedTables2ReportTest extends ReportRunner {
  36. @Test
  37. public void testRunReport() throws BirtException, IOException {
  38. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xlsx");
  39. assertNotNull(inputStream);
  40. try {
  41. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  42. assertNotNull(workbook);
  43. assertEquals( 1, workbook.getNumberOfSheets() );
  44. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  45. Sheet sheet = workbook.getSheetAt(0);
  46. assertEquals(6, firstNullRow(sheet));
  47. assertEquals( "1\n2\n3", sheet.getRow(0).getCell(0).getStringCellValue());
  48. assertEquals( "1\n2\n3", sheet.getRow(0).getCell(1).getStringCellValue());
  49. XSSFColor bgColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillForegroundColorColor();
  50. assertEquals( "FFFFFFFF", bgColour.getARGBHex() );
  51. // assertEquals( null, bgColour );
  52. XSSFColor baseColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFont().getXSSFColor();
  53. assertEquals( "FFFFFFFF", baseColour.getARGBHex() );
  54. // assertTrue( !bgColour.equals( baseColour ) );
  55. XSSFRichTextString rich = (XSSFRichTextString)sheet.getRow(0).getCell(0).getRichStringCellValue();
  56. assertEquals( 2, rich.numFormattingRuns() );
  57. assertEquals( 5, rich.getString().length() );
  58. } finally {
  59. inputStream.close();
  60. }
  61. }
  62. @Test
  63. public void testRunReportXls() throws BirtException, IOException {
  64. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xls");
  65. assertNotNull(inputStream);
  66. try {
  67. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  68. assertNotNull(workbook);
  69. assertEquals( 1, workbook.getNumberOfSheets() );
  70. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  71. Sheet sheet = workbook.getSheetAt(0);
  72. assertEquals(6, firstNullRow(sheet));
  73. assertEquals( "1\n2\n3", sheet.getRow(0).getCell(0).getStringCellValue());
  74. assertEquals( "1\n2\n3", sheet.getRow(0).getCell(1).getStringCellValue());
  75. short bgColour = ((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillBackgroundColor();
  76. assertEquals( "0:0:0", workbook.getCustomPalette().getColor(bgColour).getHexString() );
  77. short baseColour = workbook.getFontAt(((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFontIndex()).getColor();
  78. assertEquals( "0:0:0", workbook.getCustomPalette().getColor(baseColour).getHexString() );
  79. // Someone else can explain how it makes sense for these two to need to be the same, given that the result is them being different!
  80. assertEquals( workbook.getCustomPalette().getColor(bgColour).getHexString(), workbook.getCustomPalette().getColor(baseColour).getHexString() );
  81. HSSFRichTextString rich = (HSSFRichTextString)sheet.getRow(0).getCell(0).getRichStringCellValue();
  82. assertEquals( 1, rich.numFormattingRuns() );
  83. assertEquals( 5, rich.getString().length() );
  84. } finally {
  85. inputStream.close();
  86. }
  87. }
  88. }