Search in sources :

Example 1 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.

@Test
void testVisitedStatusIsConvertedToActive() {
    // Given
    Event event = new Event();
    event.setStatus(EventStatus.VISITED);
    event.setProgramStage("programStageUid");
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid("programInstanceUid");
    Program program = new Program();
    program.setUid("programUid");
    ProgramStage programStage = new ProgramStage();
    programStage.setUid("programStageUid");
    programStage.setProgram(program);
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
    preheat.put(TrackerIdentifier.UID, programStage);
    bundle.setPreheat(preheat);
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertEquals(EventStatus.ACTIVE, bundle.getEvents().get(0).getStatus());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 2 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ProgramInstanceSupplierTest method verifySupplier.

@Test
void verifySupplier() {
    // given
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.put(TrackerIdentifier.UID, Lists.newArrayList(programWithRegistration, programWithoutRegistration));
    // when
    this.supplier.preheatAdd(params, preheat);
    // then
    assertNotNull(preheat.getProgramInstancesWithoutRegistration(programWithoutRegistration.getUid()));
}
Also used : TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 3 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ProgramInstanceSupplierTest method verifySupplierWhenNoEventProgramArePresent.

@Test
void verifySupplierWhenNoEventProgramArePresent() {
    // given
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.put(TrackerIdentifier.UID, programWithRegistration);
    // when
    this.supplier.preheatAdd(params, preheat);
    // then
    final List<String> programUids = programInstances.stream().map(pi -> pi.getProgram().getUid()).collect(Collectors.toList());
    for (String programUid : programUids) {
        assertNull(preheat.getProgramInstancesWithoutRegistration(programUid));
    }
}
Also used : Strictness(org.mockito.quality.Strictness) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Program(org.hisp.dhis.program.Program) Lists(com.google.common.collect.Lists) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) WITH_REGISTRATION(org.hisp.dhis.program.ProgramType.WITH_REGISTRATION) ProgramInstance(org.hisp.dhis.program.ProgramInstance) WITHOUT_REGISTRATION(org.hisp.dhis.program.ProgramType.WITHOUT_REGISTRATION) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ProgramInstanceStore(org.hisp.dhis.program.ProgramInstanceStore) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ProgramStore(org.hisp.dhis.program.ProgramStore) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) List(java.util.List) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 4 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ProgramInstanceSupplierTest method verifySupplierWhenNoProgramsArePresent.

@Test
void verifySupplierWhenNoProgramsArePresent() {
    // given
    TrackerPreheat preheat = new TrackerPreheat();
    when(programStore.getByType(WITHOUT_REGISTRATION)).thenReturn(List.of(programWithoutRegistration));
    programInstances = rnd.objects(ProgramInstance.class, 1).collect(Collectors.toList());
    // set the OrgUnit parent to null to avoid recursive errors when mapping
    programInstances.forEach(p -> p.getOrganisationUnit().setParent(null));
    programInstances.get(0).setProgram(programWithoutRegistration);
    when(programInstanceStore.getByPrograms(List.of(programWithoutRegistration))).thenReturn(programInstances);
    // when
    this.supplier.preheatAdd(params, preheat);
    // then
    assertNotNull(preheat.getProgramInstancesWithoutRegistration(programWithoutRegistration.getUid()));
}
Also used : TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 5 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ClassBasedSupplierTest method verifyClassBasedSupplierStrategy.

@Test
void verifyClassBasedSupplierStrategy() {
    when(strategiesMap.getOrDefault(anyString(), anyString())).thenReturn("classbasedstrategy");
    when(applicationContext.getBean(anyString(), eq(ClassBasedSupplierStrategy.class))).thenReturn(trackerEntityInstanceStrategy);
    classBasedSupplier.preheatAdd(trackerImportParams, new TrackerPreheat());
    verify(applicationContext).getBean("classbasedstrategy", ClassBasedSupplierStrategy.class);
}
Also used : TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ClassBasedSupplierStrategy(org.hisp.dhis.tracker.preheat.supplier.strategy.ClassBasedSupplierStrategy) 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