Search in sources :

Example 16 with AvailabilityStatus

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;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 17 with AvailabilityStatus

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);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with AvailabilityStatus

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());
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 19 with AvailabilityStatus

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);
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpUtils(org.hisp.dhis.system.util.HttpUtils) Test(org.junit.jupiter.api.Test)

Example 20 with AvailabilityStatus

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"));
    }
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpUtils(org.hisp.dhis.system.util.HttpUtils) RemoteServerUnavailableException(org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)28 Test (org.junit.jupiter.api.Test)19 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)14 HttpUtils (org.hisp.dhis.system.util.HttpUtils)12 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)9 IOException (java.io.IOException)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)6 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)5 Date (java.util.Date)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 IntegrationTest (org.hisp.dhis.IntegrationTest)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpResponse (org.apache.http.HttpResponse)3 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)3 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 RemoteServerUnavailableException (org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException)2