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

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

https://bitbucket.org/xunchangguo/spudsoft-birt-excel-emitters
Java | 161 lines | 110 code | 29 blank | 22 comment | 0 complexity | 524fc2e390156ed203b3d5035cda4741 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.HSSFPrintSetup;
  29. import org.apache.poi.hssf.usermodel.HSSFSheet;
  30. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  31. import org.apache.poi.ss.usermodel.PaperSize;
  32. import org.apache.poi.ss.usermodel.PrintOrientation;
  33. import org.apache.poi.ss.usermodel.Sheet;
  34. import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
  35. import org.apache.poi.xssf.usermodel.XSSFSheet;
  36. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  37. import org.eclipse.birt.core.exception.BirtException;
  38. import org.junit.Test;
  39. public class PageLayoutTest extends ReportRunner {
  40. @Test
  41. public void testRunReportXlsx() throws BirtException, IOException {
  42. InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xlsx");
  43. assertNotNull(inputStream);
  44. try {
  45. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  46. assertNotNull(workbook);
  47. assertEquals( 1, workbook.getNumberOfSheets() );
  48. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  49. XSSFSheet sheet0 = workbook.getSheetAt(0);
  50. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  51. assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
  52. assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
  53. assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  54. assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
  55. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  56. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  57. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  58. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  59. } finally {
  60. inputStream.close();
  61. }
  62. }
  63. @Test
  64. public void testRunReportXls() throws BirtException, IOException {
  65. InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xls");
  66. assertNotNull(inputStream);
  67. try {
  68. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  69. assertNotNull(workbook);
  70. assertEquals( 1, workbook.getNumberOfSheets() );
  71. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  72. HSSFSheet sheet0 = workbook.getSheetAt(0);
  73. HSSFPrintSetup printSetup = sheet0.getPrintSetup();
  74. assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  75. assertEquals( true, printSetup.getLandscape() );
  76. assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  77. assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
  78. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  79. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  80. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  81. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  82. } finally {
  83. inputStream.close();
  84. }
  85. }
  86. @Test
  87. public void testRunReportPixelsXlsx() throws BirtException, IOException {
  88. InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xlsx");
  89. assertNotNull(inputStream);
  90. try {
  91. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  92. assertNotNull(workbook);
  93. assertEquals( 1, workbook.getNumberOfSheets() );
  94. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  95. XSSFSheet sheet0 = workbook.getSheetAt(0);
  96. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  97. assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
  98. assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
  99. assertEquals( 0.3, printSetup.getHeaderMargin(), 0.01 );
  100. assertEquals( 0.3, printSetup.getFooterMargin(), 0.01 );
  101. assertEquals( 0.7, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  102. assertEquals( 0.7, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  103. assertEquals( 0.75, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  104. assertEquals( 0.75, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  105. } finally {
  106. inputStream.close();
  107. }
  108. }
  109. @Test
  110. public void testRunReportPixelsXls() throws BirtException, IOException {
  111. InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xls");
  112. assertNotNull(inputStream);
  113. try {
  114. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  115. assertNotNull(workbook);
  116. assertEquals( 1, workbook.getNumberOfSheets() );
  117. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  118. HSSFSheet sheet0 = workbook.getSheetAt(0);
  119. HSSFPrintSetup printSetup = sheet0.getPrintSetup();
  120. assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  121. assertEquals( true, printSetup.getLandscape() );
  122. assertEquals( 0.5, printSetup.getHeaderMargin(), 0.01 );
  123. assertEquals( 0.5, printSetup.getFooterMargin(), 0.01 );
  124. assertEquals( 0.75, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  125. assertEquals( 0.75, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  126. assertEquals( 1.0, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  127. assertEquals( 1.0, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  128. } finally {
  129. inputStream.close();
  130. }
  131. }
  132. }