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