Search in sources :

Example 26 with TrackerPreheat

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);
}
Also used : TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test)

Example 27 with TrackerPreheat

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")));
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with TrackerPreheat

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));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Period(org.hisp.dhis.period.Period) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test)

Example 29 with TrackerPreheat

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));
}
Also used : IntStream(java.util.stream.IntStream) InjectMocks(org.mockito.InjectMocks) Event(org.hisp.dhis.tracker.domain.Event) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Matchers.hasSize(org.hamcrest.Matchers.hasSize) User(org.hisp.dhis.user.User) Matchers.is(org.hamcrest.Matchers.is) CodeGenerator(org.hisp.dhis.common.CodeGenerator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) User(org.hisp.dhis.user.User) Event(org.hisp.dhis.tracker.domain.Event) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test)

Example 30 with TrackerPreheat

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ArrayList(java.util.ArrayList) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)33 Test (org.junit.jupiter.api.Test)17 List (java.util.List)11 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)10 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)10 Event (org.hisp.dhis.tracker.domain.Event)9 Collectors (java.util.stream.Collectors)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Optional (java.util.Optional)6 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)6 ProgramStage (org.hisp.dhis.program.ProgramStage)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 Component (org.springframework.stereotype.Component)5 Lists (com.google.common.collect.Lists)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)4 Program (org.hisp.dhis.program.Program)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4