agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/managers/JobManagerIT.java
/**
	 * Tests that the job status is updated when a new status or message value is given. Also verifies a message
	 * is added to the queue if a notification for the job status is set. 
	 * @param originalJobStatus
	 * @param newJobStatus
	 * @param notificationMessage
	 * @param notificatonEventName
	 * @param shouldThrowException
	 * @param message
	 */
Tests that the job status is updated when a new status or message value is given. Also verifies a message
is added to the queue if a notification for the job status is set.
Tests that the job status is updated when a new status or message value is given . Also verifies a message is added to the queue if a notification for the job status is set .
@Test(dataProvider="updateStatusJobStatusTypeJobStatusTypeStringProvider", enabled=false)
	public void updateStatusJobJobStatusTypeString(JobStatusType originalJobStatus, JobStatusType newJobStatus, String notificationMessage, String notificatonEventName, boolean shouldThrowException, String message)
	{
		Job job = null;
		try 
		{
			NotificationDao notificationDao = new NotificationDao();
			Software software = createSoftware();
			job = createJob(originalJobStatus, software);
			Notification notification = null;
			if (!StringUtils.isEmpty(notificatonEventName)) {
				notification = new Notification(job.getUuid(), job.getOwner(), notificatonEventName, "http://example.com", false);
				notificationDao.persist(notification);
			}
			JobManager.updateStatus(job, newJobStatus, notificationMessage);
			Assert.assertEquals(job.getStatus(), newJobStatus,
					"Job status did not update after status update.");
			Assert.assertEquals(job.getErrorMessage(), notificationMessage,
					"Job description did not update after status update.");
			List<JobEvent> events = JobEventDao.getByJobIdAndStatus(job.getId(), job.getStatus());
			int expectedEvents = (originalJobStatus.equals(newJobStatus) && !originalJobStatus.getDescription().equals(notificationMessage)) ? 2 : 1;
			Assert.assertEquals(expectedEvents, events.size(),
					"Wrong number of events found. Expected " + expectedEvents + ", found " + events.size());
			JobEvent event = events.get(events.size() -1);
			Assert.assertEquals(event.getDescription(), notificationMessage,
					"Wrong event description found. Expected '" + notificationMessage
							+ "', found '" + event.getDescription() + "'");
			if (!(originalJobStatus.equals(newJobStatus) && originalJobStatus.getDescription().equals(notificationMessage)) &&
					(StringUtils.equals(notificatonEventName, newJobStatus.name()) || StringUtils.equals(notificatonEventName, "*")))
			{
				MessageQueueClient client = MessageClientFactory.getMessageClient();
				Message queuedMessage = null;
				try {
					queuedMessage = client.pop(Settings.NOTIFICATION_TOPIC,
							Settings.NOTIFICATION_QUEUE);
				} catch (Throwable e) { 
					Assert.fail("Failed to remove message from the queue. Further tests will fail.", e);
				}
				finally {
					client.delete(Settings.NOTIFICATION_TOPIC,
							Settings.NOTIFICATION_QUEUE, queuedMessage.getId());
				}
				Assert.assertNotNull(queuedMessage,
						"Null message found on the queue");
				JsonNode json = mapper.readTree(queuedMessage.getMessage());
				Assert.assertEquals(notification.getUuid(), json.get("uuid").textValue(),
						"Notification message has wrong uuid");
				Assert.assertEquals(job.getStatus().name(), json.get("event").textValue(),
						"Notification message has wrong event");
			}
			else
			{
				Assert.assertEquals(getMessageCount(Settings.NOTIFICATION_QUEUE), 0, 
						"Messages found in the queue when none should be there.");
			}
		} catch (Exception e) {
			if (!shouldThrowException) {
				Assert.fail(message, e);
			}
		}
		finally {
			try { clearJobs(); } catch (Exception ignored) {}
		}
	}
@ Test ( dataProvider = "updateStatusJobStatusTypeJobStatusTypeStringProvider" , enabled = false ) public void updateStatusJobJobStatusTypeString ( JobStatusType originalJobStatus , JobStatusType newJobStatus , String notificationMessage , String notificatonEventName , boolean shouldThrowException , String message ) { Job job = null ; try { NotificationDao notificationDao = new NotificationDao ( ) ; Software software = createSoftware ( ) ; job = createJob ( originalJobStatus , software ) ; Notification notification = null ; if ( ! StringUtils . isEmpty ( notificatonEventName ) ) { notification = new Notification ( job . getUuid ( ) , job . getOwner ( ) , notificatonEventName , "http://example.com" , false ) ; notificationDao . persist ( notification ) ; } JobManager . updateStatus ( job , newJobStatus , notificationMessage ) ; Assert . assertEquals ( job . getStatus ( ) , newJobStatus , "Job status did not update after status update." ) ; Assert . assertEquals ( job . getErrorMessage ( ) , notificationMessage , "Job description did not update after status update." ) ; List < JobEvent > events = JobEventDao . getByJobIdAndStatus ( job . getId ( ) , job . getStatus ( ) ) ; int expectedEvents = ( originalJobStatus . equals ( newJobStatus ) && ! originalJobStatus . getDescription ( ) . equals ( notificationMessage ) ) ? 2 : 1 ; Assert . assertEquals ( expectedEvents , events . size ( ) , "Wrong number of events found. Expected " + expectedEvents + ", found " + events . size ( ) ) ; JobEvent event = events . get ( events . size ( ) - 1 ) ; Assert . assertEquals ( event . getDescription ( ) , notificationMessage , "Wrong event description found. Expected '" + notificationMessage + "', found '" + event . getDescription ( ) + "'" ) ; if ( ! ( originalJobStatus . equals ( newJobStatus ) && originalJobStatus . getDescription ( ) . equals ( notificationMessage ) ) && ( StringUtils . equals ( notificatonEventName , newJobStatus . name ( ) ) || StringUtils . equals ( notificatonEventName , "*" ) ) ) { MessageQueueClient client = MessageClientFactory . getMessageClient ( ) ; Message queuedMessage = null ; try { queuedMessage = client . pop ( Settings . NOTIFICATION_TOPIC , Settings . NOTIFICATION_QUEUE ) ; } catch ( Throwable e ) { Assert . fail ( "Failed to remove message from the queue. Further tests will fail." , e ) ; } finally { client . delete ( Settings . NOTIFICATION_TOPIC , Settings . NOTIFICATION_QUEUE , queuedMessage . getId ( ) ) ; } Assert . assertNotNull ( queuedMessage , "Null message found on the queue" ) ; JsonNode json = mapper . readTree ( queuedMessage . getMessage ( ) ) ; Assert . assertEquals ( notification . getUuid ( ) , json . get ( "uuid" ) . textValue ( ) , "Notification message has wrong uuid" ) ; Assert . assertEquals ( job . getStatus ( ) . name ( ) , json . get ( "event" ) . textValue ( ) , "Notification message has wrong event" ) ; } else { Assert . assertEquals ( getMessageCount ( Settings . NOTIFICATION_QUEUE ) , 0 , "Messages found in the queue when none should be there." ) ; } } catch ( Exception e ) { if ( ! shouldThrowException ) { Assert . fail ( message , e ) ; } } finally { try { clearJobs ( ) ; } catch ( Exception ignored ) { } } }
Tests that the job status is updated when a new status or message value is given.
Tests that the job status is updated when a new status or message value is given .
// verify status update // verify event creation // this test will fail if the events do not come back ordered by created asc  // verify notification message was sent // check for messages in the queue?