Search in sources :

Example 16 with AnalyticsTableUpdateParams

use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.

the class JdbcAnalyticsTableManagerTest method testGetLatestAnalyticsTable.

@Test
void testGetLatestAnalyticsTable() {
    Date lastFullTableUpdate = new DateTime(2019, 3, 1, 2, 0).toDate();
    Date lastLatestPartitionUpdate = new DateTime(2019, 3, 1, 9, 0).toDate();
    Date startTime = new DateTime(2019, 3, 1, 10, 0).toDate();
    AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).withLatestPartition().build();
    List<Map<String, Object>> queryResp = Lists.newArrayList();
    queryResp.add(ImmutableMap.of("dataelementid", 1));
    when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE)).thenReturn(lastFullTableUpdate);
    when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE)).thenReturn(lastLatestPartitionUpdate);
    when(jdbcTemplate.queryForList(Mockito.anyString())).thenReturn(queryResp);
    List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
    assertEquals(1, tables.size());
    AnalyticsTable table = tables.get(0);
    assertNotNull(table);
    assertNotNull(table.getTablePartitions());
    assertEquals(1, table.getTablePartitions().size());
    AnalyticsTablePartition partition = table.getLatestPartition();
    assertNotNull(partition);
    assertTrue(partition.isLatestPartition());
    assertEquals(lastFullTableUpdate, partition.getStartDate());
    assertEquals(startTime, partition.getEndDate());
}
Also used : AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

AnalyticsTableUpdateParams (org.hisp.dhis.analytics.AnalyticsTableUpdateParams)16 Test (org.junit.jupiter.api.Test)14 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)11 Program (org.hisp.dhis.program.Program)11 Date (java.util.Date)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)9 DhisConvenienceTest.createProgramTrackedEntityAttribute (org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute)7 DhisConvenienceTest.createTrackedEntityAttribute (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute)7 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)7 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)7 DateTime (org.joda.time.DateTime)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)6 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)6 AnalyticsTablePartition (org.hisp.dhis.analytics.AnalyticsTablePartition)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Map (java.util.Map)5 LocalDate (java.time.LocalDate)4 HashSet (java.util.HashSet)4 DhisConvenienceTest.createCategory (org.hisp.dhis.DhisConvenienceTest.createCategory)4