annotate _test/Test/DOM/Builder.pm @ 44:32d2350fccf9

ORM *Minor fixes *Working tarnsform to sql *Fixes to the sql traits
author Sergey
date Mon, 11 Jan 2010 01:42:00 +0300
parents c2e7f7c96bcd
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
1 package Test::DOM::Builder;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
2 use strict;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
3 use warnings;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
4
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
5 use base qw(IMPL::Test::Unit);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
6 __PACKAGE__->PassThroughArgs;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
7
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
9 use IMPL::Test qw(test failed shared);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
10
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
11 require IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
12 require IMPL::DOM::Navigator::Builder;
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
13 require IMPL::DOM::Navigator::SimpleBuilder;
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
14 require IMPL::DOM::Document;
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
15 require IMPL::DOM::XMLReader;
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
16
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
17 BEGIN {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
18 public property schemaDoc => prop_all;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
19 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
20
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
21 sub CTOR {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
22 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
23
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
24 my $schema = new IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
25 $schema->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
26 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
27 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
28 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
29 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
30 new IMPL::DOM::Schema::ComplexNode( name => 'address', maxOccur => 'unbounded' )->appendRange(
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
31 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
32 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
33 new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
34 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
35 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
36 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
37 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
38 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
39
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
40 $this->schemaDoc( $schema );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
41 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
42
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
43 test CreateBuilder => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
44 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
45
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
46 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
47 new IMPL::DOM::Document(nodeName => 'personInfo'),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
48 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
49 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
50 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
51
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
52 test BuildDocument => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
53 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
54
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
55 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
56 'IMPL::DOM::Document',
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
57 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
58 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
59
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
60 $builder->NavigateCreate('personInfo', version => '1');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
61 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
62 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
63 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
64 $builder->Back();
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
65 for(1..10) {
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
66 $builder->NavigateCreate('address', local => 1);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
67 $builder->NavigateCreate('street')->nodeValue('Hellroad');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
68 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
69 $builder->NavigateCreate('line')->nodeValue($_);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
70 $builder->Back();
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
71 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
72 }
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
73 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
74
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
75 my @errors = $this->schemaDoc->Validate($builder->Document);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
76 failed ("The built document doesn't pass a validation",@errors) if @errors;
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
77
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
78 return 1;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
79 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
80
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
81 test BuildSimpleDocument => sub {
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
82 my ($this) = @_;
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
83
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
84 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
85
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
86 $builder->NavigateCreate('personInfo', version => '1');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
87 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
88 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
89 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
90 $builder->Back();
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
91 for(1..10) {
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
92 $builder->NavigateCreate('address', local => 1);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
93 $builder->NavigateCreate('street')->nodeValue('Hellroad');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
94 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
95 $builder->NavigateCreate('line')->nodeValue($_);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
96 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
97 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
98 }
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
99 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
100
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
101 my @errors = $this->schemaDoc->Validate($builder->Document);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
102 failed ("The built document doesn't pass a validation",@errors) if @errors;
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
103
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
104 return 1;
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
105 };
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
106
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
107 test BuildDocumentFromXml => sub {
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
108 my ($this) = @_;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
109
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
110 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
111 my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
112
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
113 $reader->ParseFile("Resources/person_info.xml");
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
114
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
115 my $doc = $builder->Document() or failed("No document was constrcuted");
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
116
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
117 my @errors = $this->schemaDoc->Validate($doc);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
118 failed("The document isn't correct", @errors) if @errors;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
119 my $name = ($doc->selectNodes("firstName"))[0]->nodeValue;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
120 failed("The firstName has a wrong value", "Expected: Norman", "Got: $name") unless $name eq "Norman";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
121
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
122 };
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
123
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
124
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
125 1;