use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldReturnNullOnInValidDHISResponse.
@Test
void testShouldReturnNullOnInValidDHISResponse() {
when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(downloadUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(new AvailabilityStatus(true, "test_message", null));
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(null);
String actualVersionSnapShot = target.downloadMetadataVersionSnapshot(new MetadataVersion("testVersion", VersionType.BEST_EFFORT));
assertNull(actualVersionSnapShot);
}
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testhandleAggregateDataPushShouldThrowExceptionWhenDataPushIsUnsuccessful.
@Test
void testhandleAggregateDataPushShouldThrowExceptionWhenDataPushIsUnsuccessful() {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
ImportSummary expectedSummary = new ImportSummary();
expectedSummary.setStatus(ImportStatus.ERROR);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
doThrow(MetadataSyncServiceException.class).when(metadataSyncPreProcessor).handleDataValuePush(mockRetryContext, metadataSyncJobParameters);
assertThrows(MetadataSyncServiceException.class, () -> metadataSyncPreProcessor.handleDataValuePush(mockRetryContext, metadataSyncJobParameters));
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus 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.synch.AvailabilityStatus 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.synch.AvailabilityStatus 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));
}
Aggregations