Search in sources :

Example 26 with AvailabilityStatus

use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldGetMetaDataDifferenceWithStatusOk.

@Test
void testShouldGetMetaDataDifferenceWithStatusOk() {
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    String url = "http://localhost:9080/api/metadata/version/history?baseline=testVersion";
    when(metadataSystemSettingService.getMetaDataDifferenceURL("testVersion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    HttpResponse httpResponse = mock(HttpResponse.class);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
    try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
        mocked.when(() -> HttpUtils.httpGET(baselineUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
        List<MetadataVersion> metadataVersionList = new ArrayList<>();
        metadataVersionList.add(metadataVersion);
        when(metadataSystemSettingService.getMetaDataDifferenceURL("testVersion")).thenReturn(baselineUrl);
        when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
        when(renderService.fromMetadataVersion(any(ByteArrayInputStream.class), eq(RenderFormat.JSON))).thenReturn(metadataVersionList);
        List<MetadataVersion> metaDataDifference = target.getMetaDataDifference(metadataVersion);
        assertEquals(metaDataDifference.size(), metadataVersionList.size());
        assertEquals(metadataVersionList.get(0).getType(), metaDataDifference.get(0).getType());
        assertEquals(metadataVersionList.get(0).getName(), metaDataDifference.get(0).getName());
        assertEquals(metadataVersionList.get(0).getHashCode(), metaDataDifference.get(0).getHashCode());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
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) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 27 with AvailabilityStatus

use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError.

@Test
void testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError() {
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    HttpResponse httpResponse = mock(HttpResponse.class);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.CONFLICT.value());
    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)).thenReturn(dhisHttpResponse);
        assertThrows(MetadataVersionServiceException.class, () -> target.getRemoteMetadataVersion("testVersion"), "Client Error. Http call failed with status code: " + HttpStatus.CONFLICT.value() + " Caused by: " + response);
    }
}
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) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with AvailabilityStatus

use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.

@Test
void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() {
    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");
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<>());
    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) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 29 with AvailabilityStatus

use of org.hisp.dhis.dxf2.synch.AvailabilityStatus in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testhandleAggregateDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful.

@Test
void testhandleAggregateDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful() {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    ImportSummary expectedSummary = new ImportSummary();
    expectedSummary.setStatus(ImportStatus.SUCCESS);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    doNothing().when(metadataSyncPreProcessor).handleDataValuePush(mockRetryContext, metadataSyncJobParameters);
    metadataSyncPreProcessor.handleDataValuePush(mockRetryContext, metadataSyncJobParameters);
    verify(metadataSyncPreProcessor, times(1)).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)

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