MetadataSyncPostProcessor { public boolean handleSyncNotificationsAndAbortStatus( MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion ) { ImportReport importReport = metadataSyncSummary.getImportReport(); if ( importReport == null ) { handleImportFailedContext( null, retryContext, dataVersion ); return true; } Status syncStatus = importReport.getStatus(); log.info( "Import completed. Import Status: " + syncStatus ); if ( Status.OK.equals( syncStatus ) || ( Status.WARNING.equals( syncStatus ) && VersionType.BEST_EFFORT.equals( dataVersion.getType() ) ) ) { sendSuccessMailToAdmin( metadataSyncSummary ); return false; } if ( Status.ERROR.equals( syncStatus ) ) { handleImportFailedContext( metadataSyncSummary, retryContext, dataVersion ); return true; } return false; }  boolean handleSyncNotificationsAndAbortStatus( MetadataSyncSummary metadataSyncSummary, 
        MetadataRetryContext retryContext, MetadataVersion dataVersion ); void handleVersionAlreadyExists( MetadataRetryContext retryContext, MetadataVersion dataVersion ); void sendSuccessMailToAdmin( MetadataSyncSummary metadataSyncSummary ); void sendFailureMailToAdmin( MetadataRetryContext retryContext );  }
@Test public void testShouldSendSuccessEmailIfSyncSummaryIsOk() { metadataSyncSummary.setImportReport( new ImportReport() ); metadataSyncSummary.getImportReport().setStatus( Status.OK ); metadataSyncSummary.setMetadataVersion( dataVersion ); MetadataRetryContext mockRetryContext = mock( MetadataRetryContext.class ); boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus( metadataSyncSummary, mockRetryContext, dataVersion ); assertFalse( status ); }
@Test public void testShouldSendSuccessEmailIfSyncSummaryIsWarning() { metadataSyncSummary.setImportReport( new ImportReport() ); metadataSyncSummary.getImportReport().setStatus( Status.WARNING ); metadataSyncSummary.setMetadataVersion( dataVersion ); MetadataRetryContext mockRetryContext = mock( MetadataRetryContext.class ); boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus( metadataSyncSummary, mockRetryContext, dataVersion ); assertFalse( status ); }
@Test public void testShouldSendSuccessEmailIfSyncSummaryIsError() { metadataSyncSummary.setImportReport( new ImportReport() ); metadataSyncSummary.getImportReport().setStatus( Status.ERROR ); metadataSyncSummary.setMetadataVersion( dataVersion ); MetadataRetryContext mockMetadataRetryContext = mock( MetadataRetryContext.class ); RetryContext mockRetryContext = mock( RetryContext.class ); when( mockMetadataRetryContext.getRetryContext() ).thenReturn( mockRetryContext ); boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus( metadataSyncSummary, mockMetadataRetryContext, dataVersion ); assertTrue( status ); }
@Test public void testShouldSendEmailToAdminWithProperSubjectAndBody() { ImportReport importReport = mock( ImportReport.class ); metadataSyncSummary.setImportReport( importReport ); metadataSyncSummary.getImportReport().setStatus( Status.OK ); metadataSyncSummary.setMetadataVersion( dataVersion ); MetadataRetryContext mockRetryContext = mock( MetadataRetryContext.class ); boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus( metadataSyncSummary, mockRetryContext, dataVersion ); assertFalse( status ); }