use of org.hisp.dhis.dxf2.metadata.jobs.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());
}
use of org.hisp.dhis.dxf2.metadata.jobs.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();
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncJobParametersTest method testShouldAbortIfDHISVersionMismatch.
@Test
void testShouldAbortIfDHISVersionMismatch() throws DhisVersionMismatchException {
metadataVersions.add(metadataVersion);
when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new DhisVersionMismatchException(""));
when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
assertThrows(DhisVersionMismatchException.class, () -> metadataSyncJob.runSyncTask(metadataRetryContext, metadataSyncJobParameters));
verify(metadataSyncPreProcessor, times(1)).setUp(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleDataValuePush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor, times(1)).handleEventProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor, times(1)).handleTrackerProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor, times(1)).handleCurrentMetadataVersion(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
verify(metadataSyncService, times(1)).doMetadataSync(any(MetadataSyncParams.class));
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testhandleAggregateDataPushShouldThrowExceptionWhenDataPushIsUnsuccessful.
@Test
void testhandleAggregateDataPushShouldThrowExceptionWhenDataPushIsUnsuccessful() {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
ImportSummary expectedSummary = new ImportSummary();
expectedSummary.setStatus(ImportStatus.ERROR);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
doThrow(MetadataSyncServiceException.class).when(metadataSyncPreProcessor).handleDataValuePush(mockRetryContext, metadataSyncJobParameters);
assertThrows(MetadataSyncServiceException.class, () -> metadataSyncPreProcessor.handleDataValuePush(mockRetryContext, metadataSyncJobParameters));
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testShouldGetLatestMetadataVersionForTheGivenVersionList.
@Test
void testShouldGetLatestMetadataVersionForTheGivenVersionList() {
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());
}
Aggregations