@Test public void testSaveJob_error() throws Exception { Mockito .doThrow( new IOException( "For test" )) .when( this.scheduler ).saveJob( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Response resp = this.resource.saveJob( null, "job", "app", "cmd", "cron" ); Assert.assertEquals( Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); }
@Override public Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ) { this.logger.fine( "Request: save a new scheduled job as " + jobName + "." ); Response result; try { jobId = this.scheduler.saveJob( jobId, jobName, cmdName, cron, appName ); result = Response.ok( new StringWrapper( jobId )).build(); } catch( IllegalArgumentException e ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } catch( IOException e ) { result = handleError( Status.BAD_REQUEST, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).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 implements ISchedulerResource { @Override public Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ) { this.logger.fine( "Request: save a new scheduled job as " + jobName + "." ); Response result; try { jobId = this.scheduler.saveJob( jobId, jobName, cmdName, cron, appName ); result = Response.ok( new StringWrapper( jobId )).build(); } catch( IllegalArgumentException e ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } catch( IOException e ) { result = handleError( Status.BAD_REQUEST, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).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 implements ISchedulerResource { @Override public Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ) { this.logger.fine( "Request: save a new scheduled job as " + jobName + "." ); Response result; try { jobId = this.scheduler.saveJob( jobId, jobName, cmdName, cron, appName ); result = Response.ok( new StringWrapper( jobId )).build(); } catch( IllegalArgumentException e ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } catch( IOException e ) { result = handleError( Status.BAD_REQUEST, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).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 ); }
SchedulerResource implements ISchedulerResource { @Override public Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ) { this.logger.fine( "Request: save a new scheduled job as " + jobName + "." ); Response result; try { jobId = this.scheduler.saveJob( jobId, jobName, cmdName, cron, appName ); result = Response.ok( new StringWrapper( jobId )).build(); } catch( IllegalArgumentException e ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } catch( IOException e ) { result = handleError( Status.BAD_REQUEST, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).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 ); }
SchedulerResource implements ISchedulerResource { @Override public Response saveJob( String jobId, String jobName, String appName, String cmdName, String cron ) { this.logger.fine( "Request: save a new scheduled job as " + jobName + "." ); Response result; try { jobId = this.scheduler.saveJob( jobId, jobName, cmdName, cron, appName ); result = Response.ok( new StringWrapper( jobId )).build(); } catch( IllegalArgumentException e ) { result = handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).build(); } catch( IOException e ) { result = handleError( Status.BAD_REQUEST, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( jobName )), lang( this.manager )).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 );  }