private void initClusterEntitiesWithConfigGroups() throws Exception{
    String userName = "admin";

    ServiceConfigEntity oozieServiceConfigEntity = createServiceConfig("OOZIE", userName, 1L, 1L, System.currentTimeMillis(), null);
    ClusterEntity  clusterEntity = oozieServiceConfigEntity.getClusterEntity();

    Long clusterId = clusterEntity.getClusterId();

    if(null == clusterId){
      clusterId = 1L;
      clusterEntity.setClusterId(clusterId);
      clusterEntity = clusterDAO.merge(clusterEntity);
    }

    StackEntity stackEntityHDP01 = stackDAO.find(HDP_01.getStackName(),HDP_01.getStackVersion());
    String oozieSite = "oozie-site";

    // create 2 configurations for HDP-0.1
    int count = 2;
    for (int i = 1; i <= count; i++) {
      Thread.sleep(1);
      ClusterConfigEntity entity = new ClusterConfigEntity();
      entity.setClusterEntity(clusterEntity);
      entity.setClusterId(clusterEntity.getClusterId());
      entity.setType(oozieSite);
      entity.setVersion(Long.valueOf(i));
      entity.setTag("version"+i);
      entity.setTimestamp(new Date().getTime());
      entity.setStack(stackEntityHDP01);
      entity.setData("");
      entity.setSelected(false);

      if (i == count) {
        entity.setSelected(true);
      }

      clusterDAO.createConfig(entity);
      clusterEntity.getClusterConfigEntities().add(entity);
      clusterDAO.merge(clusterEntity);
    }

    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
    if (resourceTypeEntity == null) {
      resourceTypeEntity = new ResourceTypeEntity();
      resourceTypeEntity.setId(ResourceType.CLUSTER.getId());
      resourceTypeEntity.setName(ResourceType.CLUSTER.name());
      resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity);
    }

    ResourceEntity resourceEntity = new ResourceEntity();
    resourceEntity.setResourceType(resourceTypeEntity);

    // create a configuration group for oozie
    ConfigGroupEntity configGroupEntity = new ConfigGroupEntity();
    configGroupEntity.setClusterEntity(clusterEntity);
    configGroupEntity.setClusterId(clusterEntity.getClusterId());
    configGroupEntity.setGroupName("oozie_server");
    configGroupEntity.setDescription("oozie server");
    configGroupEntity.setTag("OOZIE");
    configGroupDAO.create(configGroupEntity);

    // create a new configuration for oozie, for the config group
    ClusterConfigEntity configEntityForGroup = new ClusterConfigEntity();
    configEntityForGroup.setSelected(false);
    configEntityForGroup.setType("oozie-site");
    configEntityForGroup.setTag("version3");
    configEntityForGroup.setData("someData");
    configEntityForGroup.setAttributes("someAttributes");
    configEntityForGroup.setStack(stackEntityHDP01);

    List<ClusterConfigEntity> configEntitiesForGroup = new ArrayList<>();
    configEntitiesForGroup.add(configEntityForGroup);
    List<ConfigGroupConfigMappingEntity> configMappingEntities = new ArrayList<>();

    for (ClusterConfigEntity config : configEntitiesForGroup) {
      config.setClusterEntity(clusterEntity);
      config.setClusterId(clusterEntity.getClusterId());
      clusterDAO.createConfig(config);

      Thread.sleep(1);
      ConfigGroupConfigMappingEntity configMappingEntity = new
        ConfigGroupConfigMappingEntity();
      configMappingEntity.setClusterId(clusterEntity.getClusterId());
      configMappingEntity.setClusterConfigEntity(config);
      configMappingEntity.setConfigGroupEntity(configGroupEntity);
      configMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
      configMappingEntity.setVersionTag(config.getTag());
      configMappingEntity.setConfigType(config.getType());
      configMappingEntity.setTimestamp(System.currentTimeMillis());
      configMappingEntities.add(configMappingEntity);
      configGroupConfigMappingDAO.create(configMappingEntity);
    }

    configGroupEntity.setConfigGroupConfigMappingEntities(configMappingEntities);
    configGroupDAO.merge(configGroupEntity);
  }
Createa a cluster with 3 configurations for Oozie in the {@link #HDP_01}
stack. Only {@code version2}, will be enabled. {@code version3} will be for
a new configuration group.

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