Search in sources :

Example 11 with PivotTableReportElement

use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class PivotTableRendererTest method testNoColumnDimensions.

@Test
public void testNoColumnDimensions() {
    // input test data : element + content
    DummyPivotTableData2 testData = new DummyPivotTableData2();
    PivotTableReportElement element = testData.testElement();
    // Destination book
    HSSFWorkbook book = new HSSFWorkbook();
    // CLASS under test
    ExcelPivotTableRenderer renderer = new ExcelPivotTableRenderer();
    renderer.render(book, element);
    // Write output to disk
    try {
        File outputFile = new File("build/report-tests");
        outputFile.mkdirs();
        OutputStream out = new FileOutputStream(new File(outputFile, "testNoColumnDimensions.xls"));
        book.write(out);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // VERIFY output
    Sheet sheet = book.getSheetAt(0);
    Assert.assertEquals(100, (int) sheet.getRow(5).getCell(1).getNumericCellValue());
}
Also used : DummyPivotTableData2(org.activityinfo.server.report.DummyPivotTableData2) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) PivotTableReportElement(org.activityinfo.legacy.shared.reports.model.PivotTableReportElement) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 12 with PivotTableReportElement

use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class PivotTableGeneratorTest method testIndicatorSortOrder.

@Test
public void testIndicatorSortOrder() {
    // test input data: user
    User user = new User();
    user.setLocale("fr");
    // test input data: PivotTableElement
    PivotTableReportElement element = new PivotTableReportElement();
    Dimension indicatorDim = new Dimension(DimensionType.Indicator);
    element.addRowDimension(indicatorDim);
    // test input data: aggregated results
    List<Bucket> buckets = new ArrayList<Bucket>();
    buckets.add(newBucket(300, category(indicatorDim, 1, "Nb. menages", 3)));
    buckets.add(newBucket(400, category(indicatorDim, 2, "Nb. personnes", 1)));
    buckets.add(newBucket(600, category(indicatorDim, 3, "Nb. deplaces", 2)));
    // collaborator : PivotDAO
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
    replay(dispatcher);
    // CLASS UNDER TEST!!
    PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
    generator.generate(user, element, dummyFilter(), null);
    Assert.assertNotNull("element content", element.getContent());
    List<PivotTableData.Axis> rows = element.getContent().getData().getRootRow().getChildren();
    Assert.assertEquals(2, ((EntityCategory) rows.get(0).getCategory()).getId());
    Assert.assertEquals(3, ((EntityCategory) rows.get(1).getCategory()).getId());
    Assert.assertEquals(1, ((EntityCategory) rows.get(2).getCategory()).getId());
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) PivotTableReportElement(org.activityinfo.legacy.shared.reports.model.PivotTableReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Aggregations

PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)12 Test (org.junit.Test)8 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)5 ArrayList (java.util.ArrayList)4 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)4 DummyPivotTableData2 (org.activityinfo.server.report.DummyPivotTableData2)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)2 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)2 PivotContent (org.activityinfo.legacy.shared.reports.content.PivotContent)2 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)2 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)2 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)2 DispatcherSync (org.activityinfo.server.command.DispatcherSync)2 User (org.activityinfo.server.database.hibernate.entity.User)2 ReportChangeEvent (org.activityinfo.ui.client.page.report.ReportChangeEvent)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2