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