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());
}
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());
}
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);
}
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());
}
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);
}
Aggregations