root/honeyclient/tags/bug/POST-42/t/honeyclient_util_config.t

Revision 96, 7.3 kB (checked in by kindlund, 2 years ago)

Completed registry parser documentation and unit tests; corrected minor mispellings; updated POD documentation to reflect public website.

Line 
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More 'no_plan';
5 $| = 1;
6
7
8
9 # =begin testing
10 {
11 # Make sure Log::Log4perl loads
12 BEGIN { use_ok('Log::Log4perl', qw(:nowarn))
13         or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path.");
14        
15         # Suppress all logging messages, since we need clean output for unit testing.
16         Log::Log4perl->init({
17             "log4perl.rootLogger"                               => "DEBUG, Buffer",
18             "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
19             "log4perl.appender.Buffer.min_level"                => "fatal",
20             "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
21             "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
22         });
23 }
24 require_ok('Log::Log4perl');
25 use Log::Log4perl qw(:easy);
26
27 # Make sure the module loads properly, with the exportable
28 # functions shared.
29 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar setVar))
30         or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path."); }
31 require_ok('HoneyClient::Util::Config');
32 can_ok('HoneyClient::Util::Config', 'getVar');
33 can_ok('HoneyClient::Util::Config', 'setVar');
34 use HoneyClient::Util::Config qw(getVar setVar);
35
36 # Suppress all logging messages, since we need clean output for unit testing.
37 Log::Log4perl->init({
38     "log4perl.rootLogger"                               => "DEBUG, Buffer",
39     "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
40     "log4perl.appender.Buffer.min_level"                => "fatal",
41     "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
42     "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
43 });
44
45 # Make sure XML::XPath loads.
46 BEGIN { use_ok('XML::XPath')
47         or diag("Can't load XML::XPath package.  Check to make sure the package library is correctly listed within the path."); }
48 require_ok('XML::XPath');
49 can_ok('XML::XPath', 'findnodes');
50 use XML::XPath;
51
52 # Make sure XML::Tidy loads
53 BEGIN { use_ok('XML::Tidy')
54         or diag("Can't load XML::Tidy package. Check to make sure the package library is correctly listed within the path."); }
55 require_ok('XML::Tidy');
56 can_ok('XML::Tidy','tidy');
57 can_ok('XML::Tidy','write');
58 use XML::Tidy;
59
60 # Make sure Data::Dumper loads
61 BEGIN { use_ok('Data::Dumper')
62         or diag("Can't load Data::Dumper package. Check to make sure the package library is correctly listed within the path."); }
63 require_ok('Data::Dumper');
64 use Data::Dumper;
65 }
66
67
68
69 # =begin testing
70 {
71 my $value = getVar(name => "address", namespace => "HoneyClient::Util::Config::Test");
72 is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test')")
73     or diag("The getVar() call failed.  Attempted to get variable 'address' using namespace 'HoneyClient::Util::Config::Test' within the global configuration file.");
74
75 $value = getVar(name => "address", namespace => "HoneyClient::Util::Config::Test", attribute => 'default');
76 is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'default')")
77     or diag("The getVar() call failed.  Attempted to get attribute 'default' for variable 'address' using namespace 'HoneyClient::Util::Config::Test' within the global configuration file.");
78
79 # This check tests to make sure getVar() is able to use valid output
80 # from undefined namespaces (but where some of the parent namespace is
81 # partially known).
82 $value = getVar(name => "address", namespace => "HoneyClient::Util::Config::Test::Undefined::Child", attribute => 'default');
83 is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Undefined::Child', attribute => 'default')")
84     or diag("The getVar() call failed.  Attempted to get attribute 'default' for variable 'address' using namespace 'HoneyClient::Util::Config::Test::Undefined::Child' within the global configuration file.");
85 }
86
87
88
89 # =begin testing
90 {
91 # Test setting an existing value
92 my $oldval = getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test' );
93 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', value => 'foobar' );
94 my $value = getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test' );
95 is($value, 'foobar', "setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', value => 'foobar' )")
96     or diag("The setVar() call failed.  Attempted to set variable 'address' using namespace 'HoneyClient::Util::Config::Test' to 'foobar' within the global configuration file.");
97 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', value => $oldval );
98
99 # Test setting an attribute
100 $oldval = getVar(name => 'address', attribute => 'default', namespace => 'HoneyClient::Util::Config::Test' );
101 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'default', value => 'foobar' );
102 $value = getVar(name => 'address', attribute => 'default', namespace => 'HoneyClient::Util::Config::Test' );
103 is($value, 'foobar', "setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'default', value => 'foobar' )")
104     or diag("The setVar() call failed.  Attempted to set 'default' attribute of variable 'address' using namespace 'HoneyClient::Util::Config::Test' to 'foobar' within the global configuration file.");
105 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'default', value => $oldval );
106
107 # Test creating a value
108 setVar(name => 'zingers', namespace => 'HoneyClient::Util::Config::Test', value => 'foobar');
109 $value = getVar(name => 'zingers', namespace => 'HoneyClient::Util::Config::Test' );
110 is($value, 'foobar', "setVar(name => 'zingers', namespace => 'HoneyClient::Util::Config::Test', value => 'foobar' )")
111     or diag("The setVar() call failed.  Attempted to create variable 'zing' using namespace 'HoneyClient::Util::Config::Test' with a value of 'foobar' within the global configuration file.");
112
113 # Test creating an attribute
114 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'zing', value => 'foobar');
115 $value = getVar(name => 'address', attribute => 'zing', namespace => 'HoneyClient::Util::Config::Test' );
116 is($value, 'foobar', "setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test', attribute => 'zing', value => 'foobar' )")
117     or diag("The setVar() call failed.  Attempted to create attribute 'zing' using namespace 'HoneyClient::Util::Config::Test' with a value of 'foobar' within the global configuration file.");
118
119 # Creating new namespaces
120 setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Foo::Bar', value => 'baz');
121 $value =  getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Foo::Bar');
122 is($value, 'baz', "setVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Foo::Bar', value => 'baz')")
123     or diag("The setVar() call failed.  Attempted to create attribute 'address' using namespace 'HoneyClient::Util::Config::Test::Foo::Bar' with a value of 'baz' within global configuration file.");
124 }
125
126
127
128
129 1;
Note: See TracBrowser for help on using the browser.