@Test
  public void testCreateClusterWithRepository() throws Exception {
    Injector injector = createNiceMock(Injector.class);

    RepositoryVersionEntity repoVersion = createNiceMock(RepositoryVersionEntity.class);
    RepositoryVersionDAO repoVersionDAO = createNiceMock(RepositoryVersionDAO.class);
    expect(repoVersionDAO.findByStackAndVersion(anyObject(StackId.class),
        anyObject(String.class))).andReturn(repoVersion).anyTimes();

    expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).atLeastOnce();
    expect(injector.getInstance(Gson.class)).andReturn(null);
    expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class));

    StackId stackId = new StackId("HDP-2.1");

    Cluster cluster = createNiceMock(Cluster.class);
    Service service = createNiceMock(Service.class);
    expect(service.getDesiredStackId()).andReturn(stackId).atLeastOnce();

    expect(clusters.getCluster("c1")).andReturn(cluster).atLeastOnce();


    StackInfo stackInfo = createNiceMock(StackInfo.class);

    expect(ambariMetaInfo.getStack("HDP", "2.1")).andReturn(stackInfo).atLeastOnce();
    expect(ambariMetaInfo.getCommonWidgetsDescriptorFile()).andReturn(null).once();

    replay(injector, clusters, ambariMetaInfo, stackInfo, cluster, service, repoVersionDAO, repoVersion);

    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
    setAmbariMetaInfo(ambariMetaInfo, controller);
    Class<?> c = controller.getClass();

    Field f = c.getDeclaredField("repositoryVersionDAO");
    f.setAccessible(true);
    f.set(controller, repoVersionDAO);

    Properties p = new Properties();
    p.setProperty("", "");
    Configuration configuration = new Configuration(p);
    f = c.getDeclaredField("configs");
    f.setAccessible(true);
    f.set(controller, configuration);

    ClusterRequest cr = new ClusterRequest(null, "c1", "HDP-2.1", null);
    controller.createCluster(cr);

    // verification
    verify(injector, clusters, ambariMetaInfo, stackInfo, cluster, repoVersionDAO, repoVersion);
  }
Ensure that RollbackException is thrown outside the updateClusters method
when a unique constraint violation occurs.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java