49
|
1 package Test::DOM::Schema;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Test::Unit);
|
|
6 use IMPL::Test qw(test failed shared);
|
|
7 use IMPL::Class::Property;
|
|
8
|
|
9 __PACKAGE__->PassThroughArgs;
|
|
10
|
|
11 require IMPL::DOM::Schema;
|
|
12
|
|
13 BEGIN {
|
|
14 shared public property SampleSchema => prop_all;
|
|
15 }
|
|
16
|
|
17 test GetMetaSchema => sub {
|
|
18 my $metaSchema = IMPL::DOM::Schema->MetaSchema();
|
|
19 };
|
|
20
|
|
21 test AutoverifyMetaSchema => sub {
|
|
22 my $metaSchema = IMPL::DOM::Schema->MetaSchema();
|
|
23
|
|
24 if (my @errors = $metaSchema->Validate($metaSchema)) {
|
|
25 failed "Self verification failed", map $_ ? $_->Message : 'unknown', @errors;
|
|
26 }
|
|
27 };
|
|
28
|
|
29 test VerifyCorrectSchema => sub {
|
|
30 my ($this) = @_;
|
|
31 my $metaSchema = IMPL::DOM::Schema->MetaSchema();
|
|
32
|
|
33 my $schema = new IMPL::DOM::Schema;
|
|
34 $schema->appendRange(
|
|
35 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
|
|
36 IMPL::DOM::Schema::NodeSet->new()->appendRange(
|
|
37 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
|
|
38 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
|
|
39 new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange(
|
|
40 IMPL::DOM::Schema::NodeSet->new()->appendRange(
|
|
41 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
|
|
42 new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
|
|
43 )
|
|
44 )
|
|
45 )
|
|
46 )
|
|
47 );
|
|
48
|
|
49 $this->SampleSchema($schema);
|
|
50
|
|
51 my @errors = $metaSchema->Validate($schema);
|
|
52 failed "Failed to validate a wellformed schema", map $_->Message, @errors if @errors;
|
|
53 };
|
|
54
|
|
55 test VerifyWrongSchema => sub {
|
|
56 my $metaSchema = IMPL::DOM::Schema->MetaSchema();
|
|
57
|
|
58 my $schema = new IMPL::DOM::Schema;
|
|
59 $schema->appendRange(
|
|
60 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
|
|
61 new IMPL::DOM::Schema::ComplexType( type => 'someType' ),
|
|
62 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
|
|
63 new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange(
|
|
64 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
|
|
65 new IMPL::DOM::Schema::SimpleNode( name => 'line' )
|
|
66 )
|
|
67 )
|
|
68 );
|
|
69
|
|
70 my @errors = $metaSchema->Validate($schema);
|
|
71 failed "A not wellformed schema validated correctly" unless @errors;
|
|
72 };
|
|
73
|
|
74 test ValidateCorrectData => sub {
|
|
75 my ($this) = @_;
|
|
76
|
|
77 my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange(
|
|
78 IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'),
|
|
79 IMPL::DOM::Node->new(nodeName => 'lastName', nodeValue => 'Smith'),
|
|
80 IMPL::DOM::Node->new(nodeName => 'address')->appendRange(
|
|
81 IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road')
|
|
82 )
|
|
83 );
|
|
84
|
|
85 if (my @errors = $this->SampleSchema->Validate($data)) {
|
|
86 failed "Failed to validate a correct data", map $_->Message , @errors;
|
|
87 }
|
|
88 };
|
|
89
|
|
90 test ValidateWrongData => sub {
|
|
91 my ($this) = @_;
|
|
92
|
|
93 my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange(
|
|
94 IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'),
|
|
95 IMPL::DOM::Node->new(nodeName => 'address')->appendRange(
|
|
96 IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road')
|
|
97 )
|
|
98 );
|
|
99
|
|
100 failed "A wrong data validated corretly" unless $this->SampleSchema->Validate($data);
|
|
101 };
|
|
102
|
|
103
|
|
104 1;
|