######################################################################
#
# File editing edit_xml
#
######################################################################
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\"?>
<Server><Service><Engine><OneFish type=\"clownfish\">Nemo</OneFish></Engine></Service></Server>";

    "expected"
      string => "<?xml version=\"1.0\"?>
<Server><Service><Engine><OneFish type=\"clownfish\"><TwoFish><RedFish><BlueFish/></RedFish></TwoFish></OneFish></Engine></Service></Server>";

  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:
    "text" string => "Nemo";

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

bundle edit_xml test_delete(str)
{
  delete_text:
    "$(str)"
      build_xpath => "/Server/Service/Engine/OneFish[@type=\'clownfish\']/TwoFish/RedFish/BlueFish",
      select_xpath => "/Server/Service/Engine/OneFish[@type=\'clownfish\']";
}

#######################################################
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
