@Test
  public void testCreateDefaultHostParams() throws Exception {
    String clusterName = "c1";
    String SOME_STACK_NAME = "SomeStackName";
    String SOME_STACK_VERSION = "1.0";
    String MYSQL_JAR = "MYSQL_JAR";
    String JAVA_HOME = "javaHome";
    String JDK_NAME = "jdkName";
    String JCE_NAME = "jceName";
    String OJDBC_JAR_NAME = "OjdbcJarName";
    String SERVER_DB_NAME = "ServerDBName";
    Map<PropertyInfo, String> notManagedHdfsPathMap = new HashMap<>();
    PropertyInfo propertyInfo1 = new PropertyInfo();
    propertyInfo1.setName("1");
    PropertyInfo propertyInfo2 = new PropertyInfo();
    propertyInfo2.setName("2");
    notManagedHdfsPathMap.put(propertyInfo1, "/tmp");
    notManagedHdfsPathMap.put(propertyInfo2, "/apps/falcon");

    Set<String> notManagedHdfsPathSet = new HashSet<>(Arrays.asList("/tmp", "/apps/falcon"));
    Gson gson = new Gson();

    ActionManager manager = createNiceMock(ActionManager.class);
    StackId stackId = createNiceMock(StackId.class);
    Cluster cluster = createNiceMock(Cluster.class);
    Injector injector = createNiceMock(Injector.class);
    Configuration configuration = createNiceMock(Configuration.class);
    RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
    ConfigHelper configHelper = createNiceMock(ConfigHelper.class);

    Map<String, DesiredConfig> desiredConfigs = new HashMap<>();

    expect(cluster.getClusterName()).andReturn(clusterName);
    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
    expect(cluster.getDesiredConfigs()).andReturn(desiredConfigs);
    expect(stackId.getStackName()).andReturn(SOME_STACK_NAME).anyTimes();
    expect(stackId.getStackVersion()).andReturn(SOME_STACK_VERSION).anyTimes();
    expect(configuration.getMySQLJarName()).andReturn(MYSQL_JAR);
    expect(configuration.getJavaHome()).andReturn(JAVA_HOME);
    expect(configuration.getJDKName()).andReturn(JDK_NAME);
    expect(configuration.getJCEName()).andReturn(JCE_NAME);
    expect(configuration.getOjdbcJarName()).andReturn(OJDBC_JAR_NAME);
    expect(configuration.getServerDBName()).andReturn(SERVER_DB_NAME);
    expect(configuration.getJavaVersion()).andReturn(8);
    expect(configuration.areHostsSysPrepped()).andReturn("true");
    expect(configuration.getGplLicenseAccepted()).andReturn(false);
    expect(configuration.getDatabaseConnectorNames()).andReturn(new HashMap<>()).anyTimes();
    expect(configuration.getPreviousDatabaseConnectorNames()).andReturn(new HashMap<>()).anyTimes();
    expect(repositoryVersionEntity.getVersion()).andReturn("1234").anyTimes();
    expect(repositoryVersionEntity.getStackId()).andReturn(stackId).anyTimes();
    expect(configHelper.getPropertiesWithPropertyType(stackId,
        PropertyInfo.PropertyType.NOT_MANAGED_HDFS_PATH, cluster, desiredConfigs)).andReturn(
            notManagedHdfsPathMap);
    expect(configHelper.filterInvalidPropertyValues(notManagedHdfsPathMap, NOT_MANAGED_HDFS_PATH_LIST)).andReturn(
            notManagedHdfsPathSet);

    replay(manager, clusters, cluster, injector, stackId, configuration, repositoryVersionEntity, configHelper);

    AmbariManagementControllerImpl ambariManagementControllerImpl =
        createMockBuilder(AmbariManagementControllerImpl.class)
            .addMockedMethod("getRcaParameters")
            .withConstructor(manager, clusters, injector).createNiceMock();

    expect(ambariManagementControllerImpl.
        getRcaParameters()).andReturn(new HashMap<>());
    replay(ambariManagementControllerImpl);

    // Inject configuration manually
    Class<?> amciClass = AmbariManagementControllerImpl.class;
    Field f = amciClass.getDeclaredField("configs");
    f.setAccessible(true);
    f.set(ambariManagementControllerImpl, configuration);

    AmbariCustomCommandExecutionHelper helper = new AmbariCustomCommandExecutionHelper();
    Class<?> helperClass = AmbariCustomCommandExecutionHelper.class;
    f = helperClass.getDeclaredField("managementController");
    f.setAccessible(true);
    f.set(helper, ambariManagementControllerImpl);

    f = helperClass.getDeclaredField("configs");
    f.setAccessible(true);
    f.set(helper, configuration);

    f = helperClass.getDeclaredField("configHelper");
    f.setAccessible(true);
    f.set(helper, configHelper);

    f = helperClass.getDeclaredField("gson");
    f.setAccessible(true);
    f.set(helper, gson);

    Map<String, String> defaultHostParams = helper.createDefaultHostParams(cluster, repositoryVersionEntity.getStackId());

    assertEquals(16, defaultHostParams.size());
    assertEquals(MYSQL_JAR, defaultHostParams.get(DB_DRIVER_FILENAME));
    assertEquals(SOME_STACK_NAME, defaultHostParams.get(STACK_NAME));
    assertEquals(SOME_STACK_VERSION, defaultHostParams.get(STACK_VERSION));
    assertEquals("true", defaultHostParams.get(HOST_SYS_PREPPED));
    assertEquals("8", defaultHostParams.get(JAVA_VERSION));
    assertNotNull(defaultHostParams.get(NOT_MANAGED_HDFS_PATH_LIST));
    assertTrue(defaultHostParams.get(NOT_MANAGED_HDFS_PATH_LIST).contains("/tmp"));
  }
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