@Test
  public void testInitialAlertEvent() throws Exception {
    // ensure there are no historical items
    Assert.assertEquals(0, m_alertsDao.findAll().size());
    Assert.assertEquals(0,
        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));

    // get a definition to use for the incoming alert
    AlertDefinitionEntity definition = m_definitionDao.findAll(
        m_cluster.getClusterId()).get(0);

    // create the "first" alert
    Alert alert = new Alert(definition.getDefinitionName(), null,
        definition.getServiceName(), definition.getComponentName(), null,
        AlertState.CRITICAL);

    alert.setClusterId(m_cluster.getClusterId());

    AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(), alert);

    // public the received event
    m_eventPublisher.publish(event);

    // ensure we now have a history item and a current
    Assert.assertEquals(1, m_alertsDao.findAll().size());
    List<AlertCurrentEntity> currentAlerts = m_alertsDao.findCurrent();
    Assert.assertEquals(1, currentAlerts.size());

    // verify that that initial alert is HARD
    Assert.assertEquals(AlertFirmness.HARD, currentAlerts.get(0).getFirmness());
    Assert.assertEquals(AlertState.CRITICAL,
        currentAlerts.get(0).getAlertHistory().getAlertState());

    // verify that the initial alert event was triggered
    Assert.assertEquals(1,
        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));

    // clear the initial alert event that was recorded
    m_listener.reset();

    // alert the alert and re-fire
    alert.setState(AlertState.WARNING);
    m_eventPublisher.publish(event);

    // ensure that the initial alert event was NOT received again
    Assert.assertEquals(0,
        m_listener.getAlertEventReceivedCount(InitialAlertEvent.class));
  }
Tests that when a new alert is received that an {@link InitialAlertEvent}
is fired.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java