SchedulerResource implements ISchedulerResource { @Override public Response findJobProperties( String jobName ) { Response result; this.logger.fine( "Request: get the details of job " + jobName + "." ); try { ScheduledJob job = this.scheduler.findJobProperties( jobName ); if( job == null ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, ErrorDetails.name( jobName )), lang( this.manager )).build(); } else { result = Response.ok( job ).build(); } } catch( NullPointerException e ) { result = handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_SCHEDULER_IS_UNAVAILABLE, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } 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 );  }
@Test public void testGetJobDetails_noScheduler() { this.resource.scheduler = null; Response resp = this.resource.findJobProperties( "job" ); Assert.assertEquals( Status.FORBIDDEN.getStatusCode(), resp.getStatus()); }
@Test public void testGetJobDetails_notFound() { Response resp = this.resource.findJobProperties( "job" ); Assert.assertEquals( Status.NOT_FOUND.getStatusCode(), resp.getStatus()); }
@Test public void testGetJobDetails_ok() { Mockito .when( this.scheduler.findJobProperties( Mockito.anyString())) .thenReturn( new ScheduledJob( "job-id" )); Response resp = this.resource.findJobProperties( "job-id" ); Assert.assertEquals( Status.OK.getStatusCode(), resp.getStatus()); Assert.assertTrue( resp.getEntity() instanceof ScheduledJob ); }