use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.
@Test
void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() {
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
MetadataVersion currentVersion = new MetadataVersion();
currentVersion.setType(VersionType.BEST_EFFORT);
currentVersion.setName("test_version");
currentVersion.setCreated(new Date());
currentVersion.setHashCode("samplehashcode");
when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<>());
List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
assertEquals(0, expectedListOfVersions.size());
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem.
@Test
void testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem() {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
MetadataVersion currentVersion = new MetadataVersion();
currentVersion.setType(VersionType.BEST_EFFORT);
currentVersion.setName("test_version");
currentVersion.setCreated(new Date());
currentVersion.setHashCode("samplehashcode");
when(metadataVersionService.getCurrentVersion()).thenReturn(currentVersion);
MetadataVersion actualVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(mockRetryContext);
assertEquals(currentVersion, actualVersion);
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldSaveVersionAndSnapShot.
@Test
void testShouldSaveVersionAndSnapShot() {
versionService.addVersion(versionA);
versionService.saveVersion(VersionType.ATOMIC);
// testing if correct version is saved in metadataVersion table
assertEquals("Version_2", versionService.getCurrentVersion().getName());
assertEquals(VersionType.ATOMIC, versionService.getCurrentVersion().getType());
// testing if correct version name is saved in system setting
assertEquals("Version_2", metadataSystemSettingService.getSystemMetadataVersion());
// testing hash code for the given metadata string
MetadataVersion metadataVersionSnap = versionService.getVersionByName("Version_2");
assertEquals(metadataVersionSnap.getHashCode(), versionService.getCurrentVersion().getHashCode());
// testing if correct version is saved in keyjsonvalue table
List<String> versions = null;
versions = metaDataDatastoreService.getAllVersions();
assertEquals(1, versions.size());
assertEquals("Version_2", versions.get(0));
DataElement de1 = createDataElement('A');
manager.save(de1);
sleepFor(100);
versionService.saveVersion(VersionType.BEST_EFFORT);
DatastoreEntry expectedJson = metaDataDatastoreService.getMetaDataVersion("Version_3");
List<String> allVersions = metaDataDatastoreService.getAllVersions();
assertEquals(2, allVersions.size());
assertEquals("Version_3", allVersions.get(1));
assertEquals(true, expectedJson.getJbPlainValue().contains("DataElementA"));
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldReturnVersionsBetweenGivenTimeStamps.
@Test
void testShouldReturnVersionsBetweenGivenTimeStamps() {
List<MetadataVersion> versions = null;
Date startDate = new Date();
versionService.addVersion(versionA);
versions = versionService.getAllVersionsInBetween(startDate, new Date());
assertEquals(1, versions.size());
assertTrue(compareVersionsUtil(versionA, versions.get(0)));
versionService.addVersion(versionB);
versions = versionService.getAllVersionsInBetween(startDate, new Date());
assertEquals(2, versions.size());
assertTrue(compareVersionsUtil(versionB, versions.get(1)));
Date dateBetweenAandB = DateUtils.addMilliseconds(versions.get(0).getCreated(), 1);
versions = versionService.getAllVersionsInBetween(dateBetweenAandB, new Date());
assertEquals(1, versions.size());
assertTrue(compareVersionsUtil(versionB, versions.get(0)));
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataVersionController method getMetaDataVersion.
// Gets the version by versionName or latest system version
@GetMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion getMetaDataVersion(@RequestParam(value = "versionName", required = false) String versionName) throws MetadataVersionException, BadRequestException {
MetadataVersion versionToReturn = null;
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
if (StringUtils.isNotEmpty(versionName)) {
versionToReturn = versionService.getVersionByName(versionName);
if (versionToReturn == null) {
throw new MetadataVersionException("No metadata version with name " + versionName + " exists. Please check again later.");
}
} else {
versionToReturn = versionService.getCurrentVersion();
if (versionToReturn == null) {
throw new MetadataVersionException("No metadata versions exist. Please check again later.");
}
}
return versionToReturn;
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException("Exception occurred while getting metadata version." + (StringUtils.isNotEmpty(versionName) ? versionName : " ") + ex.getMessage(), ex);
}
}
Aggregations