Search in sources :

Example 56 with MetadataVersion

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());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 57 with MetadataVersion

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);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 58 with MetadataVersion

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"));
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DataElement(org.hisp.dhis.dataelement.DataElement) DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 59 with MetadataVersion

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)));
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 60 with MetadataVersion

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);
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) MetadataVersionException(org.hisp.dhis.webapi.controller.exception.MetadataVersionException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)60 Test (org.junit.jupiter.api.Test)31 Date (java.util.Date)15 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)14 ArrayList (java.util.ArrayList)11 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 HttpUtils (org.hisp.dhis.system.util.HttpUtils)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 IOException (java.io.IOException)7 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)6 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)4 RootNode (org.hisp.dhis.node.types.RootNode)4 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Test (org.junit.Test)3