diff --git a/core/src/main/java/org/pentaho/platform/web/http/api/resources/SchedulerResource.java b/core/src/main/java/org/pentaho/platform/web/http/api/resources/SchedulerResource.java index fd67acbd..2e18c95f 100644 --- a/core/src/main/java/org/pentaho/platform/web/http/api/resources/SchedulerResource.java +++ b/core/src/main/java/org/pentaho/platform/web/http/api/resources/SchedulerResource.java @@ -606,13 +606,39 @@ public String isScheduleAllowed( @QueryParam( "id" ) String id ) { @Path( "/canSchedule" ) @Produces( APPLICATION_JSON ) @StatusCodes( { - @ResponseCode( code = 200, condition = "Successful retrieved the scheduling permission." ), + @ResponseCode( code = 200, condition = "Successfully retrieved the scheduling permission." ), @ResponseCode( code = 500, condition = "Unable to retrieve the scheduling permission." ) } ) public String doGetCanSchedule() { return schedulerService.doGetCanSchedule(); } + /** + * Checks whether the current user has authority to execute schedules in the platform. + * + *

Example Request:
+ * GET pentaho/api/scheduler/canExecuteSchedules + *

+ * + *

Example Response:

+ *
+   *   true
+   * 
+ * + * @return true or false. true indicates schedule execution is allowed and false indicates schedule execution is + * not allowed for the user. + */ + @GET + @Path( "/canExecuteSchedules" ) + @Produces( APPLICATION_JSON ) + @StatusCodes( { + @ResponseCode( code = 200, condition = "Successfully retrieved the scheduling permission." ), + @ResponseCode( code = 500, condition = "Unable to retrieve the scheduling permission." ) + } ) + public String doGetCanExecuteSchedules() { + return schedulerService.doGetCanExecuteSchedule(); + } + /** * Returns the state of the scheduler with the value of RUNNING or PAUSED. * diff --git a/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/ISchedulerServicePlugin.java b/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/ISchedulerServicePlugin.java index 2817c96b..3ba8b702 100644 --- a/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/ISchedulerServicePlugin.java +++ b/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/ISchedulerServicePlugin.java @@ -51,7 +51,8 @@ */ public interface ISchedulerServicePlugin { /* - * TODO I don't think createJob actually throws IOException. look into changing IOException, SchedulerException, IllegalAccessException, -> SchedulerException, + * TODO I don't think createJob actually throws IOException. look into changing IOException, SchedulerException, + * IllegalAccessException, -> SchedulerException, */ Job createJob( JobScheduleRequest jobScheduleRequest ) throws IOException, SchedulerException, IllegalAccessException; @@ -67,6 +68,8 @@ public interface ISchedulerServicePlugin { String doGetCanSchedule(); + String doGetCanExecuteSchedule(); + String getState() throws SchedulerException; String start() throws SchedulerException; diff --git a/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/SchedulerService.java b/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/SchedulerService.java index 26697443..1a0180bd 100644 --- a/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/SchedulerService.java +++ b/core/src/main/java/org/pentaho/platform/web/http/api/resources/services/SchedulerService.java @@ -32,6 +32,7 @@ import org.pentaho.platform.api.repository2.unified.IUnifiedRepository; import org.pentaho.platform.api.repository2.unified.RepositoryFile; import org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException; +import org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto; import org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider; import org.pentaho.platform.api.scheduler2.IBlockoutManager; import org.pentaho.platform.api.scheduler2.IJob; @@ -40,15 +41,15 @@ import org.pentaho.platform.api.scheduler2.IJobTrigger; import org.pentaho.platform.api.scheduler2.IScheduler; import org.pentaho.platform.api.scheduler2.Job; +import org.pentaho.platform.api.scheduler2.JobState; import org.pentaho.platform.api.scheduler2.SchedulerException; import org.pentaho.platform.engine.core.system.PentahoSessionHolder; import org.pentaho.platform.engine.core.system.PentahoSystem; import org.pentaho.platform.engine.security.SecurityHelper; -import org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto; import org.pentaho.platform.scheduler2.blockout.BlockoutAction; -import org.pentaho.platform.api.scheduler2.JobState; import org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction; import org.pentaho.platform.security.policy.rolebased.actions.SchedulerAction; +import org.pentaho.platform.security.policy.rolebased.actions.SchedulerExecuteAction; import org.pentaho.platform.util.ActionUtil; import org.pentaho.platform.util.messages.LocaleHelper; import org.pentaho.platform.web.http.api.proxies.BlockStatusProxy; @@ -65,42 +66,37 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +@SuppressWarnings( "unused" ) public class SchedulerService implements ISchedulerServicePlugin { - + private static final Log logger = LogFactory.getLog( SchedulerService.class ); protected IScheduler scheduler = PentahoSystem.get( IScheduler.class, "IScheduler2", null ); //$NON-NLS-1$ - protected IAuthorizationPolicy policy; - protected IUnifiedRepository repository; - protected SessionResource sessionResource; - protected FileService fileService; - protected IBlockoutManager blockoutManager; - private static final Log logger = LogFactory.getLog( SchedulerService.class ); - @Override public Job createJob( JobScheduleRequest scheduleRequest ) throws IOException, SchedulerException, IllegalAccessException { - // Used to determine if created by a RunInBackgroundCommand boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null; - if ( !runInBackground && !getPolicy().isAllowed( SchedulerAction.NAME ) ) { + if ( !runInBackground && !isScheduleAllowed() ) { throw new SecurityException(); } boolean hasInputFile = !StringUtils.isEmpty( scheduleRequest.getInputFile() ); RepositoryFile file = null; + if ( hasInputFile ) { try { file = getRepository().getFile( scheduleRequest.getInputFile() ); @@ -110,7 +106,7 @@ public Job createJob( JobScheduleRequest scheduleRequest ) } } - // if we have an inputfile, generate job name based on that if the name is not passed in + // if we have an input file, generate job name based on that if the name is not passed in if ( hasInputFile && StringUtils.isEmpty( scheduleRequest.getJobName() ) ) { scheduleRequest.setJobName( file.getName().substring( 0, file.getName().lastIndexOf( "." ) ) ); //$NON-NLS-1$ } else if ( !StringUtils.isEmpty( scheduleRequest.getActionClass() ) ) { @@ -128,9 +124,12 @@ public Job createJob( JobScheduleRequest scheduleRequest ) throw new SchedulerException( new ServiceException( "Cannot find input source file " + scheduleRequest.getInputFile() ) ); } + Map metadata = getRepository().getFileMetadata( file.getId() ); + if ( metadata.containsKey( RepositoryFile.SCHEDULABLE_KEY ) ) { boolean schedulable = BooleanUtils.toBoolean( (String) metadata.get( RepositoryFile.SCHEDULABLE_KEY ) ); + if ( !schedulable ) { throw new IllegalAccessException(); } @@ -141,13 +140,14 @@ public Job createJob( JobScheduleRequest scheduleRequest ) updateStartDateForTimeZone( scheduleRequest ); } - Job job = null; + Job job; IJobTrigger jobTrigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); HashMap parameterMap = new HashMap<>(); - List parameters = (ArrayList)(ArrayList) scheduleRequest.getJobParameters(); + List parameters = scheduleRequest.getJobParameters(); + for ( IJobScheduleParam param : parameters ) { parameterMap.put( param.getName(), param.getValue() ); } @@ -177,11 +177,12 @@ public Job createJob( JobScheduleRequest scheduleRequest ) parameterMap.put( ActionUtil.QUARTZ_STREAMPROVIDER_INPUT_FILE, inputFile ); job = (Job) schedulerCreateJob( scheduleRequest.getJobName(), actionId, parameterMap, jobTrigger, - inputFile, outputFile, scheduleRequest ); + inputFile, outputFile, scheduleRequest ); } else { //TODO need to locate actions from plugins if done this way too (but for now, we're just on main) - // We will first attempt to get action class and if it fails we get the registerd bean id. + // We will first attempt to get action class and if it fails we get the registered bean id. String actionClass = scheduleRequest.getActionClass(); + try { Class iaction = getAction( actionClass ); job = (Job) getScheduler().createJob( scheduleRequest.getJobName(), iaction, parameterMap, jobTrigger ); @@ -197,8 +198,6 @@ public Job createJob( JobScheduleRequest scheduleRequest ) /** * Wrapper function around {@link SchedulerOutputPathResolver#resolveOutputFilePath()} calls * {@link #getSchedulerOutputPathResolver(JobScheduleRequest)} to get instance. - * @param scheduleRequest - * @return */ protected String resolveOutputFilePath( JobScheduleRequest scheduleRequest ) { SchedulerOutputPathResolver outputPathResolver = getSchedulerOutputPathResolver( scheduleRequest ); @@ -206,21 +205,13 @@ protected String resolveOutputFilePath( JobScheduleRequest scheduleRequest ) { } /** - * Wrapper function around {@link IScheduler#createJob(String, Class, Map, IJobTrigger, IBackgroundExecutionStreamProvider)} . + * Wrapper function around + * {@link IScheduler#createJob(String, Class, Map, IJobTrigger, IBackgroundExecutionStreamProvider)} . * Mainly allowing for different implementation for the underlying input and output streams * through {@link #createIBackgroundExecutionStreamProvider(String, String, JobScheduleRequest)} - * @param jobName - * @param action - * @param jobParams - * @param trigger - * @param inputFilePath - * @param outputFilePath - * @param jobScheduleRequest - * @return - * @throws SchedulerException */ protected IJob schedulerCreateJob( String jobName, String action, Map jobParams, - IJobTrigger trigger, final String inputFilePath, final String outputFilePath, + IJobTrigger trigger, final String inputFilePath, final String outputFilePath, JobScheduleRequest jobScheduleRequest ) throws SchedulerException { return getScheduler().createJob( jobName, action, jobParams, trigger, createIBackgroundExecutionStreamProvider( inputFilePath, outputFilePath, jobScheduleRequest ) ); @@ -228,25 +219,20 @@ protected IJob schedulerCreateJob( String jobName, String action, Map jobs = getScheduler().getJobs( getJobFilter( canAdminister, principalName ) ); - if ( jobs.size() > 0 ) { + if ( !jobs.isEmpty() ) { return (Job) jobs.get( 0 ); } return null; } - /** - * @param lineageId - * @return - * @throws FileNotFoundException - */ @Override public List doGetGeneratedContentForSchedule( String lineageId ) throws FileNotFoundException { return getFileService().searchGeneratedContent( getSessionResource().doGetCurrentUserDir(), lineageId, @@ -316,15 +302,22 @@ public boolean isScheduleAllowed() { return getPolicy().isAllowed( SchedulerAction.NAME ); } + public boolean isExecuteScheduleAllowed() { + return getPolicy().isAllowed( SchedulerExecuteAction.NAME ); + } + @Override public boolean isScheduleAllowed( String id ) { - Boolean canSchedule = isScheduleAllowed(); + boolean canSchedule = isScheduleAllowed(); + if ( canSchedule ) { Map metadata = getRepository().getFileMetadata( id ); + if ( metadata.containsKey( RepositoryFile.SCHEDULABLE_KEY ) ) { canSchedule = BooleanUtils.toBoolean( (String) metadata.get( RepositoryFile.SCHEDULABLE_KEY ) ); } } + return canSchedule; } @@ -332,10 +325,9 @@ public IJobFilter getJobFilter( boolean canAdminister, String principalName ) { return new JobFilter( canAdminister, principalName ); } - private class JobFilter implements IJobFilter { - - private boolean canAdminister; - private String principalName; + private static class JobFilter implements IJobFilter { + private final boolean canAdminister; + private final String principalName; public JobFilter( boolean canAdminister, String principalName ) { this.canAdminister = canAdminister; @@ -345,17 +337,24 @@ public JobFilter( boolean canAdminister, String principalName ) { @Override public boolean accept( IJob job ) { String actionClass = (String) job.getJobParams().get( "ActionAdapterQuartzJob-ActionClass" ); + if ( canAdminister && "org.pentaho.platform.admin.GeneratedContentCleaner".equals( actionClass ) ) { return true; } - return principalName.equals( ( (Job) job).getUserName() ) - && "org.pentaho.platform.admin.GeneratedContentCleaner".equals( actionClass ); + + return principalName.equals( job.getUserName() ) && "org.pentaho.platform.admin.GeneratedContentCleaner".equals( + actionClass ); } } @Override public String doGetCanSchedule() { - return String.valueOf( getPolicy().isAllowed( SchedulerAction.NAME ) ); + return String.valueOf( isScheduleAllowed() ); + } + + @Override + public String doGetCanExecuteSchedule() { + return String.valueOf( isExecuteScheduleAllowed() ); } @Override @@ -365,76 +364,89 @@ public String getState() throws SchedulerException { @Override public String start() throws SchedulerException { - if ( getPolicy().isAllowed( SchedulerAction.NAME ) ) { + if ( isScheduleAllowed() ) { getScheduler().start(); } + return getScheduler().getStatus().name(); } @Override public String pause() throws SchedulerException { - if ( getPolicy().isAllowed( SchedulerAction.NAME ) ) { + if ( isScheduleAllowed() ) { getScheduler().pause(); } + return getScheduler().getStatus().name(); } @Override public String shutdown() throws SchedulerException { - if ( getPolicy().isAllowed( SchedulerAction.NAME ) ) { + if ( isScheduleAllowed() ) { getScheduler().shutdown(); } + return getScheduler().getStatus().name(); } @Override public JobState pauseJob( String jobId ) throws SchedulerException { Job job = (Job) getJob( jobId ); + if ( isScheduleAllowed() || PentahoSessionHolder.getSession().getName().equals( job.getUserName() ) ) { getScheduler().pauseJob( jobId ); } + job = (Job) getJob( jobId ); + return job.getState(); } @Override public JobState resumeJob( String jobId ) throws SchedulerException { Job job = (Job) getJob( jobId ); + if ( isScheduleAllowed() || PentahoSessionHolder.getSession().getName().equals( job.getUserName() ) ) { getScheduler().resumeJob( jobId ); } + job = (Job) getJob( jobId ); + return job.getState(); } @Override public boolean removeJob( String jobId ) throws SchedulerException { Job job = (Job) getJob( jobId ); + if ( isScheduleAllowed() || PentahoSessionHolder.getSession().getName().equals( job.getUserName() ) ) { getScheduler().removeJob( jobId ); return true; } + return false; } + @SuppressWarnings( "java:S112" ) @Override public IJob getJobInfo( String jobId ) throws SchedulerException { Job job = (Job) getJob( jobId ); + if ( job == null ) { return null; } + if ( canAdminister() || getSession().getName().equals( job.getUserName() ) ) { for ( String key : job.getJobParams().keySet() ) { Serializable value = job.getJobParams().get( key ); - if ( value != null && value.getClass() != null && value.getClass().isArray() ) { - String[] sa = ( new String[ 0 ] ).getClass().cast( value ); + + if ( value != null && value.getClass().isArray() ) { ArrayList list = new ArrayList<>(); - for ( int i = 0; i < sa.length; i++ ) { - list.add( sa[ i ] ); - } + Collections.addAll( list, (String[]) value ); job.getJobParams().put( key, list ); } } + return job; } else { throw new RuntimeException( "Job not found or improper credentials for access" ); @@ -449,7 +461,7 @@ public List getBlockOutJobs() { @Override public boolean hasBlockouts() { List jobs = getBlockoutManager().getBlockOutJobs(); - return jobs != null && jobs.size() > 0; + return jobs != null && !jobs.isEmpty(); } @Override @@ -467,12 +479,14 @@ public IJob addBlockout( JobScheduleRequest jobScheduleRequest ) throws IOException, IllegalAccessException, SchedulerException { if ( canAdminister() ) { jobScheduleRequest.setActionClass( BlockoutAction.class.getCanonicalName() ); - jobScheduleRequest.getJobParameters().add( getJobScheduleParam( IBlockoutManager.DURATION_PARAM, - jobScheduleRequest.getDuration() ) ); + jobScheduleRequest.getJobParameters() + .add( getJobScheduleParam( IBlockoutManager.DURATION_PARAM, jobScheduleRequest.getDuration() ) ); jobScheduleRequest.getJobParameters() .add( getJobScheduleParam( IBlockoutManager.TIME_ZONE_PARAM, jobScheduleRequest.getTimeZone() ) ); + return createJob( jobScheduleRequest ); } + throw new IllegalAccessException(); } @@ -491,13 +505,15 @@ protected void updateStartDateForTimeZone( JobScheduleRequest jobScheduleRequest @Override public IJob updateBlockout( String jobId, JobScheduleRequest jobScheduleRequest ) throws IllegalAccessException, SchedulerException, IOException { + if ( canAdminister() ) { boolean isJobRemoved = removeJob( jobId ); + if ( isJobRemoved ) { - IJob job = addBlockout( jobScheduleRequest ); - return job; + return addBlockout( jobScheduleRequest ); } } + throw new IllegalAccessException(); } @@ -505,11 +521,13 @@ public IJob updateBlockout( String jobId, JobScheduleRequest jobScheduleRequest public BlockStatusProxy getBlockStatus( JobScheduleRequest jobScheduleRequest ) throws SchedulerException { updateStartDateForTimeZone( jobScheduleRequest ); IJobTrigger trigger = convertScheduleRequestToJobTrigger( jobScheduleRequest ); - Boolean totallyBlocked = false; - Boolean partiallyBlocked = getBlockoutManager().isPartiallyBlocked( trigger ); + boolean totallyBlocked = false; + boolean partiallyBlocked = getBlockoutManager().isPartiallyBlocked( trigger ); + if ( partiallyBlocked ) { totallyBlocked = !getBlockoutManager().willFire( trigger ); } + return getBlockStatusProxy( totallyBlocked, partiallyBlocked ); } @@ -546,6 +564,7 @@ public JobScheduleRequest getJobInfo() { @Override public JobState getJobState( JobRequest jobRequest ) throws SchedulerException { Job job = (Job) getJob( jobRequest.getJobId() ); + if ( isScheduleAllowed() || getSession().getName().equals( job.getUserName() ) ) { return job.getState(); } @@ -557,6 +576,7 @@ protected IPentahoSession getSession() { return PentahoSessionHolder.getSession(); } + @SuppressWarnings( "unchecked" ) public Class getAction( String actionClass ) throws ClassNotFoundException { return ( (Class) Class.forName( actionClass ) ); } @@ -565,6 +585,7 @@ public IUnifiedRepository getRepository() { if ( repository == null ) { repository = PentahoSystem.get( IUnifiedRepository.class ); } + return repository; } @@ -587,8 +608,6 @@ public IAuthorizationPolicy getPolicy() { /** * Instantiates {@link SchedulerOutputPathResolver}. - * @param scheduleRequest - * @return */ protected SchedulerOutputPathResolver getSchedulerOutputPathResolver( JobScheduleRequest scheduleRequest ) { return new SchedulerOutputPathResolver( scheduleRequest ); @@ -606,55 +625,48 @@ protected HashMap handlePDIScheduling( RepositoryFile file public boolean getAutoCreateUniqueFilename( final JobScheduleRequest scheduleRequest ) { List jobParameters = scheduleRequest.getJobParameters(); + for ( IJobScheduleParam jobParameter : jobParameters ) { - if ( IScheduler.RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME.equals( jobParameter.getName() ) && "boolean" - .equals( jobParameter.getType() ) ) { + if ( IScheduler.RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME.equals( jobParameter.getName() ) && "boolean".equals( + jobParameter.getType() ) ) { return (Boolean) jobParameter.getValue(); } } + return true; } public String getAppendDateFormat( final JobScheduleRequest scheduleRequest ) { List jobParameters = scheduleRequest.getJobParameters(); + for ( IJobScheduleParam jobParameter : jobParameters ) { - if ( IScheduler.RESERVEDMAPKEY_APPEND_DATE_FORMAT.equals( jobParameter.getName() ) && "string" - .equals( jobParameter.getType() ) ) { + if ( IScheduler.RESERVEDMAPKEY_APPEND_DATE_FORMAT.equals( jobParameter.getName() ) && "string".equals( + jobParameter.getType() ) ) { return (String) jobParameter.getValue(); } } + return null; } @Override public List getJobs() throws SchedulerException { IPentahoSession session = getSession(); - final String principalName = session.getName(); // this authentication wasn't matching with the job user name, + final String principalName = session.getName(); // this authentication wasn't matching with the job username, // changed to get name via the current session - final Boolean canAdminister = canAdminister( session ); + final boolean canAdminister = canAdminister(); - List jobs = getScheduler().getJobs( new IJobFilter() { - @Override - public boolean accept( IJob job ) { - if ( canAdminister ) { - return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals( job.getJobName() ); - } - return principalName.equals( ( (Job) job).getUserName() ); + return getScheduler().getJobs( job -> { + if ( canAdminister ) { + return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals( job.getJobName() ); } - } ); - - return jobs; - } - protected Boolean canAdminister() { - return canAdminister( null ); + return principalName.equals( job.getUserName() ); + } ); } - protected Boolean canAdminister( IPentahoSession session ) { - if ( getPolicy().isAllowed( AdministerSecurityAction.NAME ) ) { - return true; - } - return false; + protected boolean canAdminister() { + return getPolicy().isAllowed( AdministerSecurityAction.NAME ); } protected String resolveActionId( final String inputFile ) { @@ -674,6 +686,7 @@ protected SessionResource getSessionResource() { if ( sessionResource == null ) { sessionResource = new SessionResource(); } + return sessionResource; } diff --git a/core/src/test/java/org/pentaho/platform/web/http/api/resources/services/SchedulerServiceTest.java b/core/src/test/java/org/pentaho/platform/web/http/api/resources/services/SchedulerServiceTest.java index 51384a76..08e50786 100644 --- a/core/src/test/java/org/pentaho/platform/web/http/api/resources/services/SchedulerServiceTest.java +++ b/core/src/test/java/org/pentaho/platform/web/http/api/resources/services/SchedulerServiceTest.java @@ -20,35 +20,6 @@ package org.pentaho.platform.web.http.api.resources.services; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -63,18 +34,18 @@ import org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto; import org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider; import org.pentaho.platform.api.scheduler2.IBlockoutManager; +import org.pentaho.platform.api.scheduler2.IJob; import org.pentaho.platform.api.scheduler2.IJobFilter; import org.pentaho.platform.api.scheduler2.IJobTrigger; import org.pentaho.platform.api.scheduler2.IScheduler; -import org.pentaho.platform.api.scheduler2.IJob; import org.pentaho.platform.api.scheduler2.Job; import org.pentaho.platform.api.scheduler2.JobState; import org.pentaho.platform.api.scheduler2.SchedulerException; -import org.pentaho.platform.api.scheduler2.IActionClassResolver; import org.pentaho.platform.api.scheduler2.SimpleJobTrigger; import org.pentaho.platform.api.util.IPdiContentProvider; import org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction; import org.pentaho.platform.security.policy.rolebased.actions.SchedulerAction; +import org.pentaho.platform.security.policy.rolebased.actions.SchedulerExecuteAction; import org.pentaho.platform.web.http.api.proxies.BlockStatusProxy; import org.pentaho.platform.web.http.api.resources.JobRequest; import org.pentaho.platform.web.http.api.resources.JobScheduleParam; @@ -83,9 +54,38 @@ import org.pentaho.platform.web.http.api.resources.SchedulerResourceUtil; import org.pentaho.platform.web.http.api.resources.SessionResource; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@SuppressWarnings( "unchecked" ) @RunWith( MockitoJUnitRunner.class ) public class SchedulerServiceTest { - private static SchedulerService schedulerService; @Before @@ -105,7 +105,6 @@ public void cleanup() { @Test public void testCreateJob() throws Exception { - List jobParameters = new ArrayList<>(); JobScheduleParam jobScheduleParam1 = mock( JobScheduleParam.class ); doReturn( "name1" ).when( jobScheduleParam1 ).getName(); @@ -130,7 +129,8 @@ public void testCreateJob() throws Exception { SchedulerOutputPathResolver schedulerOutputPathResolver = mock( SchedulerOutputPathResolver.class ); doReturn( "outputFile" ).when( schedulerOutputPathResolver ).resolveOutputFilePath(); - doReturn( schedulerOutputPathResolver ).when( schedulerService ).getSchedulerOutputPathResolver( any( JobScheduleRequest.class ) ); + doReturn( schedulerOutputPathResolver ).when( schedulerService ) + .getSchedulerOutputPathResolver( any( JobScheduleRequest.class ) ); SimpleJobTrigger simpleJobTrigger = mock( SimpleJobTrigger.class ); @@ -151,30 +151,31 @@ public void testCreateJob() throws Exception { doReturn( true ).when( schedulerService ).getAutoCreateUniqueFilename( any( JobScheduleRequest.class ) ); doReturn( job ).when( schedulerService.scheduler ) - .createJob( nullable( String.class ), nullable( String.class ), any( Map.class ), any( IJobTrigger.class ), - any( IBackgroundExecutionStreamProvider.class ) ); + .createJob( nullable( String.class ), nullable( String.class ), any( Map.class ), any( IJobTrigger.class ), + any( IBackgroundExecutionStreamProvider.class ) ); doReturn( Class.class ).when( schedulerService ).getAction( nullable( String.class ) ); doReturn( job ).when( schedulerService.scheduler ) - .createJob( nullable( String.class ), any( Class.class ), any( Map.class ), any( IJobTrigger.class ) ); + .createJob( nullable( String.class ), any( Class.class ), any( Map.class ), any( IJobTrigger.class ) ); doReturn( job ).when( schedulerService.scheduler ) .createJob( nullable( String.class ), anyString(), any( Map.class ), any( IJobTrigger.class ) ); //Test 1 - try ( MockedStatic schedulerResourceUtilMockedStatic = Mockito.mockStatic( SchedulerResourceUtil.class ) ) { + try ( MockedStatic schedulerResourceUtilMockedStatic = Mockito.mockStatic( + SchedulerResourceUtil.class ) ) { IPdiContentProvider mockPdiContentProvider = mock( IPdiContentProvider.class ); - schedulerResourceUtilMockedStatic.when( () -> SchedulerResourceUtil.getiPdiContentProvider() ) - .thenReturn( mockPdiContentProvider ); + schedulerResourceUtilMockedStatic.when( SchedulerResourceUtil::getiPdiContentProvider ) + .thenReturn( mockPdiContentProvider ); schedulerResourceUtilMockedStatic.when( () -> - SchedulerResourceUtil.convertScheduleRequestToJobTrigger( eq( scheduleRequest ), any( IScheduler.class ) ) ) - .thenCallRealMethod(); + SchedulerResourceUtil.convertScheduleRequestToJobTrigger( eq( scheduleRequest ), any( IScheduler.class ) ) ) + .thenCallRealMethod(); schedulerResourceUtilMockedStatic.when( () -> - SchedulerResourceUtil.resolveActionIdFromClass( nullable( String.class ) ) ) - .thenReturn( "testResolveActionIdFromClass" ); + SchedulerResourceUtil.resolveActionIdFromClass( nullable( String.class ) ) ) + .thenReturn( "testResolveActionIdFromClass" ); Job returnJob = schedulerService.createJob( scheduleRequest ); @@ -219,7 +220,6 @@ public void testCreateJob() throws Exception { @Test public void testCreateJobException() throws Exception { - JobScheduleRequest scheduleRequest = mock( JobScheduleRequest.class ); doReturn( "className" ).when( scheduleRequest ).getActionClass(); doReturn( "jobName" ).when( scheduleRequest ).getJobName(); @@ -239,13 +239,15 @@ public void testCreateJobException() throws Exception { doReturn( "file.ext" ).when( scheduleRequest ).getInputFile(); doReturn( repositoryFile ).when( schedulerService.repository ).getFile( nullable( String.class ) ); - try ( MockedStatic schedulerResourceUtilMockedStatic = Mockito.mockStatic( SchedulerResourceUtil.class ) ) { + try ( MockedStatic schedulerResourceUtilMockedStatic = Mockito.mockStatic( + SchedulerResourceUtil.class ) ) { IPdiContentProvider mockPdiContentProvider = mock( IPdiContentProvider.class ); - schedulerResourceUtilMockedStatic.when( () -> SchedulerResourceUtil.getiPdiContentProvider() ) + schedulerResourceUtilMockedStatic.when( SchedulerResourceUtil::getiPdiContentProvider ) .thenReturn( mockPdiContentProvider ); schedulerResourceUtilMockedStatic.when( () -> SchedulerResourceUtil.convertScheduleRequestToJobTrigger( eq( scheduleRequest ), any( IScheduler.class ) ) ) .thenCallRealMethod(); + //Test 1 try { schedulerService.createJob( scheduleRequest ); @@ -267,8 +269,8 @@ public void testCreateJobException() throws Exception { //Test 3 - throw new ClassNotFoundException() moved to testCreateJob() - - // Test 4 - scheduleRequest.getActionClass() -> "blockoutaction" is duplicate of positive test case in testCreateJob() + // Test 4 - scheduleRequest.getActionClass() -> "blockoutaction" is duplicate of positive test case in + // testCreateJob() verify( scheduleRequest, times( 2 ) ).getSimpleJobTrigger(); verify( scheduleRequest, times( 2 ) ).getInputFile(); @@ -284,7 +286,6 @@ public void testCreateJobException() throws Exception { @Test public void testTriggerNow() throws Exception { - JobRequest jobRequest = mock( JobRequest.class ); Job job = mock( Job.class ); @@ -292,33 +293,41 @@ public void testTriggerNow() throws Exception { doReturn( true ).when( schedulerService.policy ).isAllowed( nullable( String.class ) ); doNothing().when( schedulerService.scheduler ).triggerNow( nullable( String.class ) ); - //Test 1 - IJob resultJob1 = schedulerService.triggerNow( jobRequest.getJobId() ); + IJob resultJob = schedulerService.triggerNow( jobRequest.getJobId() ); + assertEquals( job, resultJob ); - assertEquals( job, resultJob1 ); + verify( schedulerService.scheduler, times( 2 ) ).getJob( nullable( String.class ) ); + verify( schedulerService.scheduler, times( 1 ) ).triggerNow( nullable( String.class ) ); + verify( schedulerService.policy, times( 1 ) ).isAllowed( nullable( String.class ) ); + } - //Test 2 - doReturn( "test" ).when( job ).getUserName(); - doReturn( false ).when( schedulerService.policy ).isAllowed( nullable( String.class ) ); + @Test + public void testTriggerNowWithUser() throws Exception { + JobRequest jobRequest = mock( JobRequest.class ); + Job job = mock( Job.class ); - IPentahoSession pentahoSession = mock( IPentahoSession.class ); - doReturn( "test" ).when( pentahoSession ).getName(); - doReturn( pentahoSession ).when( schedulerService ).getSession(); + doReturn( job ).when( schedulerService.scheduler ).getJob( nullable( String.class ) ); - IJob resultJob2 = schedulerService.triggerNow( jobRequest.getJobId() ); + IPentahoSession mockSession = mock( IPentahoSession.class ); + doReturn( mockSession ).when( schedulerService ).getSession(); + + String username = "username"; + doReturn( username ).when( job ).getUserName(); + + String sessionName = "notUsername"; + doReturn( sessionName ).when( mockSession ).getName(); - assertEquals( job, resultJob2 ); + doReturn( false ).when( schedulerService.policy ).isAllowed( nullable( String.class ) ); + IJob resultJob = schedulerService.triggerNow( jobRequest.getJobId() ); + assertEquals( job, resultJob ); - verify( schedulerService.scheduler, times( 4 ) ).getJob( nullable( String.class ) ); - verify( schedulerService.scheduler, times( 2 ) ).triggerNow( nullable( String.class ) ); - verify( schedulerService.policy, times( 2 ) ).isAllowed( nullable( String.class ) ); + verify( schedulerService.scheduler, times( 2 ) ).getJob( nullable( String.class ) ); + verify( schedulerService.policy, times( 1 ) ).isAllowed( nullable( String.class ) ); } @Test public void testGetContentCleanerJob() throws Exception { - IJobFilter jobFilter = mock( IJobFilter.class ); - List jobs = new ArrayList<>(); IPentahoSession session = mock( IPentahoSession.class ); @@ -350,11 +359,8 @@ public void testGetContentCleanerJob() throws Exception { @Test public void testGetContentCleanerJobException() throws Exception { - IJobFilter jobFilter = mock( IJobFilter.class ); - List jobs = new ArrayList<>(); - IPentahoSession session = mock( IPentahoSession.class ); doReturn( session ).when( schedulerService ).getSession(); doReturn( "sessionName" ).when( session ).getName(); @@ -378,39 +384,45 @@ public void testGetContentCleanerJobException() throws Exception { @Test public void testDoGetCanSchedule() { - doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); //Test 1 String isAllowed = schedulerService.doGetCanSchedule(); - assertEquals( "true", isAllowed ); //Test 2 doReturn( false ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); - isAllowed = schedulerService.doGetCanSchedule(); - assertEquals( "false", isAllowed ); - verify( schedulerService.policy, times( 2 ) ).isAllowed( SchedulerAction.NAME ); } @Test - public void testGetState() throws SchedulerException { + public void testDoGetCanExecuteScheduleTrue() { + doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerExecuteAction.NAME ); + String isAllowed = schedulerService.doGetCanExecuteSchedule(); + assertEquals( "true", isAllowed ); + verify( schedulerService.policy, times( 1 ) ).isAllowed( SchedulerExecuteAction.NAME ); + } - doReturn( IScheduler.SchedulerStatus.RUNNING ).when( schedulerService.scheduler ).getStatus(); + @Test + public void testDoGetCanExecuteScheduleFalse() { + doReturn( false ).when( schedulerService.policy ).isAllowed( SchedulerExecuteAction.NAME ); + String isAllowed = schedulerService.doGetCanExecuteSchedule(); + assertEquals( "false", isAllowed ); + verify( schedulerService.policy, times( 1 ) ).isAllowed( SchedulerExecuteAction.NAME ); + } + @Test + public void testGetState() throws SchedulerException { + doReturn( IScheduler.SchedulerStatus.RUNNING ).when( schedulerService.scheduler ).getStatus(); String state = schedulerService.getState(); - assertEquals( "RUNNING", state ); - verify( schedulerService.scheduler ).getStatus(); } @Test public void testGetStateException() throws SchedulerException { - doThrow( new SchedulerException( "" ) ).when( schedulerService.scheduler ).getStatus(); try { @@ -433,7 +445,6 @@ public void testStart() throws SchedulerException { //Test 1 String state = schedulerService.start(); - assertEquals( "RUNNING", state ); //Test 2 @@ -470,14 +481,11 @@ public void testStartException() throws SchedulerException { @Test public void testPause() throws SchedulerException { doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); - doNothing().when( schedulerService.scheduler ).pause(); - doReturn( IScheduler.SchedulerStatus.PAUSED ).when( schedulerService.scheduler ).getStatus(); //Test 1 String state = schedulerService.pause(); - assertEquals( "PAUSED", state ); //Test 2 @@ -499,7 +507,8 @@ public void testPauseJob() throws SchedulerException { doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); doNothing().when( schedulerService.scheduler ).pauseJob( nullable( String.class ) ); - schedulerService.pauseJob( "job-id" ); + JobState state = schedulerService.pauseJob( "job-id" ); + assertNull( state ); } @Test @@ -507,7 +516,9 @@ public void testPauseJobException() throws SchedulerException { Job job = mock( Job.class ); doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); - doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ).pauseJob( nullable( String.class ) ); + doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ) + .pauseJob( nullable( String.class ) ); + try { schedulerService.pauseJob( "job-id" ); } catch ( SchedulerException e ) { @@ -521,7 +532,8 @@ public void testResumeJob() throws SchedulerException { doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); doNothing().when( schedulerService.scheduler ).resumeJob( nullable( String.class ) ); - schedulerService.resumeJob( "job-id" ); + JobState state = schedulerService.resumeJob( "job-id" ); + assertNull( state ); } @Test @@ -529,7 +541,9 @@ public void testResumeJobException() throws SchedulerException { Job job = mock( Job.class ); doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); - doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ).resumeJob( nullable( String.class ) ); + doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ) + .resumeJob( nullable( String.class ) ); + try { schedulerService.resumeJob( "job-id" ); } catch ( SchedulerException e ) { @@ -543,7 +557,8 @@ public void testRemoveJob() throws SchedulerException { doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); doNothing().when( schedulerService.scheduler ).removeJob( nullable( String.class ) ); - schedulerService.removeJob( "job-id" ); + boolean result = schedulerService.removeJob( "job-id" ); + assertTrue( result ); } @Test @@ -551,7 +566,9 @@ public void testRemoveJobException() throws SchedulerException { Job job = mock( Job.class ); doReturn( job ).when( schedulerService ).getJob( nullable( String.class ) ); doReturn( true ).when( schedulerService ).isScheduleAllowed(); - doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ).removeJob( nullable( String.class ) ); + doThrow( new SchedulerException( "pause-exception" ) ).when( schedulerService.scheduler ) + .removeJob( nullable( String.class ) ); + try { schedulerService.removeJob( "job-id" ); } catch ( SchedulerException e ) { @@ -562,7 +579,6 @@ public void testRemoveJobException() throws SchedulerException { @Test public void testPauseException() throws SchedulerException { doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); - doThrow( new SchedulerException( "" ) ).when( schedulerService.scheduler ).pause(); try { @@ -579,14 +595,11 @@ public void testPauseException() throws SchedulerException { @Test public void testShutdown() throws SchedulerException { doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); - doNothing().when( schedulerService.scheduler ).shutdown(); - doReturn( IScheduler.SchedulerStatus.STOPPED ).when( schedulerService.scheduler ).getStatus(); //Test 1 String state = schedulerService.shutdown(); - assertEquals( "STOPPED", state ); //Test 2 @@ -606,7 +619,6 @@ public void testShutdown() throws SchedulerException { @Test public void testShutdownException() throws SchedulerException { doReturn( true ).when( schedulerService.policy ).isAllowed( SchedulerAction.NAME ); - doThrow( new SchedulerException( "" ) ).when( schedulerService.scheduler ).shutdown(); try { @@ -626,7 +638,7 @@ public void testGetJobs() throws Exception { doReturn( mockPentahoSession ).when( schedulerService ).getSession(); doReturn( "admin" ).when( mockPentahoSession ).getName(); - doReturn( true ).when( schedulerService ).canAdminister( mockPentahoSession ); + doReturn( true ).when( schedulerService ).canAdminister(); List mockJobs = new ArrayList<>(); mockJobs.add( mock( IJob.class ) ); doReturn( mockJobs ).when( schedulerService.scheduler ).getJobs( any( IJobFilter.class ) ); @@ -637,7 +649,7 @@ public void testGetJobs() throws Exception { verify( schedulerService, times( 1 ) ).getSession(); verify( mockPentahoSession, times( 1 ) ).getName(); - verify( schedulerService, times( 1 ) ).canAdminister( mockPentahoSession ); + verify( schedulerService, times( 1 ) ).canAdminister(); verify( schedulerService.scheduler, times( 1 ) ).getJobs( any( IJobFilter.class ) ); } @@ -656,7 +668,7 @@ public void testDoGetGeneratedContentForSchedule() throws Exception { List mockList = mock( List.class ); doReturn( mockList ).when( mockFileService ) - .searchGeneratedContent( currentUserDir, lineageId, IScheduler.RESERVEDMAPKEY_LINEAGE_ID ); + .searchGeneratedContent( currentUserDir, lineageId, IScheduler.RESERVEDMAPKEY_LINEAGE_ID ); List list = schedulerService.doGetGeneratedContentForSchedule( lineageId ); assertEquals( mockList, list ); @@ -682,13 +694,11 @@ public void testGetJobState() throws Exception { // Test 1 doReturn( true ).when( schedulerService ).isScheduleAllowed(); - JobState testState = schedulerService.getJobState( mockJobRequest ); assertEquals( JobState.BLOCKED, testState ); // Test 2 doReturn( false ).when( schedulerService ).isScheduleAllowed(); - testState = schedulerService.getJobState( mockJobRequest ); assertEquals( JobState.BLOCKED, testState ); @@ -753,7 +763,7 @@ public void testGetJobInfo() throws Exception { jobParamsKeyset.add( jobParamKey ); String value = "value"; - String[] testArray = new String[]{value}; + String[] testArray = new String[] { value }; doReturn( testArray ).when( mockJobParams ).get( jobParamKey ); // Test 1 @@ -772,7 +782,7 @@ public void testGetJobInfo() throws Exception { verify( mockJob, times( 6 ) ).getJobParams(); verify( mockJobParams, times( 2 ) ).keySet(); verify( mockJobParams, times( 2 ) ).get( jobParamKey ); - verify( schedulerService, times( 2 ) ).canAdminister( null ); + verify( schedulerService, times( 2 ) ).canAdminister(); } @Test @@ -792,7 +802,6 @@ public void testGetJobInfoError() throws Exception { @Test public void testIsScheduleAllowed() { - // Test 1 doReturn( true ).when( schedulerService ).isScheduleAllowed(); @@ -838,7 +847,6 @@ public void testIsScheduleAllowed() { @Test public void testGetBlockoutJobs() { - List jobs = new ArrayList<>(); doReturn( jobs ).when( schedulerService.blockoutManager ).getBlockOutJobs(); @@ -852,7 +860,6 @@ public void testGetBlockoutJobs() { @Test public void testHasBlockouts() { - List jobs = new ArrayList<>(); doReturn( jobs ).when( schedulerService.blockoutManager ).getBlockOutJobs(); @@ -873,7 +880,6 @@ public void testHasBlockouts() { @Test public void testAddBlockout() throws Exception { - JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class ); Job jobMock = mock( Job.class ); @@ -885,8 +891,10 @@ public void testAddBlockout() throws Exception { doReturn( true ).when( schedulerService ).canAdminister(); doNothing().when( jobScheduleRequest ).setActionClass( nullable( String.class ) ); doReturn( jobScheduleParams ).when( jobScheduleRequest ).getJobParameters(); - doReturn( jobScheduleParamMock1 ).when( schedulerService ).getJobScheduleParam( nullable( String.class ), nullable( String.class ) ); - doReturn( jobScheduleParamMock2 ).when( schedulerService ).getJobScheduleParam( nullable( String.class ), anyLong() ); + doReturn( jobScheduleParamMock1 ).when( schedulerService ) + .getJobScheduleParam( nullable( String.class ), nullable( String.class ) ); + doReturn( jobScheduleParamMock2 ).when( schedulerService ) + .getJobScheduleParam( nullable( String.class ), anyLong() ); doReturn( jobMock ).when( schedulerService ).createJob( any( JobScheduleRequest.class ) ); IJob job = schedulerService.addBlockout( jobScheduleRequest ); @@ -902,7 +910,6 @@ public void testAddBlockout() throws Exception { @Test public void testAddBlockoutException() throws Exception { - // Test 1 JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class ); doReturn( false ).when( schedulerService ).canAdminister(); @@ -915,8 +922,6 @@ public void testAddBlockoutException() throws Exception { } // Test 2 - IJob jobMock = mock( IJob.class ); - JobScheduleParam jobScheduleParamMock1 = mock( JobScheduleParam.class ); JobScheduleParam jobScheduleParamMock2 = mock( JobScheduleParam.class ); @@ -925,8 +930,10 @@ public void testAddBlockoutException() throws Exception { doReturn( true ).when( schedulerService ).canAdminister(); doNothing().when( jobScheduleRequest ).setActionClass( nullable( String.class ) ); doReturn( jobScheduleParams ).when( jobScheduleRequest ).getJobParameters(); - doReturn( jobScheduleParamMock1 ).when( schedulerService ).getJobScheduleParam( nullable( String.class ), nullable( String.class ) ); - doReturn( jobScheduleParamMock2 ).when( schedulerService ).getJobScheduleParam( nullable( String.class ), anyLong() ); + doReturn( jobScheduleParamMock1 ).when( schedulerService ) + .getJobScheduleParam( nullable( String.class ), nullable( String.class ) ); + doReturn( jobScheduleParamMock2 ).when( schedulerService ) + .getJobScheduleParam( nullable( String.class ), anyLong() ); doThrow( new IOException() ).when( schedulerService ).createJob( jobScheduleRequest ); @@ -955,7 +962,6 @@ public void testAddBlockoutException() throws Exception { @Test public void testUpdateBlockout() throws Exception { - String jobId = "jobId"; JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class ); IJob jobMock = mock( IJob.class ); @@ -975,10 +981,8 @@ public void testUpdateBlockout() throws Exception { @Test public void testUpdateBlockoutException() throws Exception { - String jobId = "jobId"; JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class ); - IJob job = mock( IJob.class ); // Test 1 doReturn( false ).when( schedulerService ).canAdminister(); @@ -1039,7 +1043,6 @@ public void testUpdateBlockoutException() throws Exception { @Test public void testWillFire() { - IJobTrigger jobTrigger = mock( IJobTrigger.class ); // Test 1 @@ -1061,7 +1064,6 @@ public void testWillFire() { @Test public void testShouldFireNow() { - // Test 1 doReturn( true ).when( schedulerService.blockoutManager ).shouldFireNow(); @@ -1077,12 +1079,10 @@ public void testShouldFireNow() { assertFalse( shouldFireNow ); verify( schedulerService.blockoutManager, times( 2 ) ).shouldFireNow(); - } @Test public void testGetBlockStatus() throws Exception { - JobScheduleRequest jobScheduleRequestMock = mock( JobScheduleRequest.class ); BlockStatusProxy blockStatusProxyMock = mock( BlockStatusProxy.class ); IJobTrigger jobTrigger = mock( IJobTrigger.class ); @@ -1112,10 +1112,10 @@ public void testGetBlockStatus() throws Exception { @Test public void testGetBlockStatusException() throws Exception { - JobScheduleRequest jobScheduleRequestMock = mock( JobScheduleRequest.class ); - doThrow( new SchedulerException( "" ) ).when( schedulerService ).convertScheduleRequestToJobTrigger( jobScheduleRequestMock ); + doThrow( new SchedulerException( "" ) ).when( schedulerService ) + .convertScheduleRequestToJobTrigger( jobScheduleRequestMock ); try { schedulerService.getBlockStatus( jobScheduleRequestMock );