]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/regress.pl
c3f5a6958958dc3724ebc9f3aa95dd26ce79e1bd
[bacula/bacula] / gui / bweb / script / regress.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14    This program is Free Software; you can redistribute it and/or
15    modify it under the terms of version three of the GNU Affero General Public
16    License as published by the Free Software Foundation and included
17    in the file LICENSE.
18
19    This program is distributed in the hope that it will be useful, but
20    WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22    General Public License for more details.
23
24    You should have received a copy of the GNU Affero General Public License
25    along with this program; if not, write to the Free Software
26    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27    02110-1301, USA.
28
29    Bacula® is a registered trademark of Kern Sibbald.
30    The licensor of Bacula is the Free Software Foundation Europe
31    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
32    Switzerland, email:ftf@fsfeurope.org.
33
34 =head1 USAGE
35
36     Get it working with a regress environment:
37      * get regress module from SVN
38      * use postgresql or mysql in config
39      * make setup
40      * add catalog = all, !skipped, !saved into Messages Standard (scripts/bacula-dir.conf)
41      * add exit 0 to scripts/cleanup
42      * run bacula-backup-test
43      * uncomment job schedule in bacula-dir.conf
44      * load bweb-(mysql|postgresql).sql
45      * ./bin/bacula start
46      * configure bweb to point to bconsole and the catalog
47
48 =head1 VERSION
49
50     $Id$
51
52 =cut
53
54 use Test::More qw(no_plan);
55 use WWW::Mechanize;
56
57 use Getopt::Long;
58
59 my ($login, $pass, $url, $verbose);
60 GetOptions ("login=s"  => \$login,
61             "passwd=s" => \$pass,
62             "url|u=s"  => \$url,
63             "verbose"  => \$verbose,
64             );
65
66 die "Usage: $0 --url http://.../cgi-bin/bweb/bweb.pl [-l user -p pass]"
67     unless ($url);
68
69 print "Making tests on $url\n";
70 my ($req, $res, $c, $cli, $job_url);
71
72 my $agent = new WWW::Mechanize(autocheck=>1);
73 if ($login) {
74     $agent->credentials($login, $pass);
75 }
76
77 ################################################################
78 # Check bweb libraries
79 ################################################################
80
81 # first, try to load all bweb libraries
82 require_ok('Bweb');
83 require_ok('Bconsole');
84 require_ok('CCircle');
85 require_ok('GBalloon');
86 require_ok('GTime');
87
88 # test first page and check for the last job 
89 $agent->get($url); ok($agent->success, "Get main page"); $c = $agent->content;
90 like($c, qr!</html>!, "Check EOP");
91 ok($c =~ m!(action=job_zoom;jobid=\d+)!, "Get the first JobId");
92 die "Can't get first jobid ($c)" unless $1;
93 $job_url=$1;
94
95 # check missing view
96 ok($agent->follow_link(text_regex=>qr/Missing Jobs/), "Go to Missing Jobs page");
97 $c=$agent->content;
98 like($c, qr/BackupCatalog/, "Check for BackupCatalog job");
99 unlike($c, qr/backup/, "Check for backup job");
100
101 # test job_zoom page
102 # check for
103 #  - job log
104 #  - fileset
105 #  - media view
106 $agent->get("$url?$job_url");
107 ok($agent->success,"Get job zoom"); $c=$agent->content;
108 like($c, qr!</html>!, "Check EOP");
109 like($c, qr!Using Device!, "Check for job log");
110
111 ok($agent->form_name('fileset_view'), "Find form");
112 $agent->click(); $c=$agent->content;
113 ok($agent->success, "Get fileset"); 
114 like($c, qr!</html>!, "Check EOP");
115 ok($c =~ m!<pre>\s*(/[^>]+?)</pre>!s,"Check fileset");
116 print $1 if $verbose;
117 $agent->back(); ok($agent->success,"Return from fileset");
118
119 ok($agent->form_name("rerun"), "Find form");
120 $agent->click(); $c=$agent->content;
121 ok($agent->success, "ReRun job");
122 ok($agent->form_name("form1"), "Find form");
123 ok($c =~ m!<select name='job'>\s*<option value='(.+?)'!,"jobs");
124 ok($agent->field('job', $1), "set field job=1");
125 ok($c =~ m!<select name='client'>\s*<option value='(.+?)'!, "clients");
126 ok($agent->field('client', $1), "set field client=$1");
127 ok($c =~ m!<select name='storage'>\s*<option value='(.+?)'!, "storages");
128 ok($agent->field('storage', $1), "set field storage=$1");
129 ok($c =~ m!<select name='fileset'>\s*<option value='(.+?)'!, "filesets");
130 ok($agent->field('fileset', $1), "set field fileset=1");
131 ok($c =~ m!<select name='pool'>\s*<option value=''></option>\s*<option value='(.+?)'!, "pools");
132 $agent->field('pool', $1);
133 $agent->click_button(value => 'run_job_now');
134 ok($agent->success(), "submit");
135 sleep 2;
136 ok($agent->follow_link(text_regex=>qr/here/i), "follow link");
137 ok($agent->success(), "get job page"); $c=$agent->content;
138 like($c, qr/Using Device/, "Check job log");
139
140 # try to delete this job
141 $agent->get("$url?$job_url");
142 ok($agent->success,"Get job zoom");
143 ok($agent->form_name('delete'), "Find form");
144 $agent->click(); $c=$agent->content;
145 ok($agent->success, "Delete it"); 
146 like($c, qr!deleted from the catalog!, "Check deleted message");
147
148 $agent->get("$url?$job_url");
149 ok($agent->success,"Get job zoom");
150 $c=$agent->content;
151 like($c, qr!An error has occurred!, "Check deleted job");
152
153 # list jobs
154 ok($agent->follow_link(text_regex=>qr/Defined Jobs/), "Go to Defined Jobs page");
155 $c=$agent->content;
156 like($c, qr/BackupCatalog/, "Check for BackupCatalog job");
157
158 ################################################################
159 # client tests
160 ################################################################
161
162 ok($agent->follow_link(text_regex=>qr/Clients/), "Go to Clients page");
163 $c=$agent->content;
164 ok($c =~ m!chkbox.value = '(.+?)';!, "get client name");
165 $cli = $1;
166
167 $agent->get("$url?action=client_status;client=$cli");
168 ok($agent->success(), "submit"); $c=$agent->content;
169 like($c, qr/Terminated Jobs/, "check for client status");
170
171 $agent->get("$url?action=job;client=$cli");
172 ok($agent->success(), "submit"); $c=$agent->content;
173 like($c, qr/'$cli'\).selected = true;/, "list jobs for this client");
174
175 ################################################################
176 # Test location basic functions
177 ################################################################
178
179 my $loc = "loc$$";
180 ok($agent->follow_link(text_regex=>qr/Location/), "Go to Location page");
181 ok($agent->form_number(2), "Find form");
182 $agent->click_button(value => 'location_add');
183 ok($agent->success(), "submit");
184 ok($agent->form_number(2), "Find form");
185 $agent->field("location", $loc);
186 ok($agent->field("cost", 20), "set field cost=20");
187 ok($agent->field("enabled", "yes"), "set field enabled=yes");
188 ok($agent->field("enabled", "no"), "try set field enabled=no");
189 ok($agent->field("enabled", "archived"), "try set field enabled=archived");
190 $agent->click_button(value => 'location_add');
191 ok($agent->success(), "submit"); $c=$agent->content;
192 like($c, qr/$loc/, "Check if location is ok");
193 like($c, qr/inflag2.png/, "Check if enabled is archived");
194
195 $agent->get("$url?location=$loc&action=location_edit");
196 ok($agent->success(), "Try to edit location"); $c=$agent->content;
197 like($c, qr/$loc/, "Check for location");
198 ok($agent->form_number(2), "Find form");
199 $agent->field("cost", 40);
200 $agent->field("enabled", "no");
201 $loc = "new$loc";
202 $agent->field("newlocation", $loc);
203 $agent->click_button(value => 'location_save');
204 ok($agent->success(), "submit to edit location"); $c=$agent->content;
205 like($c, qr/$loc/, "Check if location is ok");
206 like($c, qr/inflag0.png/, "Check if enabled is 'no'");
207 like($c, qr/40/, "Check for cost");
208
209 ################################################################
210 # Test media
211 ################################################################
212
213 ok($agent->follow_link(text_regex=>qr/All Media/), "Go to All Media page");
214 ok($agent->success(), "submit"); $c=$agent->content;
215 ok($c =~ m/chkbox.value = '(.+?)'/, "get first media");
216 my $vol = $1;
217
218 $agent->get("$url?media=$vol;action=update_media");
219 ok($agent->success(), "submit"); $c=$agent->content;
220 like($c, qr/$vol/, "Check if volume is ok");
221
222 ################################################################
223 # Test group basic functions
224 ################################################################
225
226 $agent->get("$url?action=client;notingroup=yes");
227 ok($agent->success(), "submit"); $c=$agent->content;
228 like($c, qr/$cli/, "check client=$cli is groupless");
229
230 # create a group
231 my $grp = "test$$";
232 ok($agent->follow_link(text_regex=>qr/Groups/), "Go to Groups page");
233 ok($agent->success(), "submit"); $c=$agent->content;
234 unlike($c, qr/error/i, "Check for group installation");
235 ok($agent->form_number(2), "Find form");
236 $agent->click_button(value => 'groups_edit');
237 ok($agent->success(), "submit action=groups_edit");
238 ok($agent->form_number(2), "Find form to create a group");
239 $agent->field("newgroup", $grp);
240 $agent->click_button(value => 'groups_save');
241 ok($agent->success(), "submit action=groups_save");
242 $c=$agent->content; 
243 like($c, qr/$grp/, "Check if group have been created");
244
245 # rename group (client is loss because it was set by javascript)
246 $agent->get("$url?client_group=$grp;action=groups_edit");
247 ok($agent->success(), "submit action=groups_edit"); $c=$agent->content;
248 like($c, qr/$grp/, "Check if group is present to rename it");
249 ok($agent->form_number(2), "Find form");
250 $grp = "newtest$$";
251 $agent->field("newgroup", $grp);
252 $agent->field("client", $cli);
253 $agent->click_button(value => 'groups_save');
254 ok($agent->success(), "submit"); $c=$agent->content;
255 like($c, qr/'$grp'/, "Check if newgroup is present");
256
257 # check if group is ok
258 $agent->get("$url?client_group=$grp;action=client");
259 ok($agent->success(), "submit"); $c=$agent->content;
260 like($c, qr/'$cli'/, "Check if client is present in newgrp");
261
262 $agent->get("$url?action=client;notingroup=yes");
263 ok($agent->success(), "check if client=$cli is already 'not in group'");
264 $c=$agent->content;
265 unlike($c, qr/$cli/, "check client=$cli");
266
267 $agent->get("$url?client_group=other$grp;action=groups_edit");
268 ok($agent->success(), "create an empty other$grp"); $c=$agent->content;
269 like($c, qr/'other$grp'/, "check if other$grp was created");
270
271 # view job by group
272 ok($agent->follow_link(text_regex=>qr/Jobs by group/), "Go to Job by group page");
273 ok($agent->success(), "Get it"); $c=$agent->content;
274 like($c, qr/"$grp"/, "check if $grp is here");
275
276 # view job overview
277 ok($agent->follow_link(text_regex=>qr/Jobs overview/), "Go to Job overview");
278 ok($agent->success(), "Get it"); $c=$agent->content;
279 like($c, qr/"$grp"/, "check if $grp is here");
280
281 # get group stats
282 ok($agent->follow_link(url_regex=>qr/action=group_stats/), "Go to groups stats");
283 ok($agent->success(), "Get it"); $c=$agent->content;
284 like($c, qr/"$grp"/, "check if $grp is here");
285
286 # view next jobs
287 ok($agent->follow_link(text_regex=>qr/Next Jobs/), "Go to Next jobs");
288 ok($agent->success(), "Get it"); $c=$agent->content;
289 like($c, qr/'BackupCatalog'/, "check if BackupCatalog is here");
290
291 # Add media
292 ok($agent->follow_link(text_regex=>qr/Add Media/), "Go to Add Media");
293 ok($agent->success(), "Get it");
294 ok($agent->form_number(2), "Find form");
295 $agent->field('pool', 'Scratch');
296 $agent->field('storage', 'File');
297 $agent->field('nb', '3');
298 $agent->field('offset', '1');
299 $agent->field('media', "Vol$$");
300 $agent->click_button(value => 'add_media');
301 ok($agent->success(), "Create them"); $c=$agent->content;
302 like($c, qr/Vol${$}0001/, "Check if media are there");
303
304 # view pools
305 ok($agent->follow_link(text_regex=>qr/Pools/), "Go to Pool");
306 ok($agent->success(), "Get it"); $c=$agent->content;
307 like($c, qr/"Default"/, "check if Default pool is here");
308 like($c, qr/"Scratch"/, "check if Scratch pool is here");
309
310 ################################################################
311 # other checks and cleanup
312 ################################################################
313
314 # cleanup groups
315 $agent->get("$url?client_group=$grp;action=groups_del");
316 ok($agent->success(), "submit"); $c=$agent->content;
317 unlike($c, qr/'$grp'/, "Check if group was deleted");
318
319 $agent->get("$url?client_group=other$grp;action=groups_del");
320 ok($agent->success(), "submit"); $c=$agent->content;
321 unlike($c, qr/'other$grp'/, "Check if group was deleted");
322
323 # cleanup location
324 $agent->get("$url?location=$loc;action=location_del");
325 ok($agent->success(), "submit"); $c=$agent->content;
326 unlike($c, qr/$loc/, "Check if location was deleted");
327
328 exit 0;
329
330
331 __END__
332