PageRenderTime 68ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

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

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