protected ClusterEntity createCluster(Injector injector, String clusterName,
      StackEntity desiredStackEntity, String repositoryVersion) {
    ResourceTypeDAO resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);

    // create an admin resource to represent this cluster
    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);

    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterEntity clusterEntity = new ClusterEntity();
    clusterEntity.setClusterId(1L);
    clusterEntity.setClusterName(clusterName);
    clusterEntity.setDesiredStack(desiredStackEntity);
    clusterEntity.setProvisioningState(State.INIT);
    clusterEntity.setResource(resourceEntity);

    clusterDAO.create(clusterEntity);

    OrmTestHelper ormTestHelper = injector.getInstance(OrmTestHelper.class);
    ormTestHelper.getOrCreateRepositoryVersion(
        new StackId(desiredStackEntity.getStackName(), desiredStackEntity.getStackVersion()),
        repositoryVersion);

    return clusterEntity;
  }
Creates a cluster with the specified name and stack as well as the
repository version.

@param injector
@param clusterName
@param desiredStackEntity
@return
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java