/SpudSoft BIRT Excel Emitters Tests/src/uk/co/spudsoft/birt/emitters/excel/tests/PageLayoutTest.java
Java | 161 lines | 110 code | 29 blank | 22 comment | 0 complexity | 524fc2e390156ed203b3d5035cda4741 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
- /*************************************************************
- * (C) Copyright 2011, 2012 James Talbut.
- * jim-emitters@spudsoft.co.uk
- *
- * This file is part of The SpudSoft BIRT Excel Emitters.
- * The SpudSoft BIRT Excel Emitters are free software: you can
- * redistribute them and/or modify them under the terms of the
- * GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * The SpudSoft BIRT Excel Emitters are distributed in the hope
- * that they will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with the SpudSoft BIRT Excel Emitters.
- * If not, see <http://www.gnu.org/licenses/>.
- *
- *************************************************************/
- package uk.co.spudsoft.birt.emitters.excel.tests;
-
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
-
- import java.io.IOException;
- import java.io.InputStream;
-
- import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.PaperSize;
- import org.apache.poi.ss.usermodel.PrintOrientation;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.eclipse.birt.core.exception.BirtException;
- import org.junit.Test;
-
- public class PageLayoutTest extends ReportRunner {
-
- @Test
- public void testRunReportXlsx() throws BirtException, IOException {
-
- InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xlsx");
- assertNotNull(inputStream);
- try {
-
- XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
- assertNotNull(workbook);
-
- assertEquals( 1, workbook.getNumberOfSheets() );
- assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
-
- XSSFSheet sheet0 = workbook.getSheetAt(0);
- XSSFPrintSetup printSetup = sheet0.getPrintSetup();
- assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
- assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
- assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
- assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
- assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
- assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
- assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
- assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
-
- } finally {
- inputStream.close();
- }
- }
-
- @Test
- public void testRunReportXls() throws BirtException, IOException {
-
- InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xls");
- assertNotNull(inputStream);
- try {
-
- HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
- assertNotNull(workbook);
-
- assertEquals( 1, workbook.getNumberOfSheets() );
- assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
-
- HSSFSheet sheet0 = workbook.getSheetAt(0);
- HSSFPrintSetup printSetup = sheet0.getPrintSetup();
- assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
- assertEquals( true, printSetup.getLandscape() );
- assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
- assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
- assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
- assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
- assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
- assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
-
- } finally {
- inputStream.close();
- }
- }
-
- @Test
- public void testRunReportPixelsXlsx() throws BirtException, IOException {
-
- InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xlsx");
- assertNotNull(inputStream);
- try {
-
- XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
- assertNotNull(workbook);
-
- assertEquals( 1, workbook.getNumberOfSheets() );
- assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
-
- XSSFSheet sheet0 = workbook.getSheetAt(0);
- XSSFPrintSetup printSetup = sheet0.getPrintSetup();
- assertEquals( PaperSize.A4_PAPER, printSetup.getPaperSizeEnum() );
- assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
- assertEquals( 0.3, printSetup.getHeaderMargin(), 0.01 );
- assertEquals( 0.3, printSetup.getFooterMargin(), 0.01 );
- assertEquals( 0.7, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
- assertEquals( 0.7, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
- assertEquals( 0.75, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
- assertEquals( 0.75, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
-
- } finally {
- inputStream.close();
- }
- }
-
- @Test
- public void testRunReportPixelsXls() throws BirtException, IOException {
-
- InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xls");
- assertNotNull(inputStream);
- try {
-
- HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
- assertNotNull(workbook);
-
- assertEquals( 1, workbook.getNumberOfSheets() );
- assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
-
- HSSFSheet sheet0 = workbook.getSheetAt(0);
- HSSFPrintSetup printSetup = sheet0.getPrintSetup();
- assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() );
- assertEquals( true, printSetup.getLandscape() );
- assertEquals( 0.5, printSetup.getHeaderMargin(), 0.01 );
- assertEquals( 0.5, printSetup.getFooterMargin(), 0.01 );
- assertEquals( 0.75, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
- assertEquals( 0.75, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
- assertEquals( 1.0, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
- assertEquals( 1.0, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
-
- } finally {
- inputStream.close();
- }
- }
-
- }