MetadataSyncPreProcessor { public void handleDataValuePush( MetadataRetryContext context, MetadataSyncJobParameters jobParameters ) { SynchronizationResult dataValuesSynchronizationResult = dataValueSync.synchronizeData( jobParameters.getDataValuesPageSize() ); if ( dataValuesSynchronizationResult.status == SynchronizationStatus.FAILURE ) { context.updateRetryContext( MetadataSyncJob.DATA_PUSH_SUMMARY, dataValuesSynchronizationResult.message, null, null ); throw new MetadataSyncServiceException( dataValuesSynchronizationResult.message ); } } MetadataSyncPreProcessor(
        SystemSettingManager systemSettingManager,
        MetadataVersionService metadataVersionService,
        MetadataVersionDelegate metadataVersionDelegate,
        TrackerSynchronization trackerSync,
        EventSynchronization eventSync,
        DataValueSynchronization dataValueSync,
        CompleteDataSetRegistrationSynchronization completeDataSetRegistrationSync ); void setUp( MetadataRetryContext context ); void handleDataValuePush( MetadataRetryContext context, MetadataSyncJobParameters jobParameters ); void handleTrackerProgramsDataPush( MetadataRetryContext context, MetadataSyncJobParameters jobParameters ); void handleEventProgramsDataPush( MetadataRetryContext context, MetadataSyncJobParameters jobParameters ); List<MetadataVersion> handleMetadataVersionsList( MetadataRetryContext context, MetadataVersion metadataVersion ); MetadataVersion handleCurrentMetadataVersion( MetadataRetryContext context ); void handleCompleteDataSetRegistrationDataPush( MetadataRetryContext context );  }
@Test public void testHandleDataPushShouldCallDataPush() throws Exception { MetadataRetryContext mockRetryContext = mock( MetadataRetryContext.class ); AvailabilityStatus availabilityStatus = new AvailabilityStatus( true, "test_message", null ); when( synchronizationManager.isRemoteServerAvailable() ).thenReturn( availabilityStatus ); metadataSyncPreProcessor.handleDataValuePush( mockRetryContext, metadataSyncJobParameters ); verify( synchronizationManager, times( 1 ) ).executeDataValuePush(); }
@Test( expected = MetadataSyncServiceException.class ) public void testhandleAggregateDataPushShouldThrowExceptionWhenDataPushIsUnsuccessful() throws Exception { 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 ); metadataSyncPreProcessor.handleDataValuePush( mockRetryContext, metadataSyncJobParameters ); }
@Test public void testhandleAggregateDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful() throws Exception { MetadataRetryContext mockRetryContext = mock( MetadataRetryContext.class ); ImportSummary expectedSummary = new ImportSummary(); expectedSummary.setStatus( ImportStatus.SUCCESS ); AvailabilityStatus availabilityStatus = new AvailabilityStatus( true, "test_message", null ); when( synchronizationManager.isRemoteServerAvailable() ).thenReturn( availabilityStatus ); doNothing().when( metadataSyncPreProcessor ).handleDataValuePush( mockRetryContext, metadataSyncJobParameters ); metadataSyncPreProcessor.handleDataValuePush( mockRetryContext, metadataSyncJobParameters ); verify( metadataSyncPreProcessor, times( 1 ) ).handleDataValuePush( mockRetryContext, metadataSyncJobParameters ); }