PageRenderTime 73ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/yaytay/spudsoft-birt-excel-emitters
Java | 117 lines | 82 code | 23 blank | 12 comment | 0 complexity | ca908982a1254c719ad5c8010b7952ad 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.InputStream;
  17. import org.apache.poi.ss.usermodel.Sheet;
  18. import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
  19. import org.apache.poi.xssf.usermodel.XSSFSheet;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21. import org.junit.Test;
  22. public class Issue43StructuredHeader extends ReportRunner {
  23. @Test
  24. public void testWithoutOption() throws Exception {
  25. debug = false;
  26. InputStream inputStream = runAndRenderReport("StructuredHeader.rptdesign", "xlsx");
  27. assertNotNull(inputStream);
  28. try {
  29. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  30. assertNotNull(workbook);
  31. assertEquals( 3, workbook.getNumberOfSheets() );
  32. assertEquals( 4, this.firstNullRow(workbook.getSheetAt(0)));
  33. assertEquals( 4, this.firstNullRow(workbook.getSheetAt(1)));
  34. assertEquals( 4, this.firstNullRow(workbook.getSheetAt(2)));
  35. XSSFSheet sheet0 = workbook.getSheetAt(0);
  36. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  37. assertEquals( XSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  38. assertEquals( false, printSetup.getLandscape() );
  39. assertEquals( 0.7 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  40. assertEquals( 0.7 / 2.54, printSetup.getFooterMargin(), 0.01 );
  41. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  42. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  43. assertEquals( 2.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  44. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  45. } finally {
  46. inputStream.close();
  47. }
  48. }
  49. @Test
  50. public void testWithOption() throws Exception {
  51. debug = false;
  52. structuredHeader = true;
  53. InputStream inputStream = runAndRenderReport("StructuredHeader.rptdesign", "xlsx");
  54. structuredHeader = false;
  55. assertNotNull(inputStream);
  56. try {
  57. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  58. assertNotNull(workbook);
  59. assertEquals( 3, workbook.getNumberOfSheets() );
  60. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(0)));
  61. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(1)));
  62. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(2)));
  63. XSSFSheet sheet0 = workbook.getSheetAt(0);
  64. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  65. assertEquals( XSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  66. assertEquals( false, printSetup.getLandscape() );
  67. assertEquals( 0.7 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  68. assertEquals( 0.7 / 2.54, printSetup.getFooterMargin(), 0.01 );
  69. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  70. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  71. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  72. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  73. } finally {
  74. inputStream.close();
  75. }
  76. }
  77. @Test
  78. public void testWithUserProperty() throws Exception {
  79. debug = false;
  80. structuredHeader = false;
  81. InputStream inputStream = runAndRenderReport("StructuredHeaderWithUserProperty.rptdesign", "xlsx");
  82. assertNotNull(inputStream);
  83. try {
  84. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  85. assertNotNull(workbook);
  86. assertEquals( 3, workbook.getNumberOfSheets() );
  87. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(0)));
  88. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(1)));
  89. assertEquals( 8, this.firstNullRow(workbook.getSheetAt(2)));
  90. } finally {
  91. inputStream.close();
  92. }
  93. }
  94. }