Search in sources :

Example 31 with TrackerPreheat

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

the class BidirectionalRelationshipsPreProcessorTest method getPreheat.

private TrackerPreheat getPreheat() {
    RelationshipType uniDirectionalRelationshipType = createRelationshipType('A');
    uniDirectionalRelationshipType.setUid(RELATIONSHIP_TYPE_UID);
    uniDirectionalRelationshipType.setBidirectional(false);
    RelationshipType biDirectionalRelationshipType = createRelationshipType('B');
    biDirectionalRelationshipType.setUid(BIDIRECTIONAL_RELATIONSHIP_TYPE_UID);
    biDirectionalRelationshipType.setBidirectional(true);
    TrackerPreheat trackerPreheat = new TrackerPreheat();
    trackerPreheat.put(TrackerIdentifier.UID, Lists.newArrayList(biDirectionalRelationshipType, uniDirectionalRelationshipType));
    return trackerPreheat;
}
Also used : RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat)

Example 32 with TrackerPreheat

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

the class EventNoteValidationHookTest method testNoteWithExistingUidWarnings.

@Test
void testNoteWithExistingUidWarnings() {
    // Given
    final Note note = rnd.nextObject(Note.class);
    TrackerBundle trackerBundle = mock(TrackerBundle.class);
    TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
    TrackerPreheat preheat = mock(TrackerPreheat.class);
    when(ctx.getBundle()).thenReturn(trackerBundle);
    when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
    when(trackerBundle.getPreheat()).thenReturn(preheat);
    when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    event.setNotes(Collections.singletonList(note));
    // When
    this.hook.validateEvent(reporter, event);
    // Then
    assertTrue(reporter.hasWarnings());
    assertTrue(reporter.hasWarningReport(r -> TrackerErrorCode.E1119.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
    assertThat(event.getNotes(), hasSize(0));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Mockito.mock(org.mockito.Mockito.mock) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 33 with TrackerPreheat

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

the class AssignedUserValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    hookToTest = new AssignedUserValidationHook();
    TrackerBundle bundle = TrackerBundle.builder().build();
    TrackerPreheat preheat = new TrackerPreheat();
    User user = new User();
    user.setUid(USER_ID);
    preheat.put(TrackerIdentifier.UID, user);
    bundle.setPreheat(preheat);
    when(validationContext.getBundle()).thenReturn(bundle);
    ProgramStage programStage = new ProgramStage();
    programStage.setEnableUserAssignment(true);
    when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
}
Also used : User(org.hisp.dhis.user.User) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

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