@Test
  public void testGetLastServiceConfigsForServiceWhenAConfigGroupIsDeleted() throws Exception {
    Clusters clusters = injector.getInstance(Clusters.class);
    clusters.addCluster("c1", HDP_01);
    initClusterEntitiesWithConfigGroups();
    ConfigGroupEntity configGroupEntity1 = new ConfigGroupEntity();
    ClusterEntity clusterEntity = clusterDAO.findByName("c1");
    Long clusterId = clusterEntity.getClusterId();
    configGroupEntity1.setClusterEntity(clusterEntity);
    configGroupEntity1.setClusterId(clusterEntity.getClusterId());
    configGroupEntity1.setGroupName("toTestDeleteGroup_OOZIE");
    configGroupEntity1.setDescription("toTestDeleteGroup_OOZIE_DESC");
    configGroupEntity1.setTag("OOZIE");
    configGroupEntity1.setServiceName("OOZIE");
    configGroupDAO.create(configGroupEntity1);
    ConfigGroupEntity testDeleteGroup_OOZIE = configGroupDAO.findByName("toTestDeleteGroup_OOZIE");
    createServiceConfigWithGroup("OOZIE", "", 2L, 2L, System.currentTimeMillis(), null,
        testDeleteGroup_OOZIE.getGroupId());
    Collection<ServiceConfigEntity> serviceConfigEntityList = serviceConfigDAO.getLastServiceConfigsForService(clusterId,
        "OOZIE");
    Assert.assertEquals(2, serviceConfigEntityList.size());
    configGroupDAO.remove(configGroupEntity1);
    serviceConfigEntityList = serviceConfigDAO.getLastServiceConfigsForService(clusterId, "OOZIE");
    Assert.assertEquals(1, serviceConfigEntityList.size());
  }
When the last configuration of a given configuration type to be stored into
the clusterconfig table is for a configuration group, that configuration is
not enabled. Therefore, it should be skipped when getting the enabled
configurations for a stack.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java