@Test
  public void testDispatchFactoryRegistration() throws Exception {
    String sourceResourceDirectory = "src" + File.separator + "test"
        + File.separator + "resources";
    Integer snmpPort = 30111;

    Properties properties = new Properties();
    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE.getKey(),"in-memory");
    properties.setProperty(Configuration.OS_VERSION.getKey(), "centos6");
    properties.setProperty(Configuration.SHARED_RESOURCES_DIR.getKey(),sourceResourceDirectory);
    properties.setProperty(Configuration.ALERTS_SNMP_DISPATCH_UDP_PORT.getKey(),snmpPort.toString());

    Injector injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties), new LdapModule());
    DispatchFactory dispatchFactory = injector.getInstance(DispatchFactory.class);
    DispatchFactory dispatchFactory2 = injector.getInstance(DispatchFactory.class);

    // verify singleton
    Assert.assertEquals(dispatchFactory, dispatchFactory2);

    EmailDispatcher emailDispatcher = injector.getInstance(EmailDispatcher.class);
    EmailDispatcher emailDispatcher2 = (EmailDispatcher) dispatchFactory.getDispatcher(emailDispatcher.getType());

    Assert.assertNotNull(emailDispatcher);
    Assert.assertNotNull(emailDispatcher2);

    // verify singleton
    Assert.assertEquals(emailDispatcher, emailDispatcher2);

    SNMPDispatcher snmpDispatcher = injector.getInstance(SNMPDispatcher.class);
    SNMPDispatcher snmpDispatcher2 = (SNMPDispatcher) dispatchFactory.getDispatcher(snmpDispatcher.getType());

    Assert.assertNotNull(snmpDispatcher);
    Assert.assertEquals(snmpDispatcher.getPort(), snmpPort);
    Assert.assertNotNull(snmpDispatcher2);
    Assert.assertEquals(snmpDispatcher2.getPort(), snmpPort);

    // verify singleton
    Assert.assertEquals(snmpDispatcher, snmpDispatcher2);
  }
Verify that know {@link NotificationDispatcher}s are registered via the
Guice {@link Module} and that they singletons.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java