Search in sources :

Example 6 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeA.

@Test
public void testImportDataValuesXmlWithCodeA() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
    assertEquals(0, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesBooleanCsv.

@Test
public void testImportDataValuesBooleanCsv() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBooleanTest.csv").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSetCsv(in, null, null);
    // False rows
    assertEquals(summary.getConflicts().toString(), 5, summary.getConflicts().size());
    List<String> expectedBools = Lists.newArrayList("true", "false");
    List<DataValue> resultBools = mockDataValueBatchHandler.getInserts();
    for (DataValue dataValue : resultBools) {
        assertTrue(expectedBools.contains(dataValue.getValue()));
    }
}
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 8 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesWithNewPeriod.

@Test
public void testImportDataValuesWithNewPeriod() throws Exception {
    ImportSummary summary = dataValueSetService.saveDataValueSet(new ClassPathResource("datavalueset/dataValueSetC.xml").getInputStream());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(3, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, 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 9 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesInvalidAttributeOptionComboOrgUnit.

@Test
public void testImportDataValuesInvalidAttributeOptionComboOrgUnit() throws Exception {
    categoryOptionA.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    categoryService.updateDataElementCategoryOption(categoryOptionA);
    in = new ClassPathResource("datavalueset/dataValueSetH.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(summary.getConflicts().toString(), 1, summary.getConflicts().size());
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(1, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(2, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
    assertTrue(dataValues.contains(new DataValue(deB, peB, ouB, ocDef, ocA)));
}
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 10 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValueSetXml.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
public void testImportDataValueSetXml() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
    assertEquals(0, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) 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