Search in sources :

Example 21 with ImportSummary

use of org.hisp.dhis.dxf2.common.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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 22 with ImportSummary

use of org.hisp.dhis.dxf2.common.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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 23 with ImportSummary

use of org.hisp.dhis.dxf2.common.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"));
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 24 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithNonExistingDataElementOrgUnit.

@Test
public void testImportDataValuesWithNonExistingDataElementOrgUnit() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetG.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 25 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithStrictPeriods.

@Test
public void testImportDataValuesWithStrictPeriods() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrictPeriods(true);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)102 Test (org.junit.Test)58 DhisSpringTest (org.hisp.dhis.DhisSpringTest)49 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 DataValue (org.hisp.dhis.datavalue.DataValue)18 Event (org.hisp.dhis.dxf2.events.event.Event)17 InputStream (java.io.InputStream)14 Date (java.util.Date)11 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)11 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 IOException (java.io.IOException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 DhisTest (org.hisp.dhis.DhisTest)9 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7