PageRenderTime 357ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ravisanthu0/spudsoft-birt-excel-emitters1
Java | 139 lines | 110 code | 29 blank | 0 comment | 0 complexity | 598aefae20c768ecc4b4925011d40e13 MD5 | raw file
Possible License(s): GPL-3.0
  1. package uk.co.spudsoft.birt.emitters.excel.tests;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
  7. import org.apache.poi.hssf.usermodel.HSSFSheet;
  8. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  9. import org.apache.poi.ss.usermodel.PaperSize;
  10. import org.apache.poi.ss.usermodel.PrintOrientation;
  11. import org.apache.poi.ss.usermodel.Sheet;
  12. import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
  13. import org.apache.poi.xssf.usermodel.XSSFSheet;
  14. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  15. import org.eclipse.birt.core.exception.BirtException;
  16. import org.junit.Test;
  17. public class PageLayoutTest extends ReportRunner {
  18. @Test
  19. public void testRunReportXlsx() throws BirtException, IOException {
  20. InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xlsx");
  21. assertNotNull(inputStream);
  22. try {
  23. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  24. assertNotNull(workbook);
  25. assertEquals( 1, workbook.getNumberOfSheets() );
  26. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  27. XSSFSheet sheet0 = workbook.getSheetAt(0);
  28. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  29. assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
  30. assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
  31. assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  32. assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
  33. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  34. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  35. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  36. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  37. } finally {
  38. inputStream.close();
  39. }
  40. }
  41. @Test
  42. public void testRunReportXls() throws BirtException, IOException {
  43. InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xls");
  44. assertNotNull(inputStream);
  45. try {
  46. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  47. assertNotNull(workbook);
  48. assertEquals( 1, workbook.getNumberOfSheets() );
  49. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  50. HSSFSheet sheet0 = workbook.getSheetAt(0);
  51. HSSFPrintSetup printSetup = sheet0.getPrintSetup();
  52. assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  53. assertEquals( true, printSetup.getLandscape() );
  54. assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
  55. assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
  56. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  57. assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  58. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  59. assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  60. } finally {
  61. inputStream.close();
  62. }
  63. }
  64. @Test
  65. public void testRunReportPixelsXlsx() throws BirtException, IOException {
  66. InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xlsx");
  67. assertNotNull(inputStream);
  68. try {
  69. XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
  70. assertNotNull(workbook);
  71. assertEquals( 1, workbook.getNumberOfSheets() );
  72. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  73. XSSFSheet sheet0 = workbook.getSheetAt(0);
  74. XSSFPrintSetup printSetup = sheet0.getPrintSetup();
  75. assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
  76. assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
  77. assertEquals( 0.3, printSetup.getHeaderMargin(), 0.01 );
  78. assertEquals( 0.3, printSetup.getFooterMargin(), 0.01 );
  79. assertEquals( 0.7, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  80. assertEquals( 0.7, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  81. assertEquals( 0.75, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  82. assertEquals( 0.75, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  83. } finally {
  84. inputStream.close();
  85. }
  86. }
  87. @Test
  88. public void testRunReportPixelsXls() throws BirtException, IOException {
  89. InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xls");
  90. assertNotNull(inputStream);
  91. try {
  92. HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
  93. assertNotNull(workbook);
  94. assertEquals( 1, workbook.getNumberOfSheets() );
  95. assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
  96. HSSFSheet sheet0 = workbook.getSheetAt(0);
  97. HSSFPrintSetup printSetup = sheet0.getPrintSetup();
  98. assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
  99. assertEquals( true, printSetup.getLandscape() );
  100. assertEquals( 0.5, printSetup.getHeaderMargin(), 0.01 );
  101. assertEquals( 0.5, printSetup.getFooterMargin(), 0.01 );
  102. assertEquals( 0.75, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
  103. assertEquals( 0.75, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
  104. assertEquals( 1.0, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
  105. assertEquals( 1.0, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
  106. } finally {
  107. inputStream.close();
  108. }
  109. }
  110. }