comparison _test/Test/DOM/Schema.pm @ 24:7f00786f8210

Первая рабочая реазизация схемы и навигаторов
author Sergey
date Mon, 05 Oct 2009 00:48:49 +0400
parents 1ca530e5c9c5
children 6d33f75c6e1f
comparison
equal deleted inserted replaced
23:716b287d4795 24:7f00786f8210
1 package Test::DOM::Schema; 1 package Test::DOM::Schema;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 4
5 use base qw(IMPL::Test::Unit); 5 use base qw(IMPL::Test::Unit);
6 use IMPL::Test qw(test failed); 6 use IMPL::Test qw(test failed shared);
7 use IMPL::Class::Property;
7 8
8 __PACKAGE__->PassThroughArgs; 9 __PACKAGE__->PassThroughArgs;
9 10
10 require IMPL::DOM::Schema; 11 require IMPL::DOM::Schema;
12
13 BEGIN {
14 shared public property SampleSchema => prop_all;
15 }
11 16
12 test GetMetaSchema => sub { 17 test GetMetaSchema => sub {
13 my $metaSchema = IMPL::DOM::Schema->MetaSchema(); 18 my $metaSchema = IMPL::DOM::Schema->MetaSchema();
14 }; 19 };
15 20
19 if (my @errors = $metaSchema->Validate($metaSchema)) { 24 if (my @errors = $metaSchema->Validate($metaSchema)) {
20 failed "Self verification failed", map $_ ? $_->Message : 'unknown', @errors; 25 failed "Self verification failed", map $_ ? $_->Message : 'unknown', @errors;
21 } 26 }
22 }; 27 };
23 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
24 1; 104 1;