agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/managers/JobRequestNotificationProcessorIT.java
/**
     * Tests job notifications validation on jobs submitted as json
     *
     * @param notificationsJsonArray the array of json objects to be added to the job
     * @param shouldThrowException   true if processing should throw an exception
     * @param message                the message to assert for a failed test
     */
Tests job notifications validation on jobs submitted as json
@param notificationsJsonArray the array of json objects to be added to the job
@param shouldThrowException   true if processing should throw an exception
@param message                the message to assert for a failed test
Tests job notifications validation on jobs submitted as json @param notificationsJsonArray the array of json objects to be added to the job @param shouldThrowException true if processing should throw an exception @param message the message to assert for a failed test
@Test(dataProvider = "processArrayNodeProvider")
    public void processArrayNode(ArrayNode notificationsJsonArray, boolean shouldThrowException, String message) {
        JobRequestNotificationProcessor jobRequestNotificationProcessor = getMockJobRequetNotificationProcessor();
        try {
            doCallRealMethod().when(jobRequestNotificationProcessor).process(any(ArrayNode.class));
            jobRequestNotificationProcessor.process(notificationsJsonArray);
            verify(jobRequestNotificationProcessor, never()).process(anyString());
            verify(jobRequestNotificationProcessor, never()).process(any(JsonNode.class));
            verify(jobRequestNotificationProcessor, times(notificationsJsonArray.size())).addNotification(any(ObjectNode.class));
            List<Notification> notifications = jobRequestNotificationProcessor.getNotifications();
            assertEquals(notifications.size(), notificationsJsonArray.size(), "Unexpected notification count. Found " + notifications.size() + " expected " + notificationsJsonArray.size());
            assertFalse(shouldThrowException, message);
            for (int i = 0; i < notificationsJsonArray.size(); i++) {
                JsonNode notificationJson = notificationsJsonArray.get(i);
                Optional<Notification> matchingNotification = notifications.stream().filter(n -> notificationJson.get("event").textValue().equals(n.getEvent())).findFirst();
                assertTrue(matchingNotification.isPresent(), "Notification should be created matching test " + notificationJson.get("event") + " event");
                assertEquals(matchingNotification.get().getCallbackUrl(), notificationJson.get("url").textValue(),
                        "Saved " + notificationJson.get("event").textValue() + " notification had the wrong callback url. Expected " +
                                notificationJson.get("url").textValue() + " found " + matchingNotification.get().getCallbackUrl());
                if (notificationJson.has("persistent")) {
                    assertEquals(matchingNotification.get().isPersistent(), notificationJson.get("persistent").asBoolean(),
                            "Saved " + notificationJson.get("event").textValue() + " notification had the wrong persistent value. Expected " +
                                    notificationJson.get("persistent").asBoolean() + " found " + matchingNotification.get().isPersistent());
                } else {
                    assertEquals(matchingNotification.get().isPersistent(), false,
                            "Saved " + notificationJson.get("event").textValue() + " notification defaulted to the wrong persistent value. Expected " +
                                    Boolean.FALSE + " found " + matchingNotification.get().isPersistent());
                }
            }
        } catch (NotificationException e) {
            if (!shouldThrowException) {
                fail(message, e);
            }
        }
    }
@ Test ( dataProvider = "processArrayNodeProvider" ) public void processArrayNode ( ArrayNode notificationsJsonArray , boolean shouldThrowException , String message ) { JobRequestNotificationProcessor jobRequestNotificationProcessor = getMockJobRequetNotificationProcessor ( ) ; try { doCallRealMethod ( ) . when ( jobRequestNotificationProcessor ) . process ( any ( ArrayNode . class ) ) ; jobRequestNotificationProcessor . process ( notificationsJsonArray ) ; verify ( jobRequestNotificationProcessor , never ( ) ) . process ( anyString ( ) ) ; verify ( jobRequestNotificationProcessor , never ( ) ) . process ( any ( JsonNode . class ) ) ; verify ( jobRequestNotificationProcessor , times ( notificationsJsonArray . size ( ) ) ) . addNotification ( any ( ObjectNode . class ) ) ; List < Notification > notifications = jobRequestNotificationProcessor . getNotifications ( ) ; assertEquals ( notifications . size ( ) , notificationsJsonArray . size ( ) , "Unexpected notification count. Found " + notifications . size ( ) + " expected " + notificationsJsonArray . size ( ) ) ; assertFalse ( shouldThrowException , message ) ; for ( int i = 0 ; i < notificationsJsonArray . size ( ) ; i ++ ) { JsonNode notificationJson = notificationsJsonArray . get ( i ) ; Optional < Notification > matchingNotification = notifications . stream ( ) . filter ( n -> notificationJson . get ( "event" ) . textValue ( ) . equals ( n . getEvent ( ) ) ) . findFirst ( ) ; assertTrue ( matchingNotification . isPresent ( ) , "Notification should be created matching test " + notificationJson . get ( "event" ) + " event" ) ; assertEquals ( matchingNotification . get ( ) . getCallbackUrl ( ) , notificationJson . get ( "url" ) . textValue ( ) , "Saved " + notificationJson . get ( "event" ) . textValue ( ) + " notification had the wrong callback url. Expected " + notificationJson . get ( "url" ) . textValue ( ) + " found " + matchingNotification . get ( ) . getCallbackUrl ( ) ) ; if ( notificationJson . has ( "persistent" ) ) { assertEquals ( matchingNotification . get ( ) . isPersistent ( ) , notificationJson . get ( "persistent" ) . asBoolean ( ) , "Saved " + notificationJson . get ( "event" ) . textValue ( ) + " notification had the wrong persistent value. Expected " + notificationJson . get ( "persistent" ) . asBoolean ( ) + " found " + matchingNotification . get ( ) . isPersistent ( ) ) ; } else { assertEquals ( matchingNotification . get ( ) . isPersistent ( ) , false , "Saved " + notificationJson . get ( "event" ) . textValue ( ) + " notification defaulted to the wrong persistent value. Expected " + Boolean . FALSE + " found " + matchingNotification . get ( ) . isPersistent ( ) ) ; } } } catch ( NotificationException e ) { if ( ! shouldThrowException ) { fail ( message , e ) ; } } }
Tests job notifications validation on jobs submitted as json
 @param notificationsJsonArray the array of json objects to be added to the job
 @param shouldThrowException   true if processing should throw an exception
 @param message                the message to assert for a failed test
Tests job notifications validation on jobs submitted as json @param notificationsJsonArray the array of json objects to be added to the job @param shouldThrowException true if processing should throw an exception @param message the message to assert for a failed test
// ensure this method call goes through // call the method under test // ensure it didn't call out to the json methods // this method should call to add each notification in turn. // ensure all the expected events are there // this won't correctly check for multiple notifications to the same event