@Test
  public void testDisallowedTransferCopy() throws Exception {
    Cluster c = clusters.getCluster("c1");
    assertEquals(1, c.getConfigsByType("zoo.cfg").size());

    Map<String, String> properties = new HashMap<String, String>() {
      {
        put("initLimit", "10");
        put("copy.key.1", "c1");
        put("copy.key.2", "c2");
      }
    };

    Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties);

    c.addDesiredConfig("user", Collections.singleton(config));
    assertEquals(2, c.getConfigsByType("zoo.cfg").size());

    List<ConfigurationKeyValue> configurations = new ArrayList<>();
    ConfigurationKeyValue keyValue = new ConfigurationKeyValue();
    configurations.add(keyValue);
    keyValue.key = "initLimit";
    keyValue.value = "11";

    createUpgrade(c, repoVersion2111);

    Map<String, String> commandParams = new HashMap<>();
    commandParams.put("clusterName", "c1");
    commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg");
    commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations));

    List<Transfer> transfers = new ArrayList<>();
    Transfer transfer = new Transfer();
    transfer.operation = TransferOperation.COPY;
    transfer.fromKey = "copy.key.2";
    transfer.toKey = "copy.to.key.2";
    transfer.ifKey = "initLimit";
    transfer.ifType = "zoo.cfg";
    transfer.ifValue = "not-the-real-value";
    transfers.add(transfer);

    transfer = new Transfer();
    transfer.operation = TransferOperation.COPY;
    transfer.fromKey = "copy.key.2";
    transfer.toKey = "copy.to.key.3";
    transfer.ifKey = "initLimit";
    transfer.ifType = "zoo.cfg";
    transfer.ifKeyState = PropertyKeyState.ABSENT;
    transfers.add(transfer);

    transfer = new Transfer();
    transfer.operation = TransferOperation.COPY;
    transfer.fromKey = "copy.key.no.need.to.exist.2";
    transfer.toKey = "copy.to.key.with.default.2";
    transfer.defaultValue = "defaultValue2";
    transfer.ifKey = "no.such.key";
    transfer.ifType = "zoo.cfg";
    transfer.ifKeyState = PropertyKeyState.PRESENT;
    transfers.add(transfer);

    commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers));

    ExecutionCommand executionCommand = new ExecutionCommand();
    executionCommand.setCommandParams(commandParams);
    executionCommand.setClusterName("c1");
    executionCommand.setRoleParams(new HashMap<>());
    executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username");

    HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null,
        null, null);

    hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(
        executionCommand));


    action.setExecutionCommand(executionCommand);
    action.setHostRoleCommand(hostRoleCommand);

    CommandReport report = action.execute(null);
    assertNotNull(report);

    assertEquals(3, c.getConfigsByType("zoo.cfg").size());

    config = c.getDesiredConfigByType("zoo.cfg");
    assertNotNull(config);
    assertFalse("version2".equals(config.getTag()));

    Map<String, String> map = config.getProperties();
    assertEquals(3, map.size());
    assertEquals("11", map.get("initLimit"));
    assertEquals("c1", map.get("copy.key.1"));
    assertEquals("c2", map.get("copy.key.2"));
  }
Tests that replacing a {@code null} value works.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java