@Test
public void testTriggerNow() throws Exception {
JobRequest jobRequest = mock( JobRequest.class );
Job job = mock( Job.class );
doReturn( job ).when( schedulerService.scheduler ).getJob( anyString() );
doReturn( true ).when( schedulerService.policy ).isAllowed( anyString() );
doNothing().when( schedulerService.scheduler ).triggerNow( anyString() );
//Test 1
Job resultJob1 = schedulerService.triggerNow( jobRequest.getJobId() );
assertEquals( job, resultJob1 );
//Test 2
doReturn( "test" ).when( job ).getUserName();
doReturn( false ).when( schedulerService.policy ).isAllowed( anyString() );
IPentahoSession pentahoSession = mock( IPentahoSession.class );
doReturn( "test" ).when( pentahoSession ).getName();
doReturn( pentahoSession ).when( schedulerService ).getSession();
Job resultJob2 = schedulerService.triggerNow( jobRequest.getJobId() );
assertEquals( job, resultJob2 );
verify( schedulerService.scheduler, times( 4 ) ).getJob( anyString() );
verify( schedulerService.scheduler, times( 2 ) ).triggerNow( anyString() );