Search in sources :

Example 11 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncTaskTest method testHandleMetadataSyncIsThrowingException.

@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataSyncIsThrowingException() throws Exception {
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new MetadataSyncServiceException(""));
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    doNothing().when(metadataRetryContext).updateRetryContext(any(String.class), any(String.class), eq(metadataVersion));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    metadataSyncTask.runSyncTask(metadataRetryContext);
    verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleAggregateDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleEventDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService).doMetadataSync(any(MetadataSyncParams.class));
    verify(metadataSyncPostProcessor, never()).handleSyncNotificationsAndAbortStatus(metadataSyncSummary, metadataRetryContext, metadataVersion);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleEventDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful.

@Test
public void testHandleEventDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    ImportSummaries expectedSummary = new ImportSummaries();
    ImportSummary summary = new ImportSummary();
    summary.setStatus(ImportStatus.SUCCESS);
    expectedSummary.addImportSummary(summary);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    when(metadataSyncPreProcessor.handleEventDataPush(mockRetryContext)).thenReturn(expectedSummary);
    ImportSummaries actualSummary = metadataSyncPreProcessor.handleEventDataPush(mockRetryContext);
    assertEquals(expectedSummary.getImportSummaries().get(0).getStatus(), actualSummary.getImportSummaries().get(0).getStatus());
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleEventDataPushShouldCallEventDataPush.

@Test
public void testHandleEventDataPushShouldCallEventDataPush() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    metadataSyncPreProcessor.handleEventDataPush(mockRetryContext);
    verify(synchronizationManager, times(1)).executeEventPush();
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext 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 15 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext 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

DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 Test (org.junit.Test)18 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)16 IntegrationTest (org.hisp.dhis.IntegrationTest)14 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)11 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)9 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)9 Date (java.util.Date)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 ArrayList (java.util.ArrayList)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)2 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)2 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1 Status (org.hisp.dhis.feedback.Status)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1