@Test
  public void testAlertDefinitionNameChangeEvent() throws Exception {
    installHdfsService();
    AlertDefinitionEntity definition = definitionDao.findAll().get(0);

    // create 2 historical entries; one will be current
    AlertHistoryEntity history = new AlertHistoryEntity();
    history.setServiceName(definition.getServiceName());
    history.setClusterId(cluster.getClusterId());
    history.setAlertDefinition(definition);
    history.setAlertLabel(definition.getLabel());
    history.setAlertText(definition.getDefinitionName());
    history.setAlertTimestamp(Long.valueOf(1L));
    history.setHostName(null);
    history.setAlertState(AlertState.OK);
    alertsDao.create(history);

    // this one will be current
    AlertHistoryEntity history2 = new AlertHistoryEntity();
    history2.setServiceName(definition.getServiceName());
    history2.setClusterId(cluster.getClusterId());
    history2.setAlertDefinition(definition);
    history2.setAlertLabel(definition.getLabel());
    history2.setAlertText(definition.getDefinitionName());
    history2.setAlertTimestamp(Long.valueOf(1L));
    history2.setHostName(null);
    history2.setAlertState(AlertState.CRITICAL);

    // current for the history
    AlertCurrentEntity current = new AlertCurrentEntity();
    current.setOriginalTimestamp(1L);
    current.setLatestTimestamp(2L);
    current.setAlertHistory(history2);
    alertsDao.create(current);

    // change the definition name
    definition.setLabel("testAlertDefinitionNameChangeEvent");
    definitionDao.merge(definition);

    // the older history item will not have the label changed while
    // the new one will
    history = alertsDao.findById(history.getAlertId());
    history2 = alertsDao.findById(history2.getAlertId());

    Assert.assertFalse(definition.getLabel().equals(history.getAlertLabel()));
    Assert.assertEquals(definition.getLabel(), history2.getAlertLabel());
  }
Tests that {@link AlertDefinitionChangedEvent} instances are fired when a
definition is updated.

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