use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.
the class DataValueSetServiceIntegrationTest method testImportUpdateValuesXml.
/**
* Import 12 data values. Then import 6 data values, where 4 are updates.
*/
@Test
public void testImportUpdateValuesXml() throws Exception {
assertEquals(0, dataValueService.getAllDataValues().size());
in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSet(in);
assertEquals(12, summary.getImportCount().getImported());
assertEquals(12, dataValueService.getAllDataValues().size());
// Update
in = new ClassPathResource("datavalueset/dataValueSetBUpdate.xml").getInputStream();
summary = dataValueSetService.saveDataValueSet(in);
assertEquals(2, summary.getImportCount().getImported());
assertEquals(4, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(14, dataValueService.getAllDataValues().size());
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.
the class DataValueSetServiceIntegrationTest method testImportDeletedValuesXml.
/**
* Import 12 data values where 4 are marked as deleted. Deleted values should
* count as imports when there are no existing non-deleted matching values.
*/
@Test
public void testImportDeletedValuesXml() throws Exception {
assertEquals(0, dataValueService.getAllDataValues().size());
in = new ClassPathResource("datavalueset/dataValueSetBDeleted.xml").getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSet(in);
assertEquals(12, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(8, dataValueService.getAllDataValues().size());
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testSaveRepeatableStageWithoutEventIdShouldCreateNewEvent.
@Test
@Category(IntegrationTest.class)
public void testSaveRepeatableStageWithoutEventIdShouldCreateNewEvent() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
sessionFactory.getCurrentSession().flush();
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
assertEquals(2, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(3, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents.
@Test
@Category(IntegrationTest.class)
public void testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
sessionFactory.getCurrentSession().flush();
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
assertEquals(2, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
event.setEvent(importSummary.getReference());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(2, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals(2, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testSaveWithoutEnrollmentShouldFail.
@Test
@Category(IntegrationTest.class)
public void testSaveWithoutEnrollmentShouldFail() {
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
ImportSummary importSummary = eventService.addEvent(event, null);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertThat(importSummary.getDescription(), CoreMatchers.containsString("is not enrolled in program"));
}
Aggregations