######################################################################
#
# File editing edit_xml - test changing an existing attribute of a node
#
######################################################################

body common control
{
      inputs => { "../../default.sub.cf" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

#######################################################

bundle agent init
{
  vars:
      "states" slist => { "actual", "expected" };

      "actual" string =>
      "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<Potatoes>
  <Potato name=\"OnePotato\" topping=\"broccoli\">
  </Potato>
  <Potato name=\"TwoPotato\">
  </Potato>
  <Potato name=\"ThreePotato\">
  </Potato>
</Potatoes>";

      "expected" string =>
      "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<Potatoes>
  <Potato name=\"OnePotato\" topping=\"sourcream\">
  </Potato>
  <Potato name=\"TwoPotato\">
  </Potato>
  <Potato name=\"ThreePotato\">
  </Potato>
</Potatoes>";

  files:
      "$(G.testfile).$(states)"
      create => "true",
      edit_line => init_insert("$(init.$(states))"),
      edit_defaults => init_empty;
}

bundle edit_line init_insert(str)
{
  insert_lines:
      "$(str)";
}

body edit_defaults init_empty
{
      empty_file_before_editing => "true";
}

#######################################################
bundle agent test
{
  meta:
      "test_soft_fail" string => "windows",
        meta => { "ENT-10215" };

  vars:
      "attribute_name" string => "topping";

  files:
      "$(G.testfile).actual"
      create => "true",
      edit_xml => test_set("$(test.attribute_name)");
}

bundle edit_xml test_set(str)
{
  set_attribute:
      "$(str)"
      select_xpath => "/Potatoes/Potato[@name=\'OnePotato\']",
      attribute_value => "sourcream";
}

#######################################################

bundle agent check
{
  methods:
      "any" usebundle => xml_check_diff("$(G.testfile).actual",
                                        "$(G.testfile).expected",
                                        "$(this.promise_filename)", "no");
}

### PROJECT_ID: core
### CATEGORY_ID: 27
