Search in sources :

Example 16 with MetadataVersion

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnDifferenceOfVersionsFromBaselineVersion.

@Test
public void testHandleMetadataVersionsListShouldReturnDifferenceOfVersionsFromBaselineVersion() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version1");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode1");
    MetadataVersion newVersion = new MetadataVersion();
    newVersion.setType(VersionType.ATOMIC);
    newVersion.setName("test_version2");
    newVersion.setCreated(new Date());
    newVersion.setHashCode("samplehashcode2");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    listOfVersions.add(newVersion);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(listOfVersions);
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    assertEquals(listOfVersions.size(), expectedListOfVersions.size());
    assertEquals(expectedListOfVersions, listOfVersions);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with MetadataVersion

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference.

@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference() throws Exception {
    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");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    listOfVersions.add(currentVersion);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenThrow(new MetadataSyncServiceException("test_message"));
    metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with MetadataVersion

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

the class DefaultMetadataVersionServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Override
protected void setUpTest() {
    MockitoAnnotations.initMocks(this);
    versionA = new MetadataVersion("Version_1", VersionType.ATOMIC);
    versionA.setHashCode("12345");
    versionB = new MetadataVersion("Version_2", VersionType.BEST_EFFORT);
    versionB.setHashCode("abcdef");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion)

Example 19 with MetadataVersion

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

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnEmptyListIfInstanceIsAlreadyOnLatestVersion.

@Test
public void testHandleMetadataVersionsListShouldReturnEmptyListIfInstanceIsAlreadyOnLatestVersion() throws Exception {
    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");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(listOfVersions);
    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.tasks.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with MetadataVersion

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

the class MetadataSyncPreProcessorTest method testShouldGetLatestMetadataVersionForTheGivenVersionList.

@Test
public void testShouldGetLatestMetadataVersionForTheGivenVersionList() throws ParseException {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ");
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version1");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode1");
    MetadataVersion version2 = new MetadataVersion("Version2", VersionType.ATOMIC);
    org.joda.time.DateTime dateTime = dateTimeFormatter.parseDateTime("2016-06-21 10:45:50Z");
    version2.setCreated(dateTime.toDate());
    MetadataVersion version3 = new MetadataVersion("Version3", VersionType.ATOMIC);
    org.joda.time.DateTime dateTime2 = dateTimeFormatter.parseDateTime("2016-06-21 10:45:54Z");
    version3.setCreated(dateTime2.toDate());
    MetadataVersion version4 = new MetadataVersion("Version4", VersionType.ATOMIC);
    org.joda.time.DateTime dateTime3 = dateTimeFormatter.parseDateTime("2016-06-21 10:45:58Z");
    version4.setCreated(dateTime3.toDate());
    List<MetadataVersion> metadataVersionList = new ArrayList<>();
    metadataVersionList.add(version2);
    metadataVersionList.add(version3);
    metadataVersionList.add(version4);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(metadataVersionList);
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    verify(systemSettingManager).saveSystemSetting(SettingKey.REMOTE_METADATA_VERSION, version4.getName());
    assertEquals(3, expectedListOfVersions.size());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ArrayList(java.util.ArrayList) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) 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