diff --git a/src/main/java/net/floodlightcontroller/notification/NotificationManagerFactory.java b/src/main/java/net/floodlightcontroller/notification/NotificationManagerFactory.java index da12ab574c3fc234d15b6820602cf8fa884165a7..5fc1d4ae41f4180cb191b822173c0d75d43ef11f 100644 --- a/src/main/java/net/floodlightcontroller/notification/NotificationManagerFactory.java +++ b/src/main/java/net/floodlightcontroller/notification/NotificationManagerFactory.java @@ -7,6 +7,7 @@ import net.floodlightcontroller.notification.syslog.SyslogNotificationFactory; * instance. * * @author kevinwang + * @edited Ryan Izard, rizard@g.clemson.edu, ryan.izard@bigswich.com * */ public class NotificationManagerFactory { @@ -14,7 +15,17 @@ public class NotificationManagerFactory { public static final String NOTIFICATION_FACTORY_NAME = "floodlight.notification.factoryName"; - // default to SyslogNotificationFactory + /** + * Do not set the default here. Delay until init(), which will be + * called by the JVM at class load. This will allow the unit tests + * to test dynamic binding to a factory, then reset to the default + * factory by clearing the System property and then calling init() + * again for subsequent unit tests that actually need a non-mocked + * NotificationManagerFactory. + * + * If a dynamic binding is not specified, init() will fall through + * to else and the default of SyslogNotifcationFactory will be used. + */ private static INotificationManagerFactory factory; /** @@ -28,7 +39,13 @@ public class NotificationManagerFactory { } /** - * A simple mechanism to initialize factory with dynamic binding + * A simple mechanism to initialize factory with dynamic binding. + * + * Extended to default to SyslogNotifcationFactory in the event + * a dynamic binding is not specified via System properties. + * This allows init() to be called multiple times for the unit tests + * and select the default or a another factory if the System property + * is cleared or is set, respectively. */ protected static void init() { String notificationfactoryClassName = null; @@ -47,7 +64,7 @@ public class NotificationManagerFactory { throw new RuntimeException(e); } } else { - factory = new SyslogNotificationFactory(); + factory = new SyslogNotificationFactory(); // use as the default } }