use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleAggregateDataPush.
public ImportSummary handleAggregateDataPush(MetadataRetryContext context) {
log.debug("Entering data push");
ImportSummary importSummary = null;
AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
if (!(remoteServerAvailable.isAvailable())) {
String message = remoteServerAvailable.getMessage();
log.error(message);
context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, remoteServerAvailable.getMessage(), null, null);
throw new MetadataSyncServiceException(message);
}
try {
importSummary = synchronizationManager.executeDataPush();
handleAggregateImportSummary(importSummary, context);
} catch (Exception ex) {
log.error("Exception happened while trying to do data push " + ex.getMessage(), ex);
if (ex instanceof MetadataSyncServiceException) {
throw (MetadataSyncServiceException) ex;
}
context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, ex.getMessage(), null, null);
throw new MetadataSyncServiceException(ex.getMessage(), ex);
}
log.debug("Exiting data push");
return importSummary;
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldNotDownloadMetadataVersion.
@Test
public void testShouldNotDownloadMetadataVersion() throws Exception {
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
String url = "http://localhost:9080/api/metadata/version/testVersion/data.gz";
when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(url);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
PowerMockito.when(HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(null);
String actualMetadataVersionSnapshot = metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion);
assertEquals(null, actualMetadataVersionSnapshot);
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleEventDataPushShouldThrowExceptionWhenEventDataPushIsUnsuccessful.
@Test(expected = MetadataSyncServiceException.class)
public void testHandleEventDataPushShouldThrowExceptionWhenEventDataPushIsUnsuccessful() throws Exception {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
ImportSummaries expectedSummary = new ImportSummaries();
ImportSummary summary = new ImportSummary();
summary.setStatus(ImportStatus.ERROR);
expectedSummary.addImportSummary(summary);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
when(metadataSyncPreProcessor.handleEventDataPush(mockRetryContext)).thenReturn(expectedSummary);
ImportSummaries actualSummary = metadataSyncPreProcessor.handleEventDataPush(mockRetryContext);
assertEquals(expectedSummary.getImportSummaries().get(0).getStatus(), actualSummary.getImportSummaries().get(0).getStatus());
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.
@Test
void testShouldDownloadMetadataVersion() {
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)) {
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
mocked.when(() -> HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
String actualVersionSnapShot = target.downloadMetadataVersionSnapshot(metadataVersion);
assertEquals(response, actualVersionSnapShot);
}
}
use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenHTTPRequestFails.
@Test
void testShouldThrowExceptionWhenHTTPRequestFails() {
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "testMessage", null);
when(metadataSystemSettingService.getVersionDetailsUrl("testVersion")).thenReturn(versionUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(versionUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenThrow(new Exception(""));
assertThrows(MetadataVersionServiceException.class, () -> target.getRemoteMetadataVersion("testVersion"));
}
}
Aggregations