Search in sources :

Example 46 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultMetadataSyncServiceTest method testShouldGetMetadataVersionForGivenVersionName.

@Test
void testShouldGetMetadataVersionForGivenVersionName() {
    parameters.put("versionName", new ArrayList<>());
    parameters.get("versionName").add("testVersion");
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    when(metadataVersionDelegate.getRemoteMetadataVersion("testVersion")).thenReturn(metadataVersion);
    MetadataSyncParams metadataSyncParams = metadataSyncService.getParamsFromMap(parameters);
    assertEquals(metadataVersion, metadataSyncParams.getVersion());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) Test(org.junit.jupiter.api.Test)

Example 47 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncImportHandlerTest method setup.

@BeforeEach
public void setup() {
    metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    syncParams = new MetadataSyncParams();
    importReport = new ImportReport();
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 48 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion 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 49 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldReturnEmptyMetadataDifference.

@Test
void testShouldReturnEmptyMetadataDifference() {
    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);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.BAD_REQUEST.value());
    try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
        mocked.when(() -> HttpUtils.httpGET(baselineUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
        assertThrows(MetadataVersionServiceException.class, () -> target.getMetaDataDifference(metadataVersion), "Client Error. Http call failed with status code: 400 Caused by: " + dhisHttpResponse.getResponse());
    }
}
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 50 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenRenderServiceThrowsExceptionWhileGettingMetadataDifference.

@Test
void testShouldThrowExceptionWhenRenderServiceThrowsExceptionWhileGettingMetadataDifference() {
    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);
    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);
        when(renderService.fromMetadataVersion(any(ByteArrayInputStream.class), eq(RenderFormat.JSON))).thenThrow(new IOException(""));
        assertThrows(MetadataVersionServiceException.class, () -> target.getMetaDataDifference(metadataVersion), "Exception occurred while trying to do JSON conversion. Caused by: ");
    } 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) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)60 Test (org.junit.jupiter.api.Test)31 Date (java.util.Date)15 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)14 ArrayList (java.util.ArrayList)11 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 HttpUtils (org.hisp.dhis.system.util.HttpUtils)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 IOException (java.io.IOException)7 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)6 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)4 RootNode (org.hisp.dhis.node.types.RootNode)4 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Test (org.junit.Test)3