Search in sources :

Example 76 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOrgUnitImport.

@Test
void testOrgUnitImport() throws Exception {
    ImportReport importReport = runImport("metadata/organisationUnits.csv", CsvImportClass.ORGANISATION_UNIT, metadata -> assertEquals(6, metadata.getOrganisationUnits().size()));
    assertEquals(6, importReport.getStats().getCreated());
    assertEquals(6, organisationUnitService.getAllOrganisationUnits().size());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 77 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOptionSetImport.

@Test
void testOptionSetImport() throws Exception {
    ImportReport importReport = runImport("metadata/optionSets.csv", CsvImportClass.OPTION_SET, metadata -> {
        assertEquals(4, metadata.getOptionSets().size());
        assertEquals(3, metadata.getOptionSets().get(0).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(1).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(2).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(3).getOptions().size());
    });
    assertEquals(16, importReport.getStats().getCreated());
    List<OptionSet> optionSets = new ArrayList<>(optionService.getAllOptionSets());
    assertEquals(4, optionSets.size());
    assertEquals(3, optionSets.get(0).getOptions().size());
    assertEquals(3, optionSets.get(1).getOptions().size());
    assertEquals(3, optionSets.get(2).getOptions().size());
    assertEquals(3, optionSets.get(3).getOptions().size());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ArrayList(java.util.ArrayList) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 78 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataRetryContextTest method testIfSummaryIsNotNull.

@Test
void testIfSummaryIsNotNull() {
    MetadataSyncSummary testSummary = new MetadataSyncSummary();
    ImportReport importReport = new ImportReport();
    importReport.setStatus(Status.ERROR);
    testSummary.setImportReport(importReport);
    metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, testSummary);
    verify(retryContext).setAttribute(testKey, testMessage);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 79 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class TrackedEntityTypeValidationTest method shouldFailMissingTrackedEntityAttribute.

@Test
void shouldFailMissingTrackedEntityAttribute() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setImportMode(ObjectBundleMode.COMMIT);
    importParams.setImportStrategy(ImportStrategy.CREATE);
    importParams.setObjects(metadata);
    ImportReport report = importService.importMetadata(importParams);
    assertEquals(Status.OK, report.getStatus());
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_missing_tea.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParamsFail = new MetadataImportParams();
    importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
    importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importParamsFail.setObjects(importMetadata);
    ImportReport importReport = importService.importMetadata(importParamsFail);
    assertEquals(Status.ERROR, importReport.getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 80 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class TrackedEntityTypeValidationTest method shouldSuccessTrackedEntityAttributeExists.

@Test
void shouldSuccessTrackedEntityAttributeExists() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setImportMode(ObjectBundleMode.COMMIT);
    importParams.setImportStrategy(ImportStrategy.CREATE);
    importParams.setObjects(metadata);
    ImportReport report = importService.importMetadata(importParams);
    assertEquals(Status.OK, report.getStatus());
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_tea_ok.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParamsFail = new MetadataImportParams();
    importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
    importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importParamsFail.setObjects(importMetadata);
    ImportReport importReport = importService.importMetadata(importParamsFail);
    assertEquals(Status.OK, importReport.getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)87 Test (org.junit.jupiter.api.Test)52 List (java.util.List)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)37 ClassPathResource (org.springframework.core.io.ClassPathResource)37 User (org.hisp.dhis.user.User)34 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)33 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)32 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11 IOException (java.io.IOException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 CsvImportOptions (org.hisp.dhis.dxf2.csv.CsvImportOptions)9 InputStream (java.io.InputStream)8 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 UserService (org.hisp.dhis.user.UserService)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8