Search in sources :

Example 1 with MonthlyFieldValue

use of org.activityinfo.test.driver.MonthlyFieldValue in project activityinfo by bedatadriven.

the class ExportUiTest method largeDatabase.

@Test
public void largeDatabase() throws Exception {
    driver.login();
    driver.setup().createDatabase(name(WASH_DATABASE));
    driver.setup().addPartner("ACF", WASH_DATABASE);
    driver.setup().createForm(name(WASH_SITE_FORM), property("database", WASH_DATABASE), property("reportingFrequency", "monthly"));
    driver.setup().createField(name(INDICATOR_NAME), property("form", WASH_SITE_FORM), property("type", "quantity"));
    // Submit 200 sites with 6 months worth of data each
    double expectedTotal = 0;
    for (int i = 0; i < 200; i++) {
        List<MonthlyFieldValue> fieldValues = new ArrayList<>();
        for (int month = 1; month < 6; ++month) {
            int count = month * 10;
            expectedTotal += count;
            MonthlyFieldValue fieldValue = new MonthlyFieldValue();
            fieldValue.setYear(2015);
            fieldValue.setMonth(month);
            fieldValue.setField(INDICATOR_NAME);
            fieldValue.setValue(count);
            fieldValues.add(fieldValue);
        }
        driver.setup().submitForm(WASH_SITE_FORM, "ACF", fieldValues);
    }
    File file = driver.setup().exportForm(WASH_SITE_FORM);
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(file));
    HSSFSheet worksheet = workbook.getSheetAt(0);
    // Find indicator column
    double exportedTotal = 0;
    int indicatorColumn = findColumn(worksheet);
    for (int rowIndex = 2; rowIndex <= worksheet.getLastRowNum(); ++rowIndex) {
        HSSFRow row = worksheet.getRow(rowIndex);
        HSSFCell cell = row.getCell(indicatorColumn);
        exportedTotal += cell.getNumericCellValue();
    }
    assertThat(exportedTotal, equalTo(expectedTotal));
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) ArrayList(java.util.ArrayList) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) MonthlyFieldValue(org.activityinfo.test.driver.MonthlyFieldValue) File(java.io.File) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 MonthlyFieldValue (org.activityinfo.test.driver.MonthlyFieldValue)1 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Test (org.junit.Test)1