PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 142 lines | 107 code | 23 blank | 12 comment | 0 complexity | cc73f812bef57179a1dadc3dac031e3f 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.HSSFCell;
  19. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  20. import org.apache.poi.ss.usermodel.Sheet;
  21. import org.apache.poi.xssf.usermodel.XSSFCell;
  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 NestedTables2ReportTest extends ReportRunner {
  27. @Test
  28. public void testRunReport() throws BirtException, IOException {
  29. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xlsx");
  30. assertNotNull(inputStream);
  31. try {
  32. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  33. assertNotNull(workbook);
  34. assertEquals( 1, workbook.getNumberOfSheets() );
  35. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  36. Sheet sheet = workbook.getSheetAt(0);
  37. assertEquals(12, firstNullRow(sheet));
  38. assertEquals( 1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0 );
  39. assertEquals( 1, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0 );
  40. assertEquals( 2, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0 );
  41. assertEquals( 2, sheet.getRow(1).getCell(1).getNumericCellValue(), 0.0 );
  42. assertEquals( 3, sheet.getRow(2).getCell(0).getNumericCellValue(), 0.0 );
  43. assertEquals( 3, sheet.getRow(2).getCell(1).getNumericCellValue(), 0.0 );
  44. assertEquals( 1, sheet.getRow(3).getCell(0).getNumericCellValue(), 0.0 );
  45. assertEquals( 2, sheet.getRow(3).getCell(1).getNumericCellValue(), 0.0 );
  46. assertEquals( 3, sheet.getRow(3).getCell(2).getNumericCellValue(), 0.0 );
  47. assertEquals( 2, sheet.getRow(4).getCell(0).getNumericCellValue(), 0.0 );
  48. assertEquals( 2, sheet.getRow(4).getCell(1).getNumericCellValue(), 0.0 );
  49. assertEquals( 4, sheet.getRow(5).getCell(0).getNumericCellValue(), 0.0 );
  50. assertEquals( 4, sheet.getRow(5).getCell(1).getNumericCellValue(), 0.0 );
  51. assertEquals( 6, sheet.getRow(6).getCell(0).getNumericCellValue(), 0.0 );
  52. assertEquals( 6, sheet.getRow(6).getCell(1).getNumericCellValue(), 0.0 );
  53. assertEquals( 2, sheet.getRow(7).getCell(0).getNumericCellValue(), 0.0 );
  54. assertEquals( 4, sheet.getRow(7).getCell(1).getNumericCellValue(), 0.0 );
  55. assertEquals( 6, sheet.getRow(7).getCell(2).getNumericCellValue(), 0.0 );
  56. assertEquals( 3, sheet.getRow(8).getCell(0).getNumericCellValue(), 0.0 );
  57. assertEquals( 3, sheet.getRow(8).getCell(1).getNumericCellValue(), 0.0 );
  58. assertEquals( 6, sheet.getRow(9).getCell(0).getNumericCellValue(), 0.0 );
  59. assertEquals( 6, sheet.getRow(9).getCell(1).getNumericCellValue(), 0.0 );
  60. assertEquals( 9, sheet.getRow(10).getCell(0).getNumericCellValue(), 0.0 );
  61. assertEquals( 9, sheet.getRow(10).getCell(1).getNumericCellValue(), 0.0 );
  62. assertEquals( 3, sheet.getRow(11).getCell(0).getNumericCellValue(), 0.0 );
  63. assertEquals( 6, sheet.getRow(11).getCell(1).getNumericCellValue(), 0.0 );
  64. assertEquals( 9, sheet.getRow(11).getCell(2).getNumericCellValue(), 0.0 );
  65. XSSFColor bgColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillForegroundColorColor();
  66. assertEquals( "FF800000", bgColour.getARGBHex() );
  67. XSSFColor baseColour = ((XSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFont().getXSSFColor();
  68. assertEquals( "FF000000", baseColour.getARGBHex() );
  69. } finally {
  70. inputStream.close();
  71. }
  72. }
  73. @Test
  74. public void testRunReportXls() throws BirtException, IOException {
  75. InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xls");
  76. assertNotNull(inputStream);
  77. try {
  78. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  79. assertNotNull(workbook);
  80. assertEquals( 1, workbook.getNumberOfSheets() );
  81. assertEquals( "Nested Tables Test Report", workbook.getSheetAt(0).getSheetName());
  82. Sheet sheet = workbook.getSheetAt(0);
  83. assertEquals(12, firstNullRow(sheet));
  84. assertEquals( 1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0 );
  85. assertEquals( 1, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0 );
  86. assertEquals( 2, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0 );
  87. assertEquals( 2, sheet.getRow(1).getCell(1).getNumericCellValue(), 0.0 );
  88. assertEquals( 3, sheet.getRow(2).getCell(0).getNumericCellValue(), 0.0 );
  89. assertEquals( 3, sheet.getRow(2).getCell(1).getNumericCellValue(), 0.0 );
  90. assertEquals( 1, sheet.getRow(3).getCell(0).getNumericCellValue(), 0.0 );
  91. assertEquals( 2, sheet.getRow(3).getCell(1).getNumericCellValue(), 0.0 );
  92. assertEquals( 3, sheet.getRow(3).getCell(2).getNumericCellValue(), 0.0 );
  93. assertEquals( 2, sheet.getRow(4).getCell(0).getNumericCellValue(), 0.0 );
  94. assertEquals( 2, sheet.getRow(4).getCell(1).getNumericCellValue(), 0.0 );
  95. assertEquals( 4, sheet.getRow(5).getCell(0).getNumericCellValue(), 0.0 );
  96. assertEquals( 4, sheet.getRow(5).getCell(1).getNumericCellValue(), 0.0 );
  97. assertEquals( 6, sheet.getRow(6).getCell(0).getNumericCellValue(), 0.0 );
  98. assertEquals( 6, sheet.getRow(6).getCell(1).getNumericCellValue(), 0.0 );
  99. assertEquals( 2, sheet.getRow(7).getCell(0).getNumericCellValue(), 0.0 );
  100. assertEquals( 4, sheet.getRow(7).getCell(1).getNumericCellValue(), 0.0 );
  101. assertEquals( 6, sheet.getRow(7).getCell(2).getNumericCellValue(), 0.0 );
  102. assertEquals( 3, sheet.getRow(8).getCell(0).getNumericCellValue(), 0.0 );
  103. assertEquals( 3, sheet.getRow(8).getCell(1).getNumericCellValue(), 0.0 );
  104. assertEquals( 6, sheet.getRow(9).getCell(0).getNumericCellValue(), 0.0 );
  105. assertEquals( 6, sheet.getRow(9).getCell(1).getNumericCellValue(), 0.0 );
  106. assertEquals( 9, sheet.getRow(10).getCell(0).getNumericCellValue(), 0.0 );
  107. assertEquals( 9, sheet.getRow(10).getCell(1).getNumericCellValue(), 0.0 );
  108. assertEquals( 3, sheet.getRow(11).getCell(0).getNumericCellValue(), 0.0 );
  109. assertEquals( 6, sheet.getRow(11).getCell(1).getNumericCellValue(), 0.0 );
  110. assertEquals( 9, sheet.getRow(11).getCell(2).getNumericCellValue(), 0.0 );
  111. short bgColour = ((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFillBackgroundColor();
  112. assertEquals( "0:0:0", workbook.getCustomPalette().getColor(bgColour).getHexString() );
  113. short baseColour = workbook.getFontAt(((HSSFCell)sheet.getRow(0).getCell(0)).getCellStyle().getFontIndex()).getColor();
  114. assertEquals( "FFFF:FFFF:FFFF", workbook.getCustomPalette().getColor(baseColour).getHexString() );
  115. } finally {
  116. inputStream.close();
  117. }
  118. }
  119. }