File: model.t

package info (click to toggle)
libconfig-model-perl 2.021-3%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,104 kB
  • sloc: perl: 20,550; makefile: 11
file content (144 lines) | stat: -rw-r--r-- 4,255 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- cperl -*-

use ExtUtils::testlib;
use Test::More tests => 12;
use Test::Exception ;
use Test::Warn ;
use Test::Differences ;
use Test::Memory::Cycle;
use Config::Model;
use Config::Model::Lister;
use Data::Dumper ;

use warnings;
no warnings qw(once);

use strict;

my $arg = shift || '';

my $trace = $arg =~ /t/ ? 1 : 0 ;
$::verbose          = 1 if $arg =~ /v/;
$::debug            = 1 if $arg =~ /d/;
Config::Model::Exception::Any->Trace(1) if $arg =~ /e/;

use Log::Log4perl qw(:easy) ;
Log::Log4perl->easy_init($arg =~ /l/ ? $TRACE: $WARN);

ok(1,"compiled") ;

my $model = Config::Model -> new()  ;

my ($cat,$models) = Config::Model::Lister::available_models ;

eq_or_diff($cat->{system},[qw/fstab lcdproc popcon/],"check available system models");
is($models->{popcon}{model},'PopCon',"check available popcon");

eq_or_diff($cat->{application}, [qw/dpkg dpkg-control dpkg-copyright multistrap/ ] ,"check available application models");
is($models->{'dpkg-copyright'}{model},'Debian::Dpkg::Copyright',"check available dpkg-copyright");

my $class_name = $model->create_config_class 
  (
   name => 'Sarge',
   experience => [ [qw/Y/] => 'beginner',  # default
                   X => 'master' 
                 ],
   status    => [ D => 'deprecated' ], #could be obsolete, standard
   description => [ X => 'X-ray (long description)' ],
   summary     => [ X => 'X-ray (summary)' ],

   element => [
               [qw/D X Y Z/] => {
                               type => 'leaf',
                               class => 'Config::Model::Value',
                               value_type => 'enum',
                               choice     => [qw/Av Bv Cv/]
                              }
              ],
  );

is($class_name,'Sarge',"check $class_name class name");
my $canonical_model = $model->get_model($class_name) ;
print "$class_name model:\n",Dumper($canonical_model) if $trace;

eq_or_diff($model->get_element_model($class_name,'D') ,
   {
   'value_type' => 'enum',
   'status' => 'deprecated',
   'type' => 'leaf',
   'class' => 'Config::Model::Value',
   'choice' => [ 'Av', 'Bv', 'Cv' ]
   }, 
   "check $class_name D element model");

eq_or_diff($model->get_element_model($class_name,'X') ,
   {
   'value_type' => 'enum',
   'summary' => 'X-ray (summary)',
   'type' => 'leaf',
   'class' => 'Config::Model::Value',
   'experience' => 'master',
   'choice' => [ 'Av', 'Bv', 'Cv' ],
   'description' => 'X-ray (long description)' }, 
   "check $class_name X element model"
   );

$class_name = $model->create_config_class 
  (
   name => 'Captain',
   experience => [ bar => 'beginner' ],
   element => [
               bar => { type => 'node', 
                        config_class_name => 'Sarge' 
                      }
              ]
  );

my @bad_model =
  (
   name => "Master",
   experience => [[qw/captain many/] => 'beginner' ],
   element => [
                captain => { 
                         type => 'node',
                         config_class_name => 'Captain',
                        },
                ],
  );

throws_ok {$model ->create_config_class(@bad_model)}
           "Config::Model::Exception::ModelDeclaration",
           "check model with orphan experience"
           ;
           
$class_name = $model ->create_config_class 
  (
   name => "Master",
   experience => [[qw/captain array_args hash_args/] => 'beginner' ],
   level     => [qw/captain/ => 'important' ] ,
   force_element_order => [qw/captain array_args hash_args/],
   element => [
                captain => { 
                         type => 'node',
                         config_class_name => 'Captain',
                        },
                [qw/array_args hash_args/] 
                => { type => 'node',
                     config_class_name => 'Captain',
                   },
               ],
   class_description => "Master description",
   description => [
                   captain       => "officer",
                   array_args => 'not officer'
                  ]
  );

ok(1,"Model created") ;

is($class_name,'Master',"check $class_name class name");

$canonical_model = $model->get_model($class_name) ;
print "$class_name model:\n",Dumper($canonical_model) if $trace;

memory_cycle_ok($model);