Search in sources :

Example 26 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPostProcessor method handleSyncNotificationsAndAbortStatus.

public boolean handleSyncNotificationsAndAbortStatus(MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion) {
    ImportReport importReport = metadataSyncSummary.getImportReport();
    if (importReport == null) {
        handleImportFailedContext(null, retryContext, dataVersion);
        return true;
    }
    Status syncStatus = importReport.getStatus();
    log.info("Import completed. Import Status: " + syncStatus);
    if (Status.OK.equals(syncStatus) || (Status.WARNING.equals(syncStatus) && VersionType.BEST_EFFORT.equals(dataVersion.getType()))) {
        sendSuccessMailToAdmin(metadataSyncSummary);
        return false;
    }
    if (Status.ERROR.equals(syncStatus)) {
        handleImportFailedContext(metadataSyncSummary, retryContext, dataVersion);
        return true;
    }
    return false;
}
Also used : Status(org.hisp.dhis.feedback.Status) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport)

Example 27 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncJobParametersTest method testHandleMetadataSyncIsThrowingException.

@Test
void testHandleMetadataSyncIsThrowingException() throws DhisVersionMismatchException {
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new MetadataSyncServiceException(""));
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    doNothing().when(metadataRetryContext).updateRetryContext(any(String.class), any(String.class), eq(metadataVersion));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    assertThrows(MetadataSyncServiceException.class, () -> metadataSyncJob.runSyncTask(metadataRetryContext, metadataSyncJobParameters));
    verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleDataValuePush(metadataRetryContext, metadataSyncJobParameters);
    verify(metadataSyncPreProcessor).handleEventProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
    verify(metadataSyncPreProcessor).handleTrackerProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
    verify(metadataSyncPreProcessor).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService).doMetadataSync(any(MetadataSyncParams.class));
    verify(metadataSyncPostProcessor, never()).handleSyncNotificationsAndAbortStatus(metadataSyncSummary, metadataRetryContext, metadataVersion);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) Test(org.junit.jupiter.api.Test)

Example 28 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsOk.

@Test
void testShouldSendSuccessEmailIfSyncSummaryIsOk() {
    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.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 29 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendEmailToAdminWithProperSubjectAndBody.

@Test
void testShouldSendEmailToAdminWithProperSubjectAndBody() {
    ImportReport importReport = mock(ImportReport.class);
    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.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 30 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.

@Test
void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() {
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode");
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<>());
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    assertEquals(0, expectedListOfVersions.size());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)15 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)13 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)12 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)11 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)10 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)8 Date (java.util.Date)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 IntegrationTest (org.hisp.dhis.IntegrationTest)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)4 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)3 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1