Search in sources :

Example 16 with ImportReport

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

the class MetadataSyncImportHandlerTest method testShouldImportMetadataWhenBestEffortWithWarnings.

@Test
public void testShouldImportMetadataWhenBestEffortWithWarnings() throws IOException {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    importReport.setStatus(Status.WARNING);
    metadataVersion.setType(VersionType.BEST_EFFORT);
    when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    doNothing().when(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
    MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
    assertEquals(metadataSyncSummary.getImportReport(), actualMetadataSyncSummary.getImportReport());
    assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
    assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
    assertEquals(metadataSyncSummary.getMetadataVersion().getType(), actualMetadataSyncSummary.getMetadataVersion().getType());
    assertEquals(metadataSyncSummary.getImportReport().getStatus(), actualMetadataSyncSummary.getImportReport().getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with ImportReport

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

the class MetadataSyncImportHandlerTest method testShouldReturnDefaultSummaryWhenImportStatusIsError.

@Test
public void testShouldReturnDefaultSummaryWhenImportStatusIsError() {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    importReport.setStatus(Status.ERROR);
    when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
    MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
    assertEquals(metadataSyncSummary.getImportReport().toString(), actualMetadataSyncSummary.getImportReport().toString());
    assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
    assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with ImportReport

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

the class MetadataSyncImportHandlerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    syncParams = new MetadataSyncParams();
    importReport = new ImportReport();
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Before(org.junit.Before)

Example 19 with ImportReport

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

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsOk.

@Test
public void testShouldSendSuccessEmailIfSyncSummaryIsOk() throws Exception {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockRetryContext, dataVersion);
    assertFalse(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with ImportReport

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

the class MetadataSyncPostProcessorTest method testShouldSendEmailToAdminWithProperSubjectAndBody.

@Test
public void testShouldSendEmailToAdminWithProperSubjectAndBody() throws Exception {
    ImportReport importReport = mock(ImportReport.class);
    when(importReport.getTypeReportMap()).thenReturn(new HashMap<>());
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockRetryContext, dataVersion);
    assertFalse(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)28 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)15 Test (org.junit.Test)14 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 User (org.hisp.dhis.user.User)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 List (java.util.List)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)4 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)4 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)4 IntegrationTest (org.hisp.dhis.IntegrationTest)3 ObjectReport (org.hisp.dhis.feedback.ObjectReport)3 TypeReport (org.hisp.dhis.feedback.TypeReport)3 IOException (java.io.IOException)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)2