PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/report/renderer/excel/PivotTableRendererTest.java

http://sigma-h.googlecode.com/
Java | 103 lines | 59 code | 27 blank | 17 comment | 0 complexity | dcec84affc929250807c275a30e7658a MD5 | raw file
  1/*
  2 * All Sigmah code is released under the GNU General Public License v3
  3 * See COPYRIGHT.txt and LICENSE.txt.
  4 */
  5
  6package org.sigmah.server.report.renderer.excel;
  7
  8import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  9import org.apache.poi.ss.usermodel.Sheet;
 10import org.junit.Assert;
 11import org.junit.Test;
 12import org.sigmah.server.report.DummyPivotTableData;
 13import org.sigmah.server.report.DummyPivotTableData2;
 14import org.sigmah.shared.report.model.PivotTableElement;
 15
 16import java.io.File;
 17import java.io.FileOutputStream;
 18import java.io.IOException;
 19import java.io.OutputStream;
 20
 21/**
 22 * @author Alex Bertram (akbertram@gmail.com)
 23 */
 24public class PivotTableRendererTest {
 25
 26    @Test
 27    public void test() {
 28
 29
 30        // input test data : element + content
 31        DummyPivotTableData testData = new DummyPivotTableData();
 32        PivotTableElement element = testData.Foobar1612Element();
 33
 34        // Destination book
 35        HSSFWorkbook book = new HSSFWorkbook();
 36
 37        // CLASS under test
 38
 39        ExcelPivotTableRenderer renderer = new ExcelPivotTableRenderer();
 40        renderer.render(book, element);
 41
 42
 43        // VERIFY output
 44
 45        Sheet sheet = book.getSheetAt(0);
 46        Assert.assertEquals("title cell", element.getTitle(),
 47                sheet.getRow(0).getCell(0).getRichStringCellValue().getString());
 48        Assert.assertEquals("last column header", "Abri",
 49                sheet.getRow(4).getCell(5).getRichStringCellValue().getString());
 50        Assert.assertEquals("columns headers indentation", (short) 0,
 51                sheet.getRow(4).getCell(3).getCellStyle().getIndention());
 52
 53        // Write output to disk
 54        try {
 55            File outputFile = new File("target/report-tests");
 56            outputFile.mkdirs();
 57            OutputStream out =
 58                    new FileOutputStream(outputFile.getAbsoluteFile() + "/PivotTableRendererTest.xls");
 59
 60            book.write(out);
 61            out.close();
 62        } catch (IOException e) {
 63            e.printStackTrace();
 64        }
 65    }
 66
 67    @Test
 68    public void testNoColumnDimensions() {
 69
 70        // input test data : element + content
 71        DummyPivotTableData2 testData = new DummyPivotTableData2();
 72        PivotTableElement element = testData.testElement();
 73
 74        // Destination book
 75        HSSFWorkbook book = new HSSFWorkbook();
 76
 77        // CLASS under test
 78
 79        ExcelPivotTableRenderer renderer = new ExcelPivotTableRenderer();
 80        renderer.render(book, element);
 81
 82        // Write output to disk
 83        try {
 84            File outputFile = new File("target/report-tests");
 85            outputFile.mkdirs();
 86            OutputStream out =
 87                    new FileOutputStream(outputFile.getAbsoluteFile() + "/testNoColumnDimensions.xls");
 88
 89            book.write(out);
 90            out.close();
 91        } catch (IOException e) {
 92            e.printStackTrace();
 93        }
 94
 95
 96        // VERIFY output
 97
 98        Sheet sheet = book.getSheetAt(0);
 99        Assert.assertEquals(100, (int) sheet.getRow(5).getCell(1).getNumericCellValue());
100
101    }
102
103}