agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/managers/monitors/DefaultJobMonitorTest.java
/**
     * Sets up a mock job and tests that the call to the {@link DefaultJobMonitor#monitor()} method updates the status to the {@code expectedJobStatus}.
     * @param executionType the type of job to test
     * @param status the remote job status that should be returned from the remote scheduler
     * @param expectedJobStatus the resulting status that should be had after update.
     */
Sets up a mock job and tests that the call to the  DefaultJobMonitor#monitor() method updates the status to the  expectedJobStatus.
@param executionType the type of job to test
@param status the remote job status that should be returned from the remote scheduler
@param expectedJobStatus the resulting status that should be had after update.
Sets up a mock job and tests that the call to the DefaultJobMonitor#monitor () method updates the status to the expectedJobStatus . @param executionType the type of job to test @param status the remote job status that should be returned from the remote scheduler @param expectedJobStatus the resulting status that should be had after update .
private DefaultJobMonitor _genericMonitorMockTestHandler(ExecutionType executionType, JobStatusType initialJobStatus, RemoteSchedulerJobStatus<?> status, JobStatusType expectedJobStatus) throws SystemUnavailableException, JobException, RemoteJobMonitorEmptyResponseException, RemoteJobMonitorResponseParsingException, RemoteJobMonitoringException, ClosedByInterruptException {
            ExecutionSystem executionSystem = createMockExecutionSystem(executionType, getSchedulerType());
            Job job = createMockJob(executionType, getSchedulerType());
            when(job.getStatus()).thenReturn(initialJobStatus);
            String initalJobErrorMessage = "Mock job " + job.getUuid() + " " + initialJobStatus.name();
            when(job.getErrorMessage()).thenReturn(initalJobErrorMessage);
            JobStatusResponse jobStatusResponse = new JobStatusResponse<>(job.getLocalJobId(), status, "-1");
            DefaultJobMonitor monitor = mock(DefaultJobMonitor.class);
            when(monitor.getExecutionSystem()).thenReturn(executionSystem);
            when(monitor.getJob()).thenReturn(job);
            when(monitor.getJobStatusResponse(any(), any())).thenReturn(jobStatusResponse);
            doNothing().when(monitor).updateJobStatus(any(JobStatusType.class), anyString());
            when(monitor.monitor()).thenCallRealMethod();
            monitor.monitor();
            return monitor;
    }
private DefaultJobMonitor _genericMonitorMockTestHandler ( ExecutionType executionType , JobStatusType initialJobStatus , RemoteSchedulerJobStatus < ? > status , JobStatusType expectedJobStatus ) throws SystemUnavailableException , JobException , RemoteJobMonitorEmptyResponseException , RemoteJobMonitorResponseParsingException , RemoteJobMonitoringException , ClosedByInterruptException { ExecutionSystem executionSystem = createMockExecutionSystem ( executionType , getSchedulerType ( ) ) ; Job job = createMockJob ( executionType , getSchedulerType ( ) ) ; when ( job . getStatus ( ) ) . thenReturn ( initialJobStatus ) ; String initalJobErrorMessage = "Mock job " + job . getUuid ( ) + " " + initialJobStatus . name ( ) ; when ( job . getErrorMessage ( ) ) . thenReturn ( initalJobErrorMessage ) ; JobStatusResponse jobStatusResponse = new JobStatusResponse < > ( job . getLocalJobId ( ) , status , "-1" ) ; DefaultJobMonitor monitor = mock ( DefaultJobMonitor . class ) ; when ( monitor . getExecutionSystem ( ) ) . thenReturn ( executionSystem ) ; when ( monitor . getJob ( ) ) . thenReturn ( job ) ; when ( monitor . getJobStatusResponse ( any ( ) , any ( ) ) ) . thenReturn ( jobStatusResponse ) ; doNothing ( ) . when ( monitor ) . updateJobStatus ( any ( JobStatusType . class ) , anyString ( ) ) ; when ( monitor . monitor ( ) ) . thenCallRealMethod ( ) ; monitor . monitor ( ) ; return monitor ; }
Sets up a mock job and tests that the call to the {@link DefaultJobMonitor#monitor()} method updates the status to the {@code expectedJobStatus}.
Sets up a mock job and tests that the call to the { @link DefaultJobMonitor#monitor () } method updates the status to the { @code expectedJobStatus } .
//        try { //            Software software = createMockSoftware(executionSystem, executionType); // create the mock job // create a response so we can verify behavior of the monitor for the given response // mock the class under test so we can isolate behavior to the monitor method // return our mock execution when called so we don't get a false system unavailable exception // return our mock job when called // return our mock job status when calling out for the remote job status response // we want to test the behavior, of the run method, not the updateJobStatus method, which gets tested separately // pass through the invocation of the method under test // The job should complete immediately, so we can run the monitor and check for the expected completed status. //        } catch (SystemUnavailableException e) { //            fail("Mock execution system should not be unavailable", e); //        } catch (RemoteJobMonitorEmptyResponseException e) { //            fail("Mock response should be " + status.toString(), e); //        } catch (RemoteJobMonitorResponseParsingException e) { //            fail("Mock response should not throw a parsing exception", e); //        } catch (RemoteJobMonitoringException e) { //            fail("RemoteJobMonitoringException should not be thrown in mock response. No remote call should be made.", e); //        } catch (ClosedByInterruptException e) { //            fail("No interrupt should occur during test", e); //        } catch (JobException e) { //            fail("Handling an active response of " + status.toString() + " should not throw an exception.", e); //        }