annotate _test/Test/SQL/Traits.pm @ 165:76515373dac0

Added Class::Template, Rewritten SQL::Schema 'use parent' directive instead of 'use base'
author wizard
date Sat, 23 Apr 2011 23:06:48 +0400
parents
children 1f7a6d762394
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
1 package Test::SQL::Traits;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
2 use parent qw(IMPL::Test::Unit);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
3
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
4 __PACKAGE__->PassThroughArgs;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
5
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
6 use IMPL::lang;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
7 use IMPL::Class::Property;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
8 use IMPL::Test qw(test failed shared assert);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
9
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
10 use IMPL::SQL::Schema;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
11 use IMPL::SQL::Schema::Traits;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
12 use IMPL::SQL::Types qw(Integer Varchar DateTime);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
13
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
14 BEGIN {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
15 shared public property schema => prop_all;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
16 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
17
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
18 sub StartUnit {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
19 return {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
20 schema => new IMPL::SQL::Schema( name => 'testTraits', version => 1 )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
21 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
22 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
23
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
24 test CreateTable => sub {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
25 my ($this) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
26
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
27 my $table = $this->schema->AddTable(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
28 new IMPL::SQL::Schema::Traits::Table(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
29 'user'
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
30 )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
31 ) or failed "Failed to create table";
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
32
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
33 $this->schema->GetTable('user') or failed "Can't get a created table";
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
34
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
35 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
36
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
37 test InsertColumn => sub {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
38 my ($this) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
39
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
40 my $table = $this->schema->GetTable('user');
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
41
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
42 $table->InsertColumn(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
43 new IMPL::SQL::Schema::Traits::Column(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
44 id => Integer, tag => { auto_increment => 1 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
45 )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
46 );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
47
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
48 my $column = $table->Column('id') or failed "Column not found";
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
49
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
50 assert( $column->name eq 'id');
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
51 assert( $column->type->isSame(Integer()) );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
52 assert( not $column->isNullable );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
53 assert( $column->tag->{auto_increment} );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
54
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
55 $table->InsertColumn(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
56 new IMPL::SQL::Schema::Traits::Column(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
57 name => Varchar(255), isNullable => 1
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
58 )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
59 );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
60
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
61 $column = $table->Column('name');
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
62
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
63 assert($column);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
64 assert($column->name eq 'name');
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
65 assert($column->type->isSame(Varchar(255)));
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
66 assert($column->isNullable);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
67 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
68
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
69 test CreateTableWithColumns => sub {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
70 my ($this) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
71
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
72 my $table = $this->schema->AddTable(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
73 new IMPL::SQL::Schema::Traits::Table(
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
74 session => [
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
75 new IMPL::SQL::Schema::Traits::Column( id => Varchar(64)),
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
76 new IMPL::SQL::Schema::Traits::Column( expires => DateTime ),
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
77 new IMPL::SQL::Schema::Traits::Column( role => Varchar(64), defaultValue => 'user' )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
78 ]
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
79 )
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
80 ) or failed "Failed to create table";
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
81
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
82 assert( $table->ColumnsCount == 3 );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
83
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
84 assert( my $column = $table->Column('id') );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
85 assert($column->type->isSame(Varchar(64)));
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
86 assert(not $column->isNullable);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
87
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
88 assert( $column = $table->Column('role') );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
89 assert( $column->defaultValue eq 'user' );
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
90 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
91
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
92 sub FinishUnit {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
93 my ($self,$session) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
94
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
95 $self->supercall::FinishUnit();
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
96
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
97 $session->{schema}->Dispose();
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
98 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
99
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
100 1;