Search in sources :

Example 6 with MonthlyReportResult

use of org.activityinfo.legacy.shared.command.result.MonthlyReportResult in project activityinfo by bedatadriven.

the class SyncIntegrationTest method updateMonthlyReports.

@Test
@OnDataSet("/dbunit/monthly-calc-indicators.db.xml")
public void updateMonthlyReports() throws SQLException, InterruptedException {
    synchronize();
    int siteId = 1;
    MonthlyReportResult result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    IndicatorRowDTO women = result.getData().get(0);
    IndicatorRowDTO men = result.getData().get(1);
    assertThat(women.getIndicatorName(), equalTo("women"));
    assertThat(women.getIndicatorId(), equalTo(7002));
    assertThat(men.getIndicatorName(), equalTo("men"));
    assertThat(men.getActivityName(), equalTo("NFI"));
    assertThat(men.getActivityId(), equalTo(901));
    assertThat(men.getIndicatorId(), equalTo(7001));
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(200d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // Update locally
    executeLocally(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 221d), new Change(men.getIndicatorId(), new Month(2009, 3), 444d), new Change(women.getIndicatorId(), new Month(2009, 5), 200d), new Change(men.getIndicatorId(), new Month(2009, 5), 522d))));
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    // Synchronize
    synchronize();
    newRequest();
    MonthlyReportResult remoteResult = executeRemotely(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = remoteResult.getData().get(0);
    men = remoteResult.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    newRequest();
    // REmote update
    executeRemotely(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 40d), new Change(women.getIndicatorId(), new Month(2009, 3), 6000d))));
    newRequest();
    synchronize();
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(40d));
    // unchanged
    assertThat(women.getValue(2009, 1), CoreMatchers.equalTo(300d));
    assertThat(women.getValue(2009, 3), equalTo(6000d));
}
Also used : Month(org.activityinfo.model.type.time.Month) Change(org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change) MonthlyReportResult(org.activityinfo.legacy.shared.command.result.MonthlyReportResult) IndicatorRowDTO(org.activityinfo.legacy.shared.model.IndicatorRowDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 7 with MonthlyReportResult

use of org.activityinfo.legacy.shared.command.result.MonthlyReportResult in project activityinfo by bedatadriven.

the class MonthlyReportsTest method testGetReports.

@Test
public void testGetReports() throws Exception {
    GetMonthlyReports cmd = new GetMonthlyReports(6);
    cmd.setStartMonth(new Month(2009, 1));
    cmd.setEndMonth(new Month(2009, 2));
    MonthlyReportResult result = execute(cmd);
    Assert.assertEquals(1, result.getData().size());
    Assert.assertEquals(35, result.getData().get(0).getValue(2009, 1).intValue());
    Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
}
Also used : Month(org.activityinfo.model.type.time.Month) GetMonthlyReports(org.activityinfo.legacy.shared.command.GetMonthlyReports) MonthlyReportResult(org.activityinfo.legacy.shared.command.result.MonthlyReportResult) Test(org.junit.Test)

Aggregations

MonthlyReportResult (org.activityinfo.legacy.shared.command.result.MonthlyReportResult)7 Month (org.activityinfo.model.type.time.Month)7 Test (org.junit.Test)4 GetMonthlyReports (org.activityinfo.legacy.shared.command.GetMonthlyReports)3 IndicatorRowDTO (org.activityinfo.legacy.shared.model.IndicatorRowDTO)3 ArrayList (java.util.ArrayList)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 Function (com.google.common.base.Function)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)1 Change (org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change)1 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Timed (org.activityinfo.server.util.monitoring.Timed)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1