annotate _test/Test/SQL/Schema.pm @ 35:f25d021780b3

DOM::Navigator::Builder working version
author Sergey
date Tue, 17 Nov 2009 17:46:24 +0300
parents 0004faa276dc
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
Sergey
parents:
diff changeset
1 package Test::SQL::Schema;
Sergey
parents:
diff changeset
2 use strict;
Sergey
parents:
diff changeset
3 use warnings;
Sergey
parents:
diff changeset
4
Sergey
parents:
diff changeset
5 use base qw(IMPL::Test::Unit);
Sergey
parents:
diff changeset
6 __PACKAGE__->PassThroughArgs;
Sergey
parents:
diff changeset
7
33
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
8 use IMPL::Class::Property;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
9 use IMPL::Class::Property::Direct;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
10
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
11 use IMPL::Test qw(test shared failed);
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
12
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
13 BEGIN {
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
14 shared public property schemaDB => prop_all;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
15 }
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
16
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
17 require IMPL::SQL::Schema;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
18 require IMPL::SQL::Schema::Constraint::Unique;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
19
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
20 use IMPL::SQL::Types qw(Integer Varchar);
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
21
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
22 test CreateSchema => sub {
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
23 my ($this) = @_;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
24
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
25 my $schema = new IMPL::SQL::Schema(Name => 'dbTest', Version => 1) or failed "Failed to create schema";
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
26
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
27 failed "Failed to set a schema name" unless $schema->Name eq 'dbTest';
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
28 failed "Failed to set a schema version" unless $schema->Version == 1;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
29
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
30 $this->schemaDB($schema);
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
31 };
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
32
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
33 test AddTable => sub {
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
34 my ($this) = @_;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
35
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
36 my $table = $this->schemaDB->AddTable({Name => 'User'}) or failed "Failed to add a table to the schema";
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
37 $table->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
38 Name => 'Id',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
39 Type => Integer
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
40 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
41 $table->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
42 Name => 'Login',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
43 Type => Varchar(255)
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
44 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
45 $table->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
46 Name => 'DisplayName',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
47 CanBeNull => 1,
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
48 Type => Varchar(255)
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
49 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
50 $table->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
51 Name => 'RoleId',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
52 CanBeNull => 1,
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
53 Type => Integer
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
54 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
55
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
56 $table->SetPrimaryKey('Id');
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
57
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
58 my $colCount = @{$table->Columns};
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
59
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
60 failed "Failed to add columns", "Expected: 4", "Got: ".$colCount unless $colCount == 4;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
61 failed "Failed to set a primary key" unless $table->PrimaryKey;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
62
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
63 my $table2 = $this->schemaDB->AddTable({Name => 'Role'});
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
64 $table2->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
65 Name => 'Id',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
66 Type => Integer
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
67 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
68 $table2->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
69 Name => 'Description',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
70 Type => Varchar(255)
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
71 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
72 $table2->InsertColumn({
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
73 Name => 'ObsoleteId',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
74 Type => Integer
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
75 });
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
76
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
77 $table2->SetPrimaryKey('Id');
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
78
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
79 $table->LinkTo($table2,'RoleId');
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
80 };
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
81
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
82 test Constraints => sub {
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
83 my ($this) = @_;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
84
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
85 my $table = $this->schemaDB->Tables->{Role} or failed "Failed to get a table";
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
86
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
87 my $constraint = $table->AddConstraint(
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
88 new IMPL::SQL::Schema::Constraint::Unique(
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
89 Name => 'Role_ObsoleteId_Uniq',
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
90 Table => $table,
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
91 Columns => ['ObsoleteId']
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
92 )
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
93 ) or failed "Failed to add constraint";
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
94
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
95 failed "Failed to retrieve a constraint" unless ($table->GetColumnConstraints('ObsoleteId'))[0] == $constraint;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
96
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
97 $table->RemoveColumn('ObsoleteId',1);
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
98
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
99 failed "A constraint remains alive after column deletion" unless $constraint->isDisposed;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
100
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
101 };
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
102
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
103 test Dispose => sub {
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
104 my ($this) = @_;
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
105
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
106 $this->schemaDB->Dispose();
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
107 };
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
108
0004faa276dc small fixes, some new tests
Sergey
parents: 32
diff changeset
109
32
Sergey
parents:
diff changeset
110 1;