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

    Map<String, String> properties = new HashMap<String, String>() {
      {
        put("set.key.1", "s1");
        put("set.key.2", "s2");
        put("set.key.3", "s3");
        put("set.key.4", "s4");
      }
    };

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

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

    // create several configurations
    List<ConfigurationKeyValue> configurations = new ArrayList<>();
    ConfigurationKeyValue fooKey3 = new ConfigurationKeyValue();
    configurations.add(fooKey3);
    fooKey3.key = "fooKey3";
    fooKey3.value = "barValue3";
    fooKey3.ifKey = "set.key.1";
    fooKey3.ifType = "zoo.cfg";
    fooKey3.ifValue = "no-such-value";

    ConfigurationKeyValue fooKey4 = new ConfigurationKeyValue();
    configurations.add(fooKey4);
    fooKey4.key = "fooKey4";
    fooKey4.value = "barValue4";
    fooKey4.ifKey = "set.key.2";
    fooKey4.ifType = "zoo.cfg";
    fooKey4.ifKeyState= PropertyKeyState.ABSENT;

    ConfigurationKeyValue fooKey5 = new ConfigurationKeyValue();
    configurations.add(fooKey5);
    fooKey5.key = "fooKey5";
    fooKey5.value = "barValue5";
    fooKey5.ifKey = "abc";
    fooKey5.ifType = "zoo.cfg";
    fooKey5.ifKeyState= PropertyKeyState.PRESENT;

    createUpgrade(c, repoVersion2200);

    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));

    ExecutionCommand executionCommand = getExecutionCommand(commandParams);
    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(2, c.getConfigsByType("zoo.cfg").size());

    config = c.getDesiredConfigByType("zoo.cfg");
    assertNotNull(config);
    assertEquals("s1", config.getProperties().get("set.key.1"));
    assertEquals("s2", config.getProperties().get("set.key.2"));
    assertEquals("s3", config.getProperties().get("set.key.3"));
    assertEquals("s4", config.getProperties().get("set.key.4"));
    assertFalse(config.getProperties().containsKey("fooKey3"));
    assertFalse(config.getProperties().containsKey("fooKey4"));
    assertFalse(config.getProperties().containsKey("fooKey5"));
  }
Tests that replacing a {@code null} value works.

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