@Test
  public void testMaintenanceModeEvents() throws Exception {
    installHdfsService();
    Service service = m_cluster.getService("HDFS");
    Class<? extends AmbariEvent> eventClass = MaintenanceModeEvent.class;

    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
    service.setMaintenanceState(MaintenanceState.ON);
    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
    Assert.assertEquals(1, m_listener.getAmbariEventReceivedCount(eventClass));

    m_listener.reset();
    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));

    List<ServiceComponentHost> componentHosts = m_cluster.getServiceComponentHosts(HOSTNAME);
    ServiceComponentHost componentHost = componentHosts.get(0);
    componentHost.setMaintenanceState(MaintenanceState.OFF);

    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
    Assert.assertEquals(1, m_listener.getAmbariEventReceivedCount(eventClass));

    m_listener.reset();
    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));

    Host host = m_clusters.getHost(HOSTNAME);
    host.setMaintenanceState(m_cluster.getClusterId(), MaintenanceState.ON);
    host.setMaintenanceState(m_cluster.getClusterId(), MaintenanceState.OFF);

    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
    Assert.assertEquals(2, m_listener.getAmbariEventReceivedCount(eventClass));
  }
Tests that {@link MaintenanceModeEvent}s are fired correctly.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java