@Test
  public void testFindTargetsViaGroupsByDefinition() throws Exception {
    initTestData();
    List<AlertDefinitionEntity> definitions = createDefinitions();
    AlertGroupEntity group = m_helper.createAlertGroup(
        m_cluster.getClusterId(), null);

    group = m_dao.findGroupById(group.getGroupId());
    assertNotNull(group);

    AlertDefinitionEntity definition = definitions.get(0);
    group.addAlertDefinition(definition);

    m_dao.merge(group);

    List<AlertTargetEntity> targets = m_dao.findAllTargets();
    AlertTargetEntity target = targets.get(0);
    Set<AlertTargetEntity> setTargets = Collections.singleton(target);

    group.setAlertTargets(setTargets);
    m_dao.merge(group);

    List<AlertGroupEntity> groups = m_dao.findGroupsByDefinition(definition);
    assertEquals(2, groups.size());

    group = groups.get(groups.indexOf(group));
    assertEquals(1, group.getAlertTargets().size());
    assertEquals(target.getTargetId(),
        group.getAlertTargets().iterator().next().getTargetId());
  }
Tests finding groups by a definition ID that they are associatd with in
order to get any targets associated with that group. This exercises the
bi-directional

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java