PageRenderTime 91ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 158 lines | 110 code | 26 blank | 22 comment | 0 complexity | 653868c52a5e913333459a3a5702deac 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 static org.junit.Assert.assertTrue;
  27. import java.io.InputStream;
  28. import org.apache.poi.ss.usermodel.Sheet;
  29. import org.apache.poi.xssf.usermodel.XSSFName;
  30. import org.apache.poi.xssf.usermodel.XSSFSheet;
  31. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  32. import org.junit.Test;
  33. public class AutoFilterTest extends ReportRunner {
  34. @Test
  35. public void autoFilter() throws Exception {
  36. debug = false;
  37. autoFilter = true;
  38. InputStream inputStream = runAndRenderReport("SideBySideMultiColumns.rptdesign", "xlsx");
  39. assertNotNull(inputStream);
  40. try {
  41. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  42. assertNotNull(workbook);
  43. assertEquals( 1, workbook.getNumberOfSheets() );
  44. assertEquals( "Sheet0", workbook.getSheetAt(0).getSheetName());
  45. XSSFSheet sheet = workbook.getSheetAt(0);
  46. assertEquals(124, this.firstNullRow(sheet));
  47. assertEquals( 297, sheet.getRow( 0 ).getHeightInPoints(), 1.0 );
  48. assertEquals( 2048, sheet.getColumnWidth( 0 ) );
  49. assertEquals( 6196, sheet.getColumnWidth( 1 ) );
  50. assertEquals( 3749, sheet.getColumnWidth( 2 ) );
  51. assertEquals( 2396, sheet.getColumnWidth( 3 ) );
  52. assertEquals( 4516, sheet.getColumnWidth( 4 ) );
  53. assertEquals( 7072, sheet.getColumnWidth( 5 ) );
  54. assertEquals( 2048, sheet.getColumnWidth( 6 ) );
  55. assertEquals( 3509, sheet.getColumnWidth( 7 ) );
  56. assertEquals( 2048, sheet.getColumnWidth( 8 ) );
  57. assertEquals( 2314, sheet.getColumnWidth( 9 ) );
  58. assertEquals( 2338, sheet.getColumnWidth( 10 ) );
  59. assertEquals( 2048, sheet.getColumnWidth( 11 ) );
  60. assertEquals( 2048, sheet.getColumnWidth( 12 ) );
  61. assertTrue( mergedRegion(sheet, 0, 0, 0, 5) );
  62. assertTrue( mergedRegion(sheet, 0, 7, 0, 12) );
  63. XSSFName name = workbook.getName( XSSFName.BUILTIN_FILTER_DB );
  64. assertEquals( 0, name.getSheetIndex() );
  65. assertEquals( "Sheet0!$A$1:$M$2", name.getRefersToFormula() );
  66. } finally {
  67. inputStream.close();
  68. }
  69. }
  70. @Test
  71. public void autoFilterMultiSheets() throws Exception {
  72. debug = false;
  73. autoFilter = true;
  74. InputStream inputStream = runAndRenderReport("MultiSheets1.rptdesign", "xlsx");
  75. assertNotNull(inputStream);
  76. try {
  77. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  78. assertNotNull(workbook);
  79. assertEquals( 3, workbook.getNumberOfSheets() );
  80. assertEquals( "Number Formats 1", workbook.getSheetAt(0).getSheetName());
  81. assertEquals( "Number Formats 2", workbook.getSheetAt(1).getSheetName());
  82. assertEquals( "Number Formats 3", workbook.getSheetAt(2).getSheetName());
  83. assertEquals(4, firstNullRow(workbook.getSheetAt(0)));
  84. assertEquals(4, firstNullRow(workbook.getSheetAt(1)));
  85. assertEquals(3, firstNullRow(workbook.getSheetAt(2)));
  86. assertEquals( true, workbook.getSheetAt(0).isDisplayGridlines());
  87. assertEquals( false, workbook.getSheetAt(1).isDisplayGridlines());
  88. assertEquals( false, workbook.getSheetAt(2).isDisplayGridlines());
  89. assertEquals( true, workbook.getSheetAt(0).isDisplayRowColHeadings());
  90. assertEquals( false, workbook.getSheetAt(1).isDisplayGridlines());
  91. assertEquals( true, workbook.getSheetAt(2).isDisplayRowColHeadings());
  92. XSSFName name = workbook.getName( XSSFName.BUILTIN_FILTER_DB );
  93. assertEquals( 0, name.getSheetIndex() );
  94. assertEquals( "'Number Formats 1'!$A$1:$H$3", name.getRefersToFormula() );
  95. assertNotNull( workbook.getSheetAt(0).getCTWorksheet().getAutoFilter() );
  96. assertNotNull( workbook.getSheetAt(1).getCTWorksheet().getAutoFilter() );
  97. assertNotNull( workbook.getSheetAt(2).getCTWorksheet().getAutoFilter() );
  98. } finally {
  99. inputStream.close();
  100. }
  101. }
  102. @Test
  103. public void autoFilterMultiTables() throws Exception {
  104. debug = false;
  105. autoFilter = true;
  106. InputStream inputStream = runAndRenderReport("NumberFormats.rptdesign", "xlsx");
  107. assertNotNull(inputStream);
  108. try {
  109. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  110. assertNotNull(workbook);
  111. assertEquals( 1, workbook.getNumberOfSheets() );
  112. assertEquals( "Number Formats Test Report", workbook.getSheetAt(0).getSheetName());
  113. Sheet sheet = workbook.getSheetAt(0);
  114. assertEquals(22, this.firstNullRow(sheet));
  115. assertEquals( 3035, sheet.getColumnWidth( 0 ) );
  116. assertEquals( 3913, sheet.getColumnWidth( 1 ) );
  117. assertEquals( 7021, sheet.getColumnWidth( 2 ) );
  118. assertEquals( 4205, sheet.getColumnWidth( 3 ) );
  119. assertEquals( 3474, sheet.getColumnWidth( 4 ) );
  120. assertEquals( 2852, sheet.getColumnWidth( 5 ) );
  121. assertEquals( 3510, sheet.getColumnWidth( 6 ) );
  122. assertEquals( 2889, sheet.getColumnWidth( 7 ) );
  123. assertEquals( 2048, sheet.getColumnWidth( 8 ) );
  124. XSSFName name = workbook.getName( XSSFName.BUILTIN_FILTER_DB );
  125. assertEquals( 0, name.getSheetIndex() );
  126. assertEquals( "'Number Formats Test Report'!$A$1:$H$3", name.getRefersToFormula() );
  127. assertNotNull( workbook.getSheetAt(0).getCTWorksheet().getAutoFilter() );
  128. } finally {
  129. inputStream.close();
  130. }
  131. }
  132. }