annotate _test/Test/DOM/Schema.pm @ 49:16ada169ca75

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