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));
}
Aggregations