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