Search in sources :

Example 1 with ProgramSchemaDescriptor

use of org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor in project dhis2-core by dhis2.

the class AbstractSchemaStrategyCachingTest method verifyObjectNotInCacheIsFetchedFromDbAndPutInCache.

@Test
void verifyObjectNotInCacheIsFetchedFromDbAndPutInCache() {
    // Given
    final Schema schema = new ProgramSchemaDescriptor().getSchema();
    String UID = CodeGenerator.generateUid();
    Program program = rnd.nextObject(Program.class);
    when(cache.get(Program.class.getSimpleName(), UID)).thenReturn(Optional.empty());
    doReturn(singletonList(program)).when(queryService).query(any(Query.class));
    ProgramStrategy strategy = new ProgramStrategy(schemaService, queryService, manager, cache);
    // When
    strategy.queryForIdentifiableObjects(preheat, schema, TrackerIdentifier.UID, singletonList(singletonList(UID)), CopyMapper.class);
    // Then
    assertThat(preheat.getAll(Program.class), hasSize(1));
    verify(cache, times(1)).put(eq("Program"), anyString(), any(), eq(20), eq(10L));
}
Also used : Program(org.hisp.dhis.program.Program) Query(org.hisp.dhis.query.Query) Schema(org.hisp.dhis.schema.Schema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProgramSchemaDescriptor(org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with ProgramSchemaDescriptor

use of org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor in project dhis2-core by dhis2.

the class AbstractSchemaStrategyCachingTest method verifyObjectInCacheIsReturned.

@Test
void verifyObjectInCacheIsReturned() {
    // Given
    final Schema schema = new ProgramSchemaDescriptor().getSchema();
    String UID = CodeGenerator.generateUid();
    Program program = rnd.nextObject(Program.class);
    when(cache.get(Program.class.getSimpleName(), UID)).thenReturn(Optional.of(program));
    ProgramStrategy strategy = new ProgramStrategy(schemaService, queryService, manager, cache);
    // When
    strategy.queryForIdentifiableObjects(preheat, schema, TrackerIdentifier.UID, singletonList(singletonList(UID)), ProgramMapper.INSTANCE.getClass());
    // Then
    assertThat(preheat.getAll(Program.class), hasSize(1));
}
Also used : Program(org.hisp.dhis.program.Program) Schema(org.hisp.dhis.schema.Schema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProgramSchemaDescriptor(org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

Program (org.hisp.dhis.program.Program)2 Schema (org.hisp.dhis.schema.Schema)2 ProgramSchemaDescriptor (org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Query (org.hisp.dhis.query.Query)1