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