annotate _test/Test/SQL/Traits.pm @ 184:7525ea9a071a

IMPL::Web::View::TTLoader tests
author sergey
date Thu, 29 Mar 2012 01:54:20 +0400
parents d1676be8afcc
children 4d0e1962161c
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
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
48 my $column = $table->GetColumn('id') or failed "Column not found";
165
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
49
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
50 assert( $column->name eq 'id');
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
51 assert( $column->type->SameValue(Integer()) );
165
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
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
61 $column = $table->GetColumn('name');
165
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');
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
65 assert($column->type->SameValue(Varchar(255)));
165
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
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
84 assert( my $column = $table->GetColumn('id') );
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
85 assert($column->type->SameValue(Varchar(64)));
165
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
86 assert(not $column->isNullable);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
87
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
88 assert( $column = $table->GetColumn('role') );
165
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
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 168
diff changeset
100 1;