aboutsummaryrefslogtreecommitdiff
path: root/t/01-config.t
blob: 5a3e6b7d1641c8db5c130c9adc0d2e07c5e2f687 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/perl 
use strict;
use warnings;
use Path::Class;
use Test::More 'no_plan';
use Test::Exception;
 
my $thisdir=file($0)->parent->absolute;
 
BEGIN { use_ok('WebCoso::Config'); }
 
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','Id','dst/file.html');
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione');
 
my @resources=WebCoso::Config->get_all_resources();
is(scalar @resources,1,'una risorsa definta');
 
isa_ok($resources[0],'WebCoso::Config::Resource');
is_deeply(
    [$resources[0]->get_axes()],
    ['filename'],
    'un solo asse');
is_deeply(
    [$resources[0]->get_axis_value('filename')],
    ["$thisdir/src/file1.rest.txt"],
    'filename');
is($resources[0]->get_datastream(filename=>"$thisdir/src/file1.rest.txt"),
   <<'EOF','');
Titolo
======
 
testo
EOF
is_deeply(
    [$resources[0]->get_properties()],
    [],
    'no properties');
is_deeply(
    [$resources[0]->get_collections()],
    [],
    'no collections');
 
is(WebCoso::Config->get_pipeline_for($resources[0]),
   'WebCoso::Pipeline::Id',
   'si segna le pipeline');
 
throws_ok {
    WebCoso::Config->get_pipeline_for('not-a-resource')
  }
    'WebCoso::X::NoSuchResource',
        'muore se gli si chiede una risorsa ignota';
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','src/nonce.rest.txt','Id','dst/file.html');
EOF
 
throws_ok {
    WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test")
  }
    'WebCoso::X::ConfigError',
        'muore se non trova il file';
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
coll('coll1');
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione');
 
is(scalar WebCoso::Config->get_all_resources(),0,'nessuna risorsa');
 
my $collections=WebCoso::Config->get_collections();
isa_ok($collections,'WebCoso::Config::Collections');
my @collections=$collections->get_all_collections();
is(scalar @collections,1,'una collezione');
 
is_deeply(
    [$collections[0]->get_axes()],
    ['language'],
    'multilingua');
is_deeply(
    [$collections[0]->get_axis_value('language')],
    [],
    'ma nessuna definita');
is_deeply(
    [$collections->get_axes()],
    ['language'],
    'multilingua, insieme');
is_deeply(
    [$collections->get_axis_value('language')],
    [],
    'ma nessuna definita, insieme');
my $props=$collections[0]->get_properties(language=>'');
isa_ok($props,'HASH');
is_deeply(
    $props,
    {name=>'coll1'},
    'solo il nome');
 
is_deeply(
    [$collections[0]->get_parents()],
    [],
    'no parents');
is_deeply(
    [$collections[0]->get_children()],
    [],
    'no children');
is_deeply(
    [$collections[0]->get_resources()],
    [],
    'no resources');
is_deeply(
    [$collections->get_root_collections()],
    [@collections],
    'una radice');
is_deeply(
    [$collections->get_leaf_collections()],
    [@collections],
    'una foglia');
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
my $c1=coll({it=>'coll1',en=>'coll1-en'});
coll('coll2',[],[$c1]);
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione');
 
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
is(scalar @collections,2,'due collezioni');
 
# qui sto assumendo che le collezioni vengano registrate in ordine di 
# definizione. Forse non sarà sempre vero 
 
is_deeply(
    [sort $collections[0]->get_axis_value('language')],
    ['en''it'],
    'due lingue');
is_deeply(
    [sort $collections->get_axis_value('language')],
    ['en''it'],
    'due lingue');
is(
    $collections[0]->get_properties(language=>'en')->{name},
    'coll1-en',
    'nome en');
is(
    $collections[0]->get_properties(language=>'it')->{name},
    'coll1',
    'nome it');
is(
    $collections[1]->get_properties(language=>'it')->{name},
    'coll2',
    'nome default');
 
is_deeply(
    [$collections[0]->get_parents()],
    [$collections[1]],
    'c2 padre di c1');
is_deeply(
    [$collections[0]->get_children()],
    [],
    'c1 no children');
is_deeply(
    [$collections[1]->get_parents()],
    [],
    'c2 no parents');
is_deeply(
    [$collections[1]->get_children()],
    [$collections[0]],
    'c1 figlio di c2');
is_deeply(
    [$collections->get_root_collections()],
    [$collections[1]],
    'una radice');
is_deeply(
    [$collections->get_leaf_collections()],
    [$collections[0]],
    'una foglia');
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
$c1=coll({it=>'coll1',en=>'coll1-en'});
$c2=coll('coll2',[],[$c1]);
$c1->add_child($c2);
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione (no strict)');
 
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
is(scalar @collections,2,'due collezioni');
 
is_deeply(
    [$collections[1]->get_children()],
    [$collections[0]],
    'c1 figlio di c2');
is_deeply(
    [$collections[0]->get_parents()],
    [$collections[1]],
    'c2 padre di c1');
 is_deeply(
    [$collections[0]->get_children()],
    [$collections[1]],
    'c2 figlio di c1');
is_deeply(
    [$collections[1]->get_parents()],
    [$collections[0]],
    'c1 padre di c2');
is_deeply(
    [$collections->get_root_collections()],
    [],
    'nessuna radice');
is_deeply(
    [$collections->get_leaf_collections()],
    [],
    'nessuna foglia');
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
$r1=res('src/file1.rest.txt','Id','dst/file.html');
$c1=coll('coll1');
$c1->add_res($r1);
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione (no strict)');
 
my @resources=WebCoso::Config->get_all_resources();
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
 
is(scalar @resources,1,'una risorsa');
is(scalar @collections,1,'una collezione');
is_deeply(
    [$resources[0]->get_collections()],
    [$collections[0]],
    'aggancio r->c');
is_deeply(
    [$collections[0]->get_resources()],
    [$resources[0]],
    'aggancio c->r');
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
$r1=res('src/file1.rest.txt','Id','dst/file.html');
$c1=coll('coll1');
$c2=coll('coll2');
$c1->add_res($r1);
$r1->add_coll($c1);
$c2->add_res($r1);
EOF
 
ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
   'eseguita la configurazione (no strict)');
 
my @resources=WebCoso::Config->get_all_resources();
my $collections=WebCoso::Config->get_collections();
my @collections=$collections->get_all_collections();
 
is(scalar @resources,1,'una risorsa');
is(scalar @collections,2,'due collezioni');
is_deeply(
    [sort $resources[0]->get_collections()],
    [sort $collections[0],$collections[1]],
    'aggancio r->c');
is_deeply(
    [$collections[0]->get_resources()],
    [$resources[0]],
    'aggancio c->r');
is_deeply(
    [$collections[1]->get_resources()],
    [$resources[0]],
    'aggancio c->r');
}
 
WebCoso::Config->clear();
 
{
my $conf_file=<<'EOF';
res('src/file1.rest.txt','NoSuchPipeline','dst/file.html');
EOF
 
throws_ok {
    WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test")
  }
    'WebCoso::X::ConfigError',
        'muore se la pipeline è ignota';
}