Search in sources :

Example 16 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary 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 MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary 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 MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary 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 19 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class DefaultMetadataSyncServiceTest method testShouldStoreMetadataSnapshotInDataStoreAndImport.

@Test
public void testShouldStoreMetadataSnapshotInDataStoreAndImport() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    MetadataImportParams metadataImportParams = new MetadataImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(syncParams.getVersion()).thenReturn(metadataVersion);
    when(syncParams.getImportParams()).thenReturn(metadataImportParams);
    when(metadataVersionService.getVersionData("testVersion")).thenReturn(null);
    when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
    MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
    verify(metadataVersionService, times(1)).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    assertEquals(null, actualSummary.getImportReport());
    assertEquals(null, actualSummary.getImportSummary());
    assertEquals(metadataVersion, actualSummary.getMetadataVersion());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary 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

DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Test (org.junit.Test)13 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)9 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)9 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)6 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)5 IntegrationTest (org.hisp.dhis.IntegrationTest)4 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)4 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)4 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)3 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 IOException (java.io.IOException)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 Email (org.hisp.dhis.email.Email)1 RemoteServerUnavailableException (org.hisp.dhis.exception.RemoteServerUnavailableException)1 Stats (org.hisp.dhis.feedback.Stats)1 Status (org.hisp.dhis.feedback.Status)1