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

    Map<String, String> properties = new HashMap<String, String>() {
      {
        put("key_to_append", "append");
        put("key_to_prepend", "prepend");
      }
    };

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

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

    createUpgrade(c, repoVersion2111);

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

    // define the changes
    final String prependValue = "This should be on a newline";
    final String appendValue = " this will be after...";

    // insert tasks
    List<Insert> insertions = new ArrayList<>();

    Insert prepend = new Insert();
    prepend.insertType = InsertType.PREPEND;
    prepend.key = "key_to_prepend";
    prepend.value = prependValue;
    prepend.newlineBefore = false;
    prepend.newlineAfter = true;

    Insert append = new Insert();
    append.insertType = InsertType.APPEND;
    append.key = "key_to_append";
    append.value = appendValue;
    append.newlineBefore = false;
    append.newlineAfter = false;

    // add them to the list
    insertions.add(prepend);
    insertions.add(append);

    // just for fun, add them again - this will test their idempotence
    insertions.add(prepend);
    insertions.add(append);

    commandParams.put(ConfigureTask.PARAMETER_INSERTIONS, new Gson().toJson(insertions));

    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(3, c.getConfigsByType("zoo.cfg").size());

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

    // build the expected values
    String expectedPrepend = prependValue + System.lineSeparator() + "prepend";
    String expectedAppend = "append" + appendValue;

    assertEquals(expectedPrepend, config.getProperties().get("key_to_prepend"));
    assertEquals(expectedAppend, config.getProperties().get("key_to_append"));
  }
Tests using the {@code <insert/>} element in a configuration upgrade pack.

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