@Test
  public void testGetClusterConfigsByStackCG() throws Exception {
    initClusterEntitiesWithConfigGroups();
    ClusterEntity clusterEntity = clusterDAO.findByName("c1");

    List<ConfigGroupEntity> configGroupEntities = configGroupDAO.findAllByTag("OOZIE");

    Long clusterId = clusterDAO.findByName("c1").getClusterId();

    Assert.assertNotNull(configGroupEntities);
    ConfigGroupEntity configGroupEntity = configGroupEntities.get(0);
    Assert.assertNotNull(configGroupEntity);
    Assert.assertEquals("c1", configGroupEntity.getClusterEntity().getClusterName());
    Assert.assertEquals(clusterId, configGroupEntity.getClusterEntity().getClusterId());
    Assert.assertEquals("oozie_server", configGroupEntity.getGroupName());
    Assert.assertEquals("OOZIE", configGroupEntity.getTag());
    Assert.assertEquals("oozie server", configGroupEntity.getDescription());

    // all 3 are HDP-0.1, but only the 2nd one is enabled
    List<ClusterConfigEntity> clusterConfigEntities = clusterDAO.getEnabledConfigsByStack(
        clusterEntity.getClusterId(), HDP_01);

    Assert.assertEquals(1, clusterConfigEntities.size());

    ClusterConfigEntity configEntity = clusterConfigEntities.get(0);
    Assert.assertEquals("version2", configEntity.getTag());
    Assert.assertEquals("oozie-site", configEntity.getType());
    Assert.assertTrue(configEntity.isSelected());

    // this should still return the 2nd one since the 3rd one has never been
    // selected as its only for configuration groups
    clusterConfigEntities = clusterDAO.getLatestConfigurations(clusterEntity.getClusterId(),
        HDP_01);

    configEntity = clusterConfigEntities.get(0);
    Assert.assertEquals("version2", configEntity.getTag());
    Assert.assertEquals("oozie-site", configEntity.getType());
    Assert.assertTrue(configEntity.isSelected());
  }
Tests getting latest and enabled configurations when there is a
configuration group. Configurations for configuration groups are not
"selected" as they are merged in with the selected configuration. This can
cause problems if searching simply for the "latest" since it will pickup
the wrong configuration.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java