annotate _test/Test/SQL/Traits.pm @ 418:3f38dabaf5cc ref20150831

sync
author cin
date Mon, 28 Dec 2015 15:11:35 +0300
parents 4d0e1962161c
children
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
15 shared public property schema => prop_all;
165
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
19 return {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
20 schema => new IMPL::SQL::Schema( name => 'testTraits', version => 1 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
21 };
165
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
25 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
26
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 my $table = $this->schema->AddTable(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28 new IMPL::SQL::Schema::Traits::Table(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
29 'user'
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
30 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
31 ) or failed "Failed to create table";
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
33 $this->schema->GetTable('user') or failed "Can't get a created table";
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34
165
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
38 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 my $table = $this->schema->GetTable('user');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 $table->InsertColumn(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
43 new IMPL::SQL::Schema::Traits::Column(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 id => Integer, tag => { auto_increment => 1 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
48 my $column = $table->GetColumn('id') or failed "Column not found";
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 assert( $column->name eq 'id');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51 assert( $column->type->SameValue(Integer()) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
52 assert( not $column->isNullable );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
53 assert( $column->tag->{auto_increment} );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
54
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
55 $table->InsertColumn(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
56 new IMPL::SQL::Schema::Traits::Column(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
57 name => Varchar(255), isNullable => 1
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
58 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
59 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
60
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
61 $column = $table->GetColumn('name');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
62
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
63 assert($column);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
64 assert($column->name eq 'name');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
65 assert($column->type->SameValue(Varchar(255)));
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
66 assert($column->isNullable);
165
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
70 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
71
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72 my $table = $this->schema->AddTable(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 new IMPL::SQL::Schema::Traits::Table(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74 session => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
75 new IMPL::SQL::Schema::Traits::Column( id => Varchar(64)),
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
76 new IMPL::SQL::Schema::Traits::Column( expires => DateTime ),
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
77 new IMPL::SQL::Schema::Traits::Column( role => Varchar(64), defaultValue => 'user' )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
78 ]
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
79 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
80 ) or failed "Failed to create table";
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
81
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
82 assert( $table->ColumnsCount == 3 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
83
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
84 assert( my $column = $table->GetColumn('id') );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
85 assert($column->type->SameValue(Varchar(64)));
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
86 assert(not $column->isNullable);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
87
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
88 assert( $column = $table->GetColumn('role') );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
89 assert( $column->defaultValue eq 'user' );
165
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
93 my ($self,$session) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
94
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
95 $self->supercall::FinishUnit();
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
96
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
97 $session->{schema}->Dispose();
165
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;