@Test
public void testAllowedTransferCopy() throws Exception {

  makeUpgradeCluster();
  Cluster c = clusters.getCluster("c1");
  assertEquals(1, c.getConfigsByType("zoo.cfg").size());
  c.setDesiredStackVersion(HDP_220_STACK);
  Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{
        put("initLimit", "10");
        put("copy.key.1", "c1");
        put("copy.key.2", "c2");
      }}, new HashMap<String, Map<String,String>>());
  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";
  Map<String, String> commandParams = new HashMap<>();
  commandParams.put("upgrade_direction", "upgrade");
  commandParams.put("version", HDP_2_2_0_1);
  commandParams.put("clusterName", "c1");
  commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg");
  commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations));
  // normal copy
  List<Transfer> transfers = new ArrayList<>();
  Transfer transfer1 = new Transfer();
  transfer1.operation = TransferOperation.COPY;
  transfer1.fromKey = "copy.key.1";
  transfer1.toKey = "copy.to.key.1";
  transfers.add(transfer1);
  // copy with default
  Transfer transfer2 = new Transfer();
  transfer2.operation = TransferOperation.COPY;
  transfer2.fromKey = "copy.key.no.need.to.exit.1";
  transfer2.toKey = "copy.to.key.with.default.1";
  transfer2.defaultValue = "defaultValue";
  transfers.add(transfer2);
  Transfer transfer3 = new Transfer();
  transfer3.operation = TransferOperation.COPY;
  transfer3.fromKey = "copy.key.2";
  transfer3.toKey = "copy.to.key.2";
  transfer3.ifKey = "initLimit";
  transfer3.ifType = "zoo.cfg";
  transfer3.ifValue = "10";
  transfers.add(transfer3);
  Transfer transfer4 = new Transfer();
  transfer4.operation = TransferOperation.COPY;
  transfer4.fromKey = "copy.key.2";
  transfer4.toKey = "copy.to.key.3";
  transfer4.ifKey = "initLimit";
  transfer4.ifType = "zoo.cfg";
  transfer4.ifKeyState = PropertyKeyState.PRESENT;
  transfers.add(transfer4);
  Transfer transfer5 = new Transfer();
  transfer5.operation = TransferOperation.COPY;
  transfer5.fromKey = "copy.key.no.need.to.exist.2";
  transfer5.toKey = "copy.to.key.with.default.2";
  transfer5.defaultValue = "defaultValue2";
  transfer5.ifKey = "no.such.key";
  transfer5.ifType = "zoo.cfg";
  transfer5.ifKeyState = PropertyKeyState.ABSENT;
  transfers.add(transfer5);
  commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers));
  ExecutionCommand executionCommand = new ExecutionCommand();
  executionCommand.setCommandParams(commandParams);
  executionCommand.setClusterName("c1");
  executionCommand.setRoleParams(new HashMap<String, String>());
  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(8, map.size());
  assertEquals("11", map.get("initLimit"));
  assertEquals(map.get("copy.key.1"), map.get("copy.to.key.1"));
  assertTrue(!map.containsKey("copy.key.no.need.to.exit.1"));
  assertEquals("defaultValue", map.get("copy.to.key.with.default.1"));
  assertTrue(!map.containsKey("copy.key.no.need.to.exit.2"));
  assertEquals("defaultValue2", map.get("copy.to.key.with.default.2"));
  assertEquals(map.get("copy.key.2"), map.get("copy.to.key.2"));
  assertEquals(map.get("copy.key.2"), map.get("copy.to.key.3"));
}