PageRenderTime 250ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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