@Test
public void testFindGroupsByDefinition() throws Exception {

  List<AlertDefinitionEntity> definitions = createDefinitions();
  AlertGroupEntity group = m_helper.createAlertGroup(
      m_cluster.getClusterId(), null);
  group = m_dao.findGroupById(group.getGroupId());
  assertNotNull(group);
  for (AlertDefinitionEntity definition : definitions) {
    group.addAlertDefinition(definition);
  }
  m_dao.merge(group);
  group = m_dao.findGroupByName(m_cluster.getClusterId(), group.getGroupName());
  assertEquals(definitions.size(), group.getAlertDefinitions().size());
  // assert that the definition is now part of 2 groups (the default group
  // and the newly associated group from above)
  for (AlertDefinitionEntity definition : definitions) {
    List<AlertGroupEntity> groups = m_dao.findGroupsByDefinition(definition);
    assertEquals(2, groups.size());
  }
}