@Test
  public void testServiceRemovedEventForAlertDefinitions() throws Exception {
    Class<? extends AmbariEvent> eventClass = ServiceRemovedEvent.class;
    Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
    installHdfsService();

    // get the default group for HDFS
    AlertGroupEntity group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");

    // verify the default group is there
    Assert.assertNotNull(group);
    Assert.assertTrue(group.isDefault());

    // check that there are alert definitions
    Assert.assertTrue(m_definitionDao.findAll(m_cluster.getClusterId()).size() > 0);

    // get all definitions for HDFS
    List<AlertDefinitionEntity> hdfsDefinitions = m_definitionDao.findByService(
        m_cluster.getClusterId(), "HDFS");

    // make sure there are at least 1
    Assert.assertTrue(hdfsDefinitions.size() > 0);

    // delete the default alert group
    m_alertDispatchDao.remove(group);

    // verify that the default group was removed
    group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");

    Assert.assertNull(group);

    // delete HDFS
    m_cluster.getService("HDFS").delete(new DeleteHostComponentStatusMetaData());

    // verify the event was received
    Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));

    // verify that the definitions were removed
    hdfsDefinitions = m_definitionDao.findByService(m_cluster.getClusterId(), "HDFS");

    Assert.assertEquals(0, hdfsDefinitions.size());
  }
Tests that {@link ServiceRemovedEvent}s are fired correctly and alerts are removed
even though the default alert group was already removed at the time the event is fired .

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