#!/usr/bin/env ruby #:nodoc: require 'test/unit' require 'ftools' require '../lib/xmlconfigfile' # # test cases for using set_parameter with the # create argument # class TC_Create < Test::Unit::TestCase #:nodoc: def setup @config = XmlConfigFile.new('original_files/create.xml') end # # add attribute with an existing element # def test_set_parameter_create_new_attr_w_exists # Existing XPath, Sanity Check @config.set_parameter('/config/created/exists/here_pre_no_attr/@post', 'exist',true) assert_equal('exist', @config.get_string('/config/created/exists/here_pre_no_attr/@post')) @config.set_parameter('/config/created/exists/here_pre_no_attr', 'post',true) assert_equal('post', @config.get_string('/config/created/exists/here_pre_no_attr')) end # # Creating a new empty element # def test_set_parameter_create_new_element_empty @config.set_parameter('/config/created/post_exists/empty', nil, true) assert_equal(nil, @config.get_string('/config/created/post_exists/empty')) end # # Creating a new element with text # def test_set_parameter_create_new_element_w_text @config.set_parameter('/config/created/post_exists/post','new',true) assert_equal('new', @config.get_string('/config/created/post_exists/post')) end # # Creating a new empty element w/ attri # def test_set_parameter_create_new_element_empty_w_attr @config.set_parameter('/config/created/post_exists/post_attr/@new_attr','hi',true) assert_equal('hi', @config.get_string('/config/created/post_exists/post_attr/@new_attr')) end # # Creating a new element with attr and text # def test_set_parameter_create_new_element_w_text_w_attr # # Try this in two different orders. # clone_config = @config.clone clone_config.set_parameter('/config/created/post_exists/post_attr_w_text/@new_attr','ok!',true) assert_equal('ok!', @config.get_string('/config/created/post_exists/post_attr_w_text/@new_attr')) clone_config.set_parameter('/config/created/post_exists/post_attr_w_text','text',true) assert_equal('text', @config.get_string('/config/created/post_exists/post_attr_w_text/')) clone_config = nil @config.set_parameter('/config/created/post_exists/post_attr_w_text','text',true) assert_equal('text', @config.get_string('/config/created/post_exists/post_attr_w_text/')) @config.set_parameter('/config/created/post_exists/post_attr_w_text/@new_attr','ok!',true) assert_equal('ok!', @config.get_string('/config/created/post_exists/post_attr_w_text/@new_attr')) end # # Run all tests from scratch, and then store results # and check validity of storage mechanism # def test_set_parameter_create_with_store store_name = 'test_create_with_store.xml' # # re-init instance of XmlConfigFile # setup # # Run Test's that modify memory version of ConfigFile # test_set_parameter_create_new_attr_w_exists test_set_parameter_create_new_element_empty test_set_parameter_create_new_element_w_text test_set_parameter_create_new_element_empty_w_attr test_set_parameter_create_new_element_w_text_w_attr # # Store New Config in Current Dir # @config.store(store_name) # # Compare same = File::cmp('reference/store_create.xml',store_name) assert_equal(true, same) File::delete(store_name) if same end end