JobConfigurationObjectBundleHook extends AbstractObjectBundleHook { List<ErrorReport> validateInternal( final JobConfiguration jobConfiguration ) { List<ErrorReport> errorReports = new ArrayList<>(); JobConfiguration persistedJobConfiguration = jobConfigurationService.getJobConfigurationByUid( jobConfiguration.getUid() ); final JobConfiguration tempJobConfiguration = validatePersistedAndPrepareTempJobConfiguration( errorReports, jobConfiguration, persistedJobConfiguration ); validateJobConfigurationCronOrFixedDelay( errorReports, tempJobConfiguration ); validateCronExpressionWithinJobType( errorReports, tempJobConfiguration ); if ( tempJobConfiguration.getJobParameters() != null ) { tempJobConfiguration.getJobParameters().validate().ifPresent( errorReports::add ); } else { if ( tempJobConfiguration.getJobType().hasJobParameters() ) { errorReports.add( new ErrorReport( this.getClass(), ErrorCode.E4029, tempJobConfiguration.getJobType() ) ); } } validateJob( errorReports, tempJobConfiguration, persistedJobConfiguration ); return errorReports; } JobConfigurationObjectBundleHook( JobConfigurationService jobConfigurationService,
        SchedulingManager schedulingManager ); @Override List<ErrorReport> validate( T object, ObjectBundle bundle ); @Override void preCreate( T object, ObjectBundle bundle ); @Override void preUpdate( IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle ); @Override void preDelete( T persistedObject, ObjectBundle bundle ); @Override void postCreate( T persistedObject, ObjectBundle bundle ); @Override void postUpdate( T persistedObject, ObjectBundle bundle );  }
@Test public void validateInternalNonConfigurableChangeError() { Mockito.when( jobConfigurationService.getJobConfigurationByUid( Mockito.eq( "jsdhJSJHD" ) ) ) .thenReturn( analyticsTableJobConfig ); Mockito.when( schedulingManager.getJob( Mockito.eq( JobType.ANALYTICSTABLE_UPDATE ) ) ) .thenReturn( job ); JobConfiguration jobConfiguration = new JobConfiguration(); jobConfiguration.setUid( "jsdhJSJHD" ); jobConfiguration.setJobType( JobType.ANALYTICSTABLE_UPDATE ); jobConfiguration.setCronExpression( CRON_HOURLY ); jobConfiguration.setEnabled( false ); List<ErrorReport> errorReports = hook.validateInternal( jobConfiguration ); Assert.assertEquals( 1, errorReports.size() ); Assert.assertEquals( ErrorCode.E7003, errorReports.get( 0 ).getErrorCode() ); }
@Test public void validateInternalNonConfigurableChange() { Mockito.when( jobConfigurationService.getJobConfigurationByUid( Mockito.eq( "jsdhJSJHD" ) ) ) .thenReturn( analyticsTableJobConfig ); Mockito.when( schedulingManager.getJob( Mockito.eq( JobType.ANALYTICSTABLE_UPDATE ) ) ) .thenReturn( job ); JobConfiguration jobConfiguration = new JobConfiguration(); jobConfiguration.setUid( "jsdhJSJHD" ); jobConfiguration.setJobType( JobType.ANALYTICSTABLE_UPDATE ); jobConfiguration.setCronExpression( CRON_HOURLY ); jobConfiguration.setEnabled( true ); List<ErrorReport> errorReports = hook.validateInternal( jobConfiguration ); Assert.assertEquals( 0, errorReports.size() ); }
@Test public void validateCronExpressionForCronTypeJobs() { String jobConfigUid = "jsdhJSJHD"; Mockito.when( jobConfigurationService.getJobConfigurationByUid( Mockito.eq( jobConfigUid ) ) ) .thenReturn( analyticsTableJobConfig ); Mockito.when( schedulingManager.getJob( Mockito.eq( JobType.ANALYTICSTABLE_UPDATE ) ) ) .thenReturn( job ); JobConfiguration jobConfiguration = new JobConfiguration(); jobConfiguration.setUid( jobConfigUid ); jobConfiguration.setJobType( JobType.ANALYTICSTABLE_UPDATE ); jobConfiguration.setEnabled( true ); List<ErrorReport> errorReports = hook.validateInternal( jobConfiguration ); Assert.assertEquals( 1, errorReports.size() ); Assert.assertEquals( ErrorCode.E7004, errorReports.get( 0 ).getErrorCode() ); }
@Test public void validateDelayForFixedIntervalTypeJobs() { String jobConfigUid = "o8kG3Qk3nG3"; JobConfiguration contAnalyticsTableJobConfig = new JobConfiguration(); contAnalyticsTableJobConfig.setUid( jobConfigUid ); contAnalyticsTableJobConfig.setJobType( JobType.CONTINUOUS_ANALYTICS_TABLE ); Mockito.when( jobConfigurationService.getJobConfigurationByUid( Mockito.eq( jobConfigUid ) ) ) .thenReturn( contAnalyticsTableJobConfig ); Mockito.when( schedulingManager.getJob( Mockito.eq( JobType.CONTINUOUS_ANALYTICS_TABLE ) ) ) .thenReturn( job ); JobConfiguration jobConfiguration = new JobConfiguration(); jobConfiguration.setUid( jobConfigUid ); jobConfiguration.setJobType( JobType.CONTINUOUS_ANALYTICS_TABLE ); jobConfiguration.setJobParameters( new ContinuousAnalyticsJobParameters( 1, null, null ) ); List<ErrorReport> errorReports = hook.validateInternal( jobConfiguration ); Assert.assertEquals( 1, errorReports.size() ); Assert.assertEquals( ErrorCode.E7007, errorReports.get( 0 ).getErrorCode() ); }