annotate Lib/IMPL/Test/Unit.pm @ 321:3dc9260017ad

Added JSON support for the request action
author cin
date Mon, 20 May 2013 01:14:27 +0400
parents 4d0e1962161c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
1 package IMPL::Test::Unit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
4
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 159
diff changeset
5 use parent qw(IMPL::Object);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
8 use Time::HiRes qw(gettimeofday tv_interval);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
10 use Error qw(:try);
83
74bae30eb25e (no commit message)
wizard
parents: 49
diff changeset
11 use Carp qw(carp);
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
12 use File::Spec();
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
13 use IMPL::Test::Result();
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
14 use IMPL::Test::FailException();
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
15 use IMPL::Exception();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
17 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
18 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
19 public property Code => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
20 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
21
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
22 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
23 my ($this,$info) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
25 die new IMPL::InvalidArgumentException("TestInfo should be supplied as an argument") unless $info;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
26
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
27 $this->Name($info->Name || 'Annon');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
28 $this->Code($info->Code)or die new IMPL::InvalidOperationException("Can't create test without entry point");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
29 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
31 sub UnitName {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
32 my ($self) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
33 $self->toString;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
34 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
36 sub Cleanup {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
37 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
38
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 83
diff changeset
39 $session->{$_} = $this->$_() foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData',undef,1);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
41 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
42 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
43
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
44 sub StartUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
45 my $class = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
46
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
47 return {};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
48 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
50 sub InitTest {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
51 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
52
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 83
diff changeset
53 $this->$_($session->{$_}) foreach map $_->DataList, $this->get_meta('IMPL::Test::Unit::SharedData',undef,1);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
54 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
55
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
56 sub FinishUnit {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
57 my ($class,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
58
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
59 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
60 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
62 sub List {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
63 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
64
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
65 return $self->get_meta('IMPL::Test::Unit::TestInfo',undef,1); # deep search with no criteria
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
66 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
68 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
69 my ($this,$session) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
71 my $t = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
72 return try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
73 $this->InitTest($session);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
74 my $code = $this->Code;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
76
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
77 my $t0 = [gettimeofday];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
78 my $elapsed;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
80 try {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
81 $this->$code();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
82 $elapsed = tv_interval ( $t0 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
83 } finally {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
84 # we need to call Cleanup anyway
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
85 $this->Cleanup($session);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
86 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
87
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
88 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
89 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
90 State => IMPL::Test::Result::SUCCESS,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
91 TimeExclusive => $elapsed,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
92 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
93 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
94 } catch IMPL::Test::FailException with {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
95 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
96 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
97 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
98 State => IMPL::Test::Result::FAIL,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
99 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
100 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
101 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
102 } otherwise {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
103 my $e = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
104 return new IMPL::Test::Result(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
105 Name => $this->Name,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
106 State => IMPL::Test::Result::ERROR,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
107 Exception => $e,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
108 TimeInclusive => tv_interval ( $t )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
109 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
110 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
111 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
112
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
113 sub GetResourceFile {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
114 my ($this,@path) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
115
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
116 my ($cwd) = map m/(.*)/, File::Spec->rel2abs(File::Spec->curdir());
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
117 return File::Spec->catfile($cwd,@path);
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
118 }
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
119
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
120 sub GetResourceDir {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
121 my ($this,@path) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
122
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
123 my ($cwd) = map m/(.*)/, File::Spec->rel2abs(File::Spec->curdir());
4d0e1962161c Replaced tabs with spaces
cin
parents: 184
diff changeset
124 return File::Spec->catdir($cwd,@path);
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
125 }
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents: 166
diff changeset
126
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
127 package IMPL::Test::Unit::TestInfo;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 159
diff changeset
128 use parent qw(IMPL::Object::Meta);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
129 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
130
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
131 require IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
132
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
133 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
134 public property Name => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
135 public property Code => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
136 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
137
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
138 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
139 my ($this,$name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
140
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
141 $this->Name($name);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
142 $this->Code($code) or die new IMPL::InvalidArgumentException("The Code is a required parameter");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
143 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
144
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
145 package IMPL::Test::Unit::SharedData;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 159
diff changeset
146 use parent qw(IMPL::Object::Meta);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
147 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
148
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
149 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
150 public property DataList => prop_all | prop_list;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
151 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
152
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
153 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
154 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
155
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
156 $this->DataList(\@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
157 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 14
diff changeset
158 1;