use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class ClassBasedSupplierTest method verifyGenericStrategy.
@Test
void verifyGenericStrategy() {
when(strategiesMap.getOrDefault(anyString(), anyString())).thenReturn(Constant.GENERIC_STRATEGY_BEAN);
when(applicationContext.getBean(Constant.GENERIC_STRATEGY_BEAN, GenericStrategy.class)).thenReturn(genericStrategy);
classBasedSupplier.preheatAdd(trackerImportParams, new TrackerPreheat());
verify(applicationContext).getBean(Constant.GENERIC_STRATEGY_BEAN, GenericStrategy.class);
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class ClassBasedSupplierTest method setUp.
@BeforeEach
public void setUp() {
classBasedSupplier = new ClassBasedSupplier(identifierCollector, strategiesMap);
classBasedSupplier.setApplicationContext(applicationContext);
TrackerPreheat trackerPreheat = new TrackerPreheat();
when(identifierCollector.collect(trackerImportParams, trackerPreheat.getDefaults())).thenReturn(new HashMap<Class<?>, Set<String>>() {
{
put(TrackedEntity.class, new HashSet<>(Collections.singletonList("trackedEntity")));
}
});
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class PeriodTypeSupplierTest method verifySupplier.
@Test
void verifySupplier() {
final List<Period> periods = rnd.objects(Period.class, 20).collect(Collectors.toList());
when(periodStore.getAll()).thenReturn(periods);
final TrackerImportParams params = TrackerImportParams.builder().build();
TrackerPreheat preheat = new TrackerPreheat();
this.supplier.preheatAdd(params, preheat);
assertThat(preheat.getPeriodMap().values(), hasSize(20));
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class UserSupplierTest method verifySupplier.
@Test
void verifySupplier() {
final List<Event> events = rnd.objects(Event.class, 5).collect(Collectors.toList());
events.forEach(e -> e.setAssignedUser(CodeGenerator.generateUid()));
final List<User> users = rnd.objects(User.class, 5).collect(Collectors.toList());
final List<String> userIds = events.stream().map(Event::getAssignedUser).collect(Collectors.toList());
IntStream.range(0, 5).forEach(i -> users.get(i).setUid(events.get(i).getAssignedUser()));
when(manager.getByUid(eq(User.class), argThat(t -> t.containsAll(userIds)))).thenReturn(users);
final TrackerImportParams params = TrackerImportParams.builder().events(events).build();
TrackerPreheat preheat = new TrackerPreheat();
this.supplier.preheatAdd(params, preheat);
for (String userUid : userIds) {
assertThat(preheat.get(User.class, userUid), is(notNullValue()));
}
// Make sure also User object are cached in the pre-heat
assertThat(preheat.getAll(User.class), hasSize(5));
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class TrackerEntityInstanceStrategyTest method verifyStrategyFiltersOutNonRootTei.
@Test
void verifyStrategyFiltersOutNonRootTei() {
// Create preheat params
final List<TrackedEntity> trackedEntities = rnd.objects(TrackedEntity.class, 2).collect(Collectors.toList());
final TrackerImportParams params = TrackerImportParams.builder().trackedEntities(trackedEntities).build();
// Preheat
TrackerPreheat preheat = new TrackerPreheat();
final List<String> rootUids = trackedEntities.stream().map(TrackedEntity::getTrackedEntity).collect(Collectors.toList());
// Add uid of non-root tei
rootUids.add("noroottei");
List<List<String>> uids = new ArrayList<>();
uids.add(rootUids);
// when
strategy.add(params, uids, preheat);
preheat.createReferenceTree();
assertTrue(preheat.getReference(trackedEntities.get(0).getTrackedEntity()).isPresent());
assertTrue(preheat.getReference(trackedEntities.get(1).getTrackedEntity()).isPresent());
assertFalse(preheat.getReference("noroottei").isPresent());
}
Aggregations