CommandExecutionJob implements Job { @Override public void execute( JobExecutionContext context ) throws JobExecutionException { String appName = (String) context.getJobDetail().getJobDataMap().get( RoboconfScheduler.APP_NAME ); String jobName = (String) context.getJobDetail().getJobDataMap().get( RoboconfScheduler.JOB_NAME ); String commandsFileName = (String) context.getJobDetail().getJobDataMap().get( RoboconfScheduler.CMD_NAME ); try { Manager manager = (Manager) context.getScheduler().getContext().get( RoboconfScheduler.MANAGER ); Application app = manager.applicationMngr().findApplicationByName( appName ); manager.commandsMngr().execute( app, commandsFileName, CommandHistoryItem.ORIGIN_SCHEDULER, jobName ); } catch( Exception e ) { this.logger.warning( "An error occurred while executing job " + jobName + " (command file =" + commandsFileName + ")." ); Utils.logException( this.logger, e ); } }  @Override void execute( JobExecutionContext context );  }
@Test public void testNormalExecution() throws Exception { CommandExecutionJob job = new CommandExecutionJob(); job.execute( this.context ); Mockito.verify( this.context, Mockito.times( 1 )).getScheduler(); Mockito.verify( this.context, Mockito.times( 3 )).getJobDetail(); Mockito.verify( this.manager, Mockito.times( 1 )).applicationMngr(); Mockito.verify( this.commandMngr, Mockito.times( 1 )).execute( null, "cmd", CommandHistoryItem.ORIGIN_SCHEDULER, "job" ); }
@Test public void testExecutionInError() throws Exception { Mockito .doThrow( new CommandException( "For test" )) .when( this.commandMngr ).execute( Mockito.any( Application.class ), Mockito.anyString(), Mockito.anyInt(), Mockito.anyString()); CommandExecutionJob job = new CommandExecutionJob(); job.execute( this.context ); Mockito.verify( this.context, Mockito.times( 1 )).getScheduler(); Mockito.verify( this.context, Mockito.times( 3 )).getJobDetail(); Mockito.verify( this.manager, Mockito.times( 1 )).applicationMngr(); Mockito.verify( this.commandMngr, Mockito.times( 1 )).execute( null, "cmd", CommandHistoryItem.ORIGIN_SCHEDULER, "job" ); }