agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/managers/JobRequestProcessorIT.java
/**
	 * Generic method to run the JobManager.processJob(JsonNode, String, String) method.
	 * @param json the json object representing the job request
	 * @param shouldThrowException true if processing should throw an exception
	 * @param message the assertion message to be returned if the test fails
	 */
Generic method to run the JobManager.processJob(JsonNode, String, String) method.
@param json the json object representing the job request
@param shouldThrowException true if processing should throw an exception
@param message the assertion message to be returned if the test fails
Generic method to run the JobManager . processJob ( JsonNode String String ) method . @param json the json object representing the job request @param shouldThrowException true if processing should throw an exception @param message the assertion message to be returned if the test fails
private Job _genericProcessJsonJob(ObjectNode json, boolean shouldThrowException, String message)
	{
		Job job = null;
		try 
		{
			JobRequestInputProcessor inputProcessor = mock(JobRequestInputProcessor.class);
			doNothing().when(inputProcessor).process(any());
			when(inputProcessor.getJobInputs()).thenReturn(mapper.createObjectNode());
			JobRequestParameterProcessor parameterProcessor = mock(JobRequestParameterProcessor.class);
			doNothing().when(parameterProcessor).process(any());
			when(parameterProcessor.getJobParameters()).thenReturn(mapper.createObjectNode());
			JobRequestNotificationProcessor notificationProcessor = mock(JobRequestNotificationProcessor.class);
			doNothing().when(notificationProcessor).process(any(JsonNode.class));
			doNothing().when(notificationProcessor).process(any(ArrayNode.class));
			doNothing().when(notificationProcessor).process(anyString());
			when(notificationProcessor.getNotifications()).thenReturn(new ArrayList<Notification>());
			JobRequestProcessor processor = mock(JobRequestProcessor.class, new Answer() {
				/**
				 * @param invocation the invocation on the mock.
				 * @return the value to be returned
				 * @throws Throwable the throwable to be thrown
				 */
				@Override
				public Object answer(InvocationOnMock invocation) throws Throwable {
					if (invocation.getMethod().getName().equals("isSoftwareInvokableByUser")) {
						return true;
					} else if (invocation.getMethod().getName().equals("getInternalUsername")) {
						return null;
					} else if (invocation.getMethod().getName().equals("getParameterProcessor")) {
						return parameterProcessor;
					} else if (invocation.getMethod().getName().equals("getInputProcessor")) {
						return inputProcessor;
					} else if (invocation.getMethod().getName().equals("getNotificationProcessor")) {
						return notificationProcessor;
					} else if (invocation.getMethod().getName().equals("checkExecutionSystemLogin")) {
						return true;
					} else if (invocation.getMethod().getName().equals("checkExecutionSystemStorage")) {
						return true;
					} else if (invocation.getMethod().getName().equals("getUsername")) {
						return TEST_OWNER;
					} else {
						return invocation.callRealMethod();
					}
				}
			});
			when(processor.getUsername()).thenReturn(TEST_OWNER);
			when(processor.getInternalUsername()).thenReturn(null);
			when(processor.isSoftwareInvokableByUser(any(), eq(TEST_OWNER))).thenReturn(true);
			job = processor.processJob(json);
			assertNotNull(job.getId(), "Job was not saved after processing.");
		} 
		catch (JobProcessingException e) {
			if (!shouldThrowException) {
				Assert.fail(message, e);
			}
		} 
		catch (Exception e) {
			Assert.fail("Unexpected failed to process job", e);
		}
		return job;
	}
private Job _genericProcessJsonJob ( ObjectNode json , boolean shouldThrowException , String message ) { Job job = null ; try { JobRequestInputProcessor inputProcessor = mock ( JobRequestInputProcessor . class ) ; doNothing ( ) . when ( inputProcessor ) . process ( any ( ) ) ; when ( inputProcessor . getJobInputs ( ) ) . thenReturn ( mapper . createObjectNode ( ) ) ; JobRequestParameterProcessor parameterProcessor = mock ( JobRequestParameterProcessor . class ) ; doNothing ( ) . when ( parameterProcessor ) . process ( any ( ) ) ; when ( parameterProcessor . getJobParameters ( ) ) . thenReturn ( mapper . createObjectNode ( ) ) ; JobRequestNotificationProcessor notificationProcessor = mock ( JobRequestNotificationProcessor . class ) ; doNothing ( ) . when ( notificationProcessor ) . process ( any ( JsonNode . class ) ) ; doNothing ( ) . when ( notificationProcessor ) . process ( any ( ArrayNode . class ) ) ; doNothing ( ) . when ( notificationProcessor ) . process ( anyString ( ) ) ; when ( notificationProcessor . getNotifications ( ) ) . thenReturn ( new ArrayList < Notification > ( ) ) ; JobRequestProcessor processor = mock ( JobRequestProcessor . class , new Answer ( ) { /**
				 * @param invocation the invocation on the mock.
				 * @return the value to be returned
				 * @throws Throwable the throwable to be thrown
				 */ @ Override public Object answer ( InvocationOnMock invocation ) throws Throwable { if ( invocation . getMethod ( ) . getName ( ) . equals ( "isSoftwareInvokableByUser" ) ) { return true ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "getInternalUsername" ) ) { return null ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "getParameterProcessor" ) ) { return parameterProcessor ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "getInputProcessor" ) ) { return inputProcessor ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "getNotificationProcessor" ) ) { return notificationProcessor ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "checkExecutionSystemLogin" ) ) { return true ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "checkExecutionSystemStorage" ) ) { return true ; } else if ( invocation . getMethod ( ) . getName ( ) . equals ( "getUsername" ) ) { return TEST_OWNER ; } else { return invocation . callRealMethod ( ) ; } } } ) ; when ( processor . getUsername ( ) ) . thenReturn ( TEST_OWNER ) ; when ( processor . getInternalUsername ( ) ) . thenReturn ( null ) ; when ( processor . isSoftwareInvokableByUser ( any ( ) , eq ( TEST_OWNER ) ) ) . thenReturn ( true ) ; job = processor . processJob ( json ) ; assertNotNull ( job . getId ( ) , "Job was not saved after processing." ) ; } catch ( JobProcessingException e ) { if ( ! shouldThrowException ) { Assert . fail ( message , e ) ; } } catch ( Exception e ) { Assert . fail ( "Unexpected failed to process job" , e ) ; } return job ; }
Generic method to run the JobManager.processJob(JsonNode, String, String) method.
Generic method to run the JobManager . processJob ( JsonNode String String ) method .