Search in sources :

Example 31 with MetadataVersion

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

the class DefaultMetadataSyncServiceTest method testShouldGetMetadataVersionForGivenVersionName.

@Test
public void testShouldGetMetadataVersionForGivenVersionName() throws Exception {
    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.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with MetadataVersion

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

the class DefaultMetadataSyncServiceTest method testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion.

@Test
public void testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = new MetadataSyncParams();
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    MetadataImportParams metadataImportParams = new MetadataImportParams();
    syncParams.setVersion(metadataVersion);
    syncParams.setImportParams(metadataImportParams);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(metadataVersionService.getVersionData("testVersion")).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    metadataSyncService.doMetadataSync(syncParams);
    verify(metadataSyncImportHandler, times(1)).importMetadata((argThat(new ArgumentMatcher<MetadataSyncParams>() {

        @Override
        public boolean matches(Object syncParams) {
            return ((MetadataSyncParams) syncParams).getImportParams().getAtomicMode().equals(AtomicMode.NONE);
        }
    })), eq(expectedMetadataSnapshot));
    verify(metadataVersionService, never()).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    verify(metadataVersionDelegate, never()).downloadMetadataVersionSnapshot(metadataVersion);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 33 with MetadataVersion

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

the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError.

@Test
public void testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError() throws Exception {
    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?versionName=Version_Name";
    when(metadataSystemSettingService.getVersionDetailsUrl("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.CONFLICT.value());
    when(metadataSystemSettingService.getVersionDetailsUrl("testVersion")).thenReturn(versionUrl);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    PowerMockito.when(HttpUtils.httpGET(versionUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
    when(renderService.fromJson(response, MetadataVersion.class)).thenReturn(metadataVersion);
    expectedException.expect(MetadataVersionServiceException.class);
    expectedException.expectMessage("Client Error. Http call failed with status code: " + HttpStatus.CONFLICT.value() + " Caused by: " + response);
    metadataVersionDelegate.getRemoteMetadataVersion("testVersion");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) HttpResponse(org.apache.http.HttpResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 34 with MetadataVersion

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

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

the class MetadataVersionDelegateTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(HttpUtils.class);
    httpResponse = mock(HttpResponse.class);
    metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) HttpResponse(org.apache.http.HttpResponse) Before(org.junit.Before)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)53 DhisSpringTest (org.hisp.dhis.DhisSpringTest)31 Test (org.junit.Test)31 IntegrationTest (org.hisp.dhis.IntegrationTest)15 Date (java.util.Date)14 ArrayList (java.util.ArrayList)12 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)12 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)6 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)6 IOException (java.io.IOException)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)3 RootNode (org.hisp.dhis.node.types.RootNode)3 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Before (org.junit.Before)3