use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramOrgUnitCheckTest method verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit.
private void verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit(String orgUnitId, IdScheme scheme) {
// assign a UID to the event's org unit
event.setOrgUnit(orgUnitId);
// Prepare data
Program program = createProgram('P');
program.setId(1);
OrganisationUnit ou = new OrganisationUnit();
ou.setId(1);
ou.setUid(orgUnitId);
when(workContext.getOrganisationUnitMap()).thenReturn(ImmutableMap.of(event.getUid(), ou));
when(workContext.getProgramWithOrgUnitsMap()).thenReturn(ImmutableMap.of(1L, ImmutableList.of(1L)));
ProgramInstance pi = new ProgramInstance();
pi.setProgram(program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
programInstanceMap.put(event.getUid(), pi);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setOrgUnitIdScheme(scheme.name());
when(workContext.getImportOptions()).thenReturn(importOptions);
// method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(summary);
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class DataValueCheckTest method verifyValidationFailOnJsonSerializationError.
@Test
void verifyValidationFailOnJsonSerializationError() throws JsonProcessingException {
ObjectMapper localObjectMapper = mock(ObjectMapper.class);
when(serviceDelegator.getJsonMapper()).thenReturn(localObjectMapper);
when(localObjectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonProcessingException("Error") {
});
event.setProgramStage("prgstg1");
DataElement de1 = addToDataElementMap(createDataElement('A'));
final Program programA = createProgram('A');
final ProgramStage programStageA = createProgramStage('A', programA);
programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
when(workContext.getProgramStage(IdScheme.UID, "prgstg1")).thenReturn(programStageA);
addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"));
DataValue dv1 = createDataValue(de1.getUid(), "1");
event.setDataValues(Sets.newHashSet(dv1));
final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
assertHasError(summary, event, null);
assertHasConflict(summary, "Invalid data value found.", de1.getUid());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventGeometryCheckTest method failOnEventWithGeometryAndProgramStageWithNoGeometry.
@Test
void failOnEventWithGeometryAndProgramStageWithNoGeometry() {
event.setGeometry(createRandomPoint());
ProgramStage programStage = createProgramStage();
programStage.setFeatureType(FeatureType.NONE);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, "Geometry (Point) does not conform to the feature type (None) specified for the program stage: " + programStage.getUid());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnNoProgramInstanceByActiveProgramAndTei.
@Test
void failOnNoProgramInstanceByActiveProgramAndTei() {
// Data preparation
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
event.setProgram(program.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Tracked entity instance: " + tei.getUid() + " is not enrolled in program: " + program.getUid());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceRepeatableStageCheckTest method failOnNonRepeatableStageAndExistingEvents.
@Test
void failOnNonRepeatableStageAndExistingEvents() {
// Data preparation
Program program = createProgram('P');
TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
event.setProgramStage(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setTrackedEntityInstance(tei.getUid());
ProgramStage programStage = createProgramStage('A', program);
programStage.setRepeatable(false);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
ProgramInstance programInstance = new ProgramInstance();
programInstanceMap.put(event.getUid(), programInstance);
Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), teiPair);
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
when(workContext.getProgramsMap()).thenReturn(programMap);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(true);
// Method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Program stage is not repeatable and an event already exists");
}
Aggregations