Search in sources :

Example 6 with AvailabilityStatus

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

Example 7 with AvailabilityStatus

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

Example 8 with AvailabilityStatus

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();
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 9 with AvailabilityStatus

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());
}
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 10 with AvailabilityStatus

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

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