PageRenderTime 59ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 152 lines | 107 code | 23 blank | 22 comment | 0 complexity | 3ce082d2aba3730499aa32cba02af2cc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /*************************************************************
  2. * (C) Copyright 2011, 2012 James Talbut.
  3. * jim-emitters@spudsoft.co.uk
  4. *
  5. * This file is part of The SpudSoft BIRT Excel Emitters.
  6. * The SpudSoft BIRT Excel Emitters are free software: you can
  7. * redistribute them and/or modify them under the terms of the
  8. * GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * The SpudSoft BIRT Excel Emitters are distributed in the hope
  13. * that they will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with the SpudSoft BIRT Excel Emitters.
  20. * If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. *************************************************************/
  23. package uk.co.spudsoft.birt.emitters.excel.tests;
  24. import static org.junit.Assert.assertEquals;
  25. import static org.junit.Assert.assertNotNull;
  26. import java.io.IOException;
  27. import java.io.InputStream;
  28. import org.apache.poi.hssf.usermodel.HSSFCell;
  29. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  30. import org.apache.poi.ss.usermodel.Sheet;
  31. import org.apache.poi.xssf.usermodel.XSSFCell;
  32. import org.apache.poi.xssf.usermodel.XSSFColor;
  33. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  34. import org.eclipse.birt.core.exception.BirtException;
  35. import org.junit.Test;
  36. public class NestedTables2ReportTest extends ReportRunner {
  37. @Test
  38. public void testRunReport() throws BirtException, IOException {
  39. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xlsx");
  40. assertNotNull(inputStream);
  41. try {
  42. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  43. assertNotNull(workbook);
  44. assertEquals( 1, workbook.getNumberOfSheets() );
  45. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  46. Sheet sheet = workbook.getSheetAt(0);
  47. assertEquals(12, firstNullRow(sheet));
  48. assertEquals( 1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0 );
  49. assertEquals( 1, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0 );
  50. assertEquals( 2, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0 );
  51. assertEquals( 2, sheet.getRow(1).getCell(1).getNumericCellValue(), 0.0 );
  52. assertEquals( 3, sheet.getRow(2).getCell(0).getNumericCellValue(), 0.0 );
  53. assertEquals( 3, sheet.getRow(2).getCell(1).getNumericCellValue(), 0.0 );
  54. assertEquals( 1, sheet.getRow(3).getCell(0).getNumericCellValue(), 0.0 );
  55. assertEquals( 2, sheet.getRow(3).getCell(1).getNumericCellValue(), 0.0 );
  56. assertEquals( 3, sheet.getRow(3).getCell(2).getNumericCellValue(), 0.0 );
  57. assertEquals( 2, sheet.getRow(4).getCell(0).getNumericCellValue(), 0.0 );
  58. assertEquals( 2, sheet.getRow(4).getCell(1).getNumericCellValue(), 0.0 );
  59. assertEquals( 4, sheet.getRow(5).getCell(0).getNumericCellValue(), 0.0 );
  60. assertEquals( 4, sheet.getRow(5).getCell(1).getNumericCellValue(), 0.0 );
  61. assertEquals( 6, sheet.getRow(6).getCell(0).getNumericCellValue(), 0.0 );
  62. assertEquals( 6, sheet.getRow(6).getCell(1).getNumericCellValue(), 0.0 );
  63. assertEquals( 2, sheet.getRow(7).getCell(0).getNumericCellValue(), 0.0 );
  64. assertEquals( 4, sheet.getRow(7).getCell(1).getNumericCellValue(), 0.0 );
  65. assertEquals( 6, sheet.getRow(7).getCell(2).getNumericCellValue(), 0.0 );
  66. assertEquals( 3, sheet.getRow(8).getCell(0).getNumericCellValue(), 0.0 );
  67. assertEquals( 3, sheet.getRow(8).getCell(1).getNumericCellValue(), 0.0 );
  68. assertEquals( 6, sheet.getRow(9).getCell(0).getNumericCellValue(), 0.0 );
  69. assertEquals( 6, sheet.getRow(9).getCell(1).getNumericCellValue(), 0.0 );
  70. assertEquals( 9, sheet.getRow(10).getCell(0).getNumericCellValue(), 0.0 );
  71. assertEquals( 9, sheet.getRow(10).getCell(1).getNumericCellValue(), 0.0 );
  72. assertEquals( 3, sheet.getRow(11).getCell(0).getNumericCellValue(), 0.0 );
  73. assertEquals( 6, sheet.getRow(11).getCell(1).getNumericCellValue(), 0.0 );
  74. assertEquals( 9, sheet.getRow(11).getCell(2).getNumericCellValue(), 0.0 );
  75. XSSFColor bgColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillForegroundColorColor();
  76. assertEquals( "FF800000", bgColour.getARGBHex() );
  77. XSSFColor baseColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFont().getXSSFColor();
  78. assertEquals( "FF000000", baseColour.getARGBHex() );
  79. } finally {
  80. inputStream.close();
  81. }
  82. }
  83. @Test
  84. public void testRunReportXls() throws BirtException, IOException {
  85. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xls");
  86. assertNotNull(inputStream);
  87. try {
  88. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  89. assertNotNull(workbook);
  90. assertEquals( 1, workbook.getNumberOfSheets() );
  91. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  92. Sheet sheet = workbook.getSheetAt(0);
  93. assertEquals(12, firstNullRow(sheet));
  94. assertEquals( 1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0 );
  95. assertEquals( 1, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0 );
  96. assertEquals( 2, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0 );
  97. assertEquals( 2, sheet.getRow(1).getCell(1).getNumericCellValue(), 0.0 );
  98. assertEquals( 3, sheet.getRow(2).getCell(0).getNumericCellValue(), 0.0 );
  99. assertEquals( 3, sheet.getRow(2).getCell(1).getNumericCellValue(), 0.0 );
  100. assertEquals( 1, sheet.getRow(3).getCell(0).getNumericCellValue(), 0.0 );
  101. assertEquals( 2, sheet.getRow(3).getCell(1).getNumericCellValue(), 0.0 );
  102. assertEquals( 3, sheet.getRow(3).getCell(2).getNumericCellValue(), 0.0 );
  103. assertEquals( 2, sheet.getRow(4).getCell(0).getNumericCellValue(), 0.0 );
  104. assertEquals( 2, sheet.getRow(4).getCell(1).getNumericCellValue(), 0.0 );
  105. assertEquals( 4, sheet.getRow(5).getCell(0).getNumericCellValue(), 0.0 );
  106. assertEquals( 4, sheet.getRow(5).getCell(1).getNumericCellValue(), 0.0 );
  107. assertEquals( 6, sheet.getRow(6).getCell(0).getNumericCellValue(), 0.0 );
  108. assertEquals( 6, sheet.getRow(6).getCell(1).getNumericCellValue(), 0.0 );
  109. assertEquals( 2, sheet.getRow(7).getCell(0).getNumericCellValue(), 0.0 );
  110. assertEquals( 4, sheet.getRow(7).getCell(1).getNumericCellValue(), 0.0 );
  111. assertEquals( 6, sheet.getRow(7).getCell(2).getNumericCellValue(), 0.0 );
  112. assertEquals( 3, sheet.getRow(8).getCell(0).getNumericCellValue(), 0.0 );
  113. assertEquals( 3, sheet.getRow(8).getCell(1).getNumericCellValue(), 0.0 );
  114. assertEquals( 6, sheet.getRow(9).getCell(0).getNumericCellValue(), 0.0 );
  115. assertEquals( 6, sheet.getRow(9).getCell(1).getNumericCellValue(), 0.0 );
  116. assertEquals( 9, sheet.getRow(10).getCell(0).getNumericCellValue(), 0.0 );
  117. assertEquals( 9, sheet.getRow(10).getCell(1).getNumericCellValue(), 0.0 );
  118. assertEquals( 3, sheet.getRow(11).getCell(0).getNumericCellValue(), 0.0 );
  119. assertEquals( 6, sheet.getRow(11).getCell(1).getNumericCellValue(), 0.0 );
  120. assertEquals( 9, sheet.getRow(11).getCell(2).getNumericCellValue(), 0.0 );
  121. short bgColour = ((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillBackgroundColor();
  122. assertEquals( "0:0:0", workbook.getCustomPalette().getColor(bgColour).getHexString() );
  123. short baseColour = workbook.getFontAt(((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFontIndex()).getColor();
  124. assertEquals( "FFFF:FFFF:FFFF", workbook.getCustomPalette().getColor(baseColour).getHexString() );
  125. } finally {
  126. inputStream.close();
  127. }
  128. }
  129. }