Search in sources :

Example 11 with MetadataRetryContext

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

the class MetadataSyncPreProcessorTest method testHandleDataPushShouldCallDataPush.

// TODO: Do not assert for methods to be executed. Assert for the result not
// on how it happens.
@Test
void testHandleDataPushShouldCallDataPush() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    metadataSyncPreProcessor.handleDataValuePush(mockRetryContext, metadataSyncJobParameters);
    verify(synchronizationManager, times(1)).executeDataValuePush();
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 12 with MetadataRetryContext

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnEmptyListIfInstanceIsAlreadyOnLatestVersion.

@Test
void testHandleMetadataVersionsListShouldReturnEmptyListIfInstanceIsAlreadyOnLatestVersion() {
    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");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(listOfVersions);
    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) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 13 with MetadataRetryContext

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference.

@Test
void testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference() {
    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");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    listOfVersions.add(currentVersion);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenThrow(new MetadataSyncServiceException("test_message"));
    assertThrows(MetadataSyncServiceException.class, () -> metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion));
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 14 with MetadataRetryContext

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnDifferenceOfVersionsFromBaselineVersion.

@Test
void testHandleMetadataVersionsListShouldReturnDifferenceOfVersionsFromBaselineVersion() {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version1");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode1");
    MetadataVersion newVersion = new MetadataVersion();
    newVersion.setType(VersionType.ATOMIC);
    newVersion.setName("test_version2");
    newVersion.setCreated(new Date());
    newVersion.setHashCode("samplehashcode2");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    listOfVersions.add(newVersion);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(listOfVersions);
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    assertEquals(listOfVersions.size(), expectedListOfVersions.size());
    assertEquals(expectedListOfVersions, listOfVersions);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 15 with MetadataRetryContext

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

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsError.

@Test
void testShouldSendSuccessEmailIfSyncSummaryIsError() {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.ERROR);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockMetadataRetryContext = mock(MetadataRetryContext.class);
    RetryContext mockRetryContext = mock(RetryContext.class);
    when(mockMetadataRetryContext.getRetryContext()).thenReturn(mockRetryContext);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockMetadataRetryContext, dataVersion);
    assertTrue(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) RetryContext(org.springframework.retry.RetryContext) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) 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