Search in sources :

Example 36 with MetadataVersion

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

the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.

@Test
public void testShouldDownloadMetadataVersion() throws Exception {
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    String url = "http://localhost:9080/api/metadata/version/testVersion/data.gz";
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    PowerMockito.when(HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
    String actualVersionSnapShot = metadataVersionDelegate.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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 37 with MetadataVersion

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

the class MetadataSyncImportHandlerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    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) Before(org.junit.Before)

Example 38 with MetadataVersion

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

the class DefaultMetadataVersionServiceTest method testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate.

@Test
public void testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate() throws Exception {
    MetadataVersion version = new MetadataVersion("test_version1", VersionType.ATOMIC);
    version.setUid("myId");
    Date date = new Date();
    version.setImportDate(date);
    version.setCreated(date);
    version.setHashCode("2asda2d31asd3ads3dadasd");
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(version);
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    assertEquals(version.getName(), ((SimpleNode) versionNodes[0].getChildren().get(0)).getValue());
    assertEquals(version.getType(), ((SimpleNode) versionNodes[0].getChildren().get(1)).getValue());
    assertEquals(version.getCreated(), ((SimpleNode) versionNodes[0].getChildren().get(2)).getValue());
    assertEquals(version.getUid(), ((SimpleNode) versionNodes[0].getChildren().get(3)).getValue());
    assertEquals(version.getImportDate(), ((SimpleNode) versionNodes[0].getChildren().get(4)).getValue());
    assertEquals(version.getHashCode(), ((SimpleNode) versionNodes[0].getChildren().get(5)).getValue());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 39 with MetadataVersion

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

the class DefaultMetadataSyncServiceTest method testShouldStoreMetadataSnapshotInDataStoreAndImport.

@Test
public void testShouldStoreMetadataSnapshotInDataStoreAndImport() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    MetadataImportParams metadataImportParams = new MetadataImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(syncParams.getVersion()).thenReturn(metadataVersion);
    when(syncParams.getImportParams()).thenReturn(metadataImportParams);
    when(metadataVersionService.getVersionData("testVersion")).thenReturn(null);
    when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
    MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
    verify(metadataVersionService, times(1)).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    assertEquals(null, actualSummary.getImportReport());
    assertEquals(null, actualSummary.getImportSummary());
    assertEquals(metadataVersion, actualSummary.getMetadataVersion());
}
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 40 with MetadataVersion

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

the class DefaultMetadataSyncServiceTest method testShouldThrowExceptionWhenSnapshotNotPassingIntegrity.

@Test
public void testShouldThrowExceptionWhenSnapshotNotPassingIntegrity() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(syncParams.getVersion()).thenReturn(metadataVersion);
    when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(false);
    expectedException.expect(MetadataSyncServiceException.class);
    expectedException.expectMessage("Metadata snapshot is corrupted.");
    metadataSyncService.doMetadataSync(syncParams);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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