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