@Test
public void testDisallowedTransferDelete() 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("delete.key.1", "d1");
        put("delete.key.2", "d2");
        put("delete.key.3", "d3");
        put("delete.key.4", "d4");
      }}, 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));
  List<Transfer> transfers = new ArrayList<>();
  Transfer transfer2 = new Transfer();
  transfer2.operation = TransferOperation.DELETE;
  transfer2.deleteKey = "delete.key.2";
  transfer2.ifKey = "initLimit";
  transfer2.ifType = "zoo.cfg";
  transfer2.ifValue = "not.real.value";
  transfers.add(transfer2);
  Transfer transfer3 = new Transfer();
  transfer3.operation = TransferOperation.DELETE;
  transfer3.deleteKey = "delete.key.3";
  transfer3.ifKey = "initLimit";
  transfer3.ifType = "zoo.cfg";
  transfer3.ifKeyState = PropertyKeyState.ABSENT;
  transfers.add(transfer3);
  Transfer transfer4 = new Transfer();
  transfer4.operation = TransferOperation.DELETE;
  transfer4.deleteKey = "delete.key.4";
  transfer4.ifKey = "no.such.key";
  transfer4.ifType = "zoo.cfg";
  transfer4.ifKeyState = PropertyKeyState.PRESENT;
  transfers.add(transfer4);
  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(5, map.size());
  assertEquals("11", map.get("initLimit"));
  String[] shouldExitKeys = new String[]{"delete.key.1","delete.key.2","delete.key.3","delete.key.4"};
  for(String key: shouldExitKeys){
    assertTrue(map.containsKey(key));
  }
}