@Test
  public void testAlertDefinitionChanged() throws Exception {
    installHdfsService();

    int definitionCount = definitionDao.findAll().size();
    AlertDefinitionEntity definition = ormHelper.createAlertDefinition(cluster.getClusterId());
    Assert.assertEquals(definitionCount + 1, definitionDao.findAll().size());

    AggregateSource source = new AggregateSource();
    Reporting reporting = new Reporting();
    ReportTemplate okTemplate = new ReportTemplate();
    okTemplate.setValue(50.0d);
    okTemplate.setText("foo");
    reporting.setOk(okTemplate);
    source.setReporting(reporting);
    source.setAlertName(definition.getDefinitionName());
    source.setType(SourceType.AGGREGATE);

    AlertDefinitionEntity aggregateEntity = new AlertDefinitionEntity();
    aggregateEntity.setClusterId(cluster.getClusterId());
    aggregateEntity.setComponentName("DATANODE");
    aggregateEntity.setEnabled(true);
    aggregateEntity.setDefinitionName("datanode_aggregate");
    aggregateEntity.setScope(Scope.ANY);
    aggregateEntity.setServiceName("HDFS");
    aggregateEntity.setSource(new Gson().toJson(source));
    aggregateEntity.setHash(UUID.randomUUID().toString());
    aggregateEntity.setScheduleInterval(1);
    aggregateEntity.setSourceType(SourceType.AGGREGATE);

    // creating the aggregate alert will register it with the mapping
    definitionDao.create(aggregateEntity);

    // pull it out of the mapping and compare fields
    AlertDefinition aggregate = aggregateMapping.getAggregateDefinition(cluster.getClusterId(),
        source.getAlertName());

    Assert.assertNotNull(aggregate);
    Assert.assertEquals("foo",
        aggregate.getSource().getReporting().getOk().getText());

    // change something about the aggregate's reporting
    String sourceText = aggregateEntity.getSource();
    sourceText = sourceText.replace("foo", "bar");
    aggregateEntity.setSource(sourceText);

    // save the aggregate; this should trigger the event,
    // causing the updated aggregate definition to be mapped
    definitionDao.merge(aggregateEntity);

    // check the aggregate mapping for the new value
    aggregate = aggregateMapping.getAggregateDefinition(cluster.getClusterId(),
        source.getAlertName());

    Assert.assertNotNull(aggregate);
    Assert.assertEquals("bar",
        aggregate.getSource().getReporting().getOk().getText());
  }
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