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