@Test public void testListJobs_ok() { List<ScheduledJob> result = new ArrayList<> (); for( int i=0; i<3; i++ ) { for( int j=0; j<4; j++ ) { ScheduledJob job = new ScheduledJob( "job-id-" + i + j ); job.setJobName( "Job " + i + j ); job.setCron( "some cron that we will not validate since we mock the scheduler" ); job.setAppName( "App-" + i ); job.setCmdName( "cmd-" + j ); result.add( job ); } } ScheduledJob customJob = new ScheduledJob( "new-job-id" ); customJob.setJobName( "Custom Job" ); customJob.setCron( "some cron that we will not validate since we mock the scheduler" ); customJob.setAppName( "App-2" ); customJob.setCmdName( "cmd-2" ); result.add( customJob ); Mockito .when( this.scheduler.listJobs()) .thenReturn( result ); Assert.assertEquals( result, this.resource.listJobs( null, null )); List<ScheduledJob> got = this.resource.listJobs( "App-2", null ); Set<String> jobNames = new HashSet<> (); for( ScheduledJob gotJob : got ) { Assert.assertEquals( "App-2", gotJob.getAppName()); jobNames.add( gotJob.getJobName()); } Assert.assertEquals( 5, got.size()); Assert.assertEquals( 5, jobNames.size()); Assert.assertTrue( jobNames.contains( "Custom Job" )); got = this.resource.listJobs( "App-2", "cmd-2" ); jobNames.clear(); for( ScheduledJob gotJob : got ) { Assert.assertEquals( "App-2", gotJob.getAppName()); jobNames.add( gotJob.getJobName()); } Assert.assertEquals( 2, got.size()); Assert.assertEquals( 2, jobNames.size()); Assert.assertTrue( jobNames.contains( "Custom Job" )); Assert.assertEquals( 1, this.resource.listJobs( "App-2", "cmd-1" ).size()); Assert.assertEquals( 0, this.resource.listJobs( "App-2", "cmd-that-does-not-exist" ).size()); Assert.assertEquals( 0, this.resource.listJobs( null, "cmd-2" ).size()); Assert.assertEquals( 0, this.resource.listJobs( "app-that-does-not-exist", null ).size()); }
@Override public List<ScheduledJob> listJobs( String appName, String cmdName ) { List<ScheduledJob> result = new ArrayList<> (); this.logger.fine( "Request: get all the scheduled jobs." ); try { if( appName == null && cmdName == null ) { result = this.scheduler.listJobs(); } else if( appName != null ) { for( ScheduledJob job : this.scheduler.listJobs()) { boolean cmdMatch = cmdName == null || cmdName.equals( job.getCmdName()); if( cmdMatch && appName.equals( job.getAppName())) result.add( job ); } } } catch( NullPointerException e ) { this.logger.warning( "Roboconf's scheduler is not available." ); } return result; }
SchedulerResource implements ISchedulerResource { @Override public List<ScheduledJob> listJobs( String appName, String cmdName ) { List<ScheduledJob> result = new ArrayList<> (); this.logger.fine( "Request: get all the scheduled jobs." ); try { if( appName == null && cmdName == null ) { result = this.scheduler.listJobs(); } else if( appName != null ) { for( ScheduledJob job : this.scheduler.listJobs()) { boolean cmdMatch = cmdName == null || cmdName.equals( job.getCmdName()); if( cmdMatch && appName.equals( job.getAppName())) result.add( job ); } } } catch( NullPointerException e ) { this.logger.warning( "Roboconf's scheduler is not available." ); } return result; } }
SchedulerResource implements ISchedulerResource { @Override public List<ScheduledJob> listJobs( String appName, String cmdName ) { List<ScheduledJob> result = new ArrayList<> (); this.logger.fine( "Request: get all the scheduled jobs." ); try { if( appName == null && cmdName == null ) { result = this.scheduler.listJobs(); } else if( appName != null ) { for( ScheduledJob job : this.scheduler.listJobs()) { boolean cmdMatch = cmdName == null || cmdName.equals( job.getCmdName()); if( cmdMatch && appName.equals( job.getAppName())) result.add( job ); } } } catch( NullPointerException e ) { this.logger.warning( "Roboconf's scheduler is not available." ); } return result; } SchedulerResource( Manager manager ); }
SchedulerResource implements ISchedulerResource { @Override public List<ScheduledJob> listJobs( String appName, String cmdName ) { List<ScheduledJob> result = new ArrayList<> (); this.logger.fine( "Request: get all the scheduled jobs." ); try { if( appName == null && cmdName == null ) { result = this.scheduler.listJobs(); } else if( appName != null ) { for( ScheduledJob job : this.scheduler.listJobs()) { boolean cmdMatch = cmdName == null || cmdName.equals( job.getCmdName()); if( cmdMatch && appName.equals( job.getAppName())) result.add( job ); } } } catch( NullPointerException e ) { this.logger.warning( "Roboconf's scheduler is not available." ); } return result; } SchedulerResource( Manager manager ); @Override Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ); @Override Response deleteJob( String jobName ); @Override Response findJobProperties( String jobName ); @Override List<ScheduledJob> listJobs( String appName, String cmdName ); void setScheduler( IScheduler scheduler ); }
SchedulerResource implements ISchedulerResource { @Override public List<ScheduledJob> listJobs( String appName, String cmdName ) { List<ScheduledJob> result = new ArrayList<> (); this.logger.fine( "Request: get all the scheduled jobs." ); try { if( appName == null && cmdName == null ) { result = this.scheduler.listJobs(); } else if( appName != null ) { for( ScheduledJob job : this.scheduler.listJobs()) { boolean cmdMatch = cmdName == null || cmdName.equals( job.getCmdName()); if( cmdMatch && appName.equals( job.getAppName())) result.add( job ); } } } catch( NullPointerException e ) { this.logger.warning( "Roboconf's scheduler is not available." ); } return result; } SchedulerResource( Manager manager ); @Override Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ); @Override Response deleteJob( String jobName ); @Override Response findJobProperties( String jobName ); @Override List<ScheduledJob> listJobs( String appName, String cmdName ); void setScheduler( IScheduler scheduler );  }