@Test
  public void testMaintenanceModeSet() throws Exception {
    String definitionName = ALERT_DEFINITION + "1";
    String componentName = "DATANODE";

    Alert alert1 = new Alert(definitionName, null, "HDFS", componentName, HOST1,
        AlertState.CRITICAL);

    alert1.setClusterId(m_cluster.getClusterId());
    alert1.setLabel(ALERT_LABEL);
    alert1.setText("HDFS " + componentName + " is OK");
    alert1.setTimestamp(1L);

    // verify that the listener works with a regular alert
    AlertReceivedListener listener = m_injector.getInstance(AlertReceivedListener.class);
    AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(), alert1);
    listener.onAlertEvent(event);

    List<AlertCurrentEntity> allCurrent = m_dao.findCurrent();
    assertEquals(1, allCurrent.size());

    AlertCurrentEntity current = allCurrent.get(0);
    assertEquals(MaintenanceState.OFF, current.getMaintenanceState());

    // remove it
    m_dao.removeCurrentByService(m_cluster.getClusterId(), "HDFS");
    allCurrent = m_dao.findCurrent();
    assertEquals(0, allCurrent.size());

    // set maintenance mode on the service
    m_cluster.getService("HDFS").setMaintenanceState(MaintenanceState.ON);

    // verify that the listener handles the event and creates the current alert
    // with the correct MM
    listener.onAlertEvent(event);

    allCurrent = m_dao.findCurrent();
    assertEquals(1, allCurrent.size());

    current = allCurrent.get(0);
    assertEquals(MaintenanceState.ON, current.getMaintenanceState());
  }
Tests that a disabled definition doesn't record alert events.
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java