]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/regress.pl
ebl cleanup
[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      * charger 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 # test job_zoom page
96 # check for
97 #  - job log
98 #  - fileset
99 #  - media view
100 $agent->get("$url?$job_url");
101 ok($agent->success,"Get job zoom"); $c=$agent->content;
102 like($c, qr!</html>!, "Check EOP");
103 like($c, qr!Using Device!, "Check for job log");
104
105 ok($agent->form_name('fileset_view'), "Find form");
106 $agent->click(); $c=$agent->content;
107 ok($agent->success, "Get fileset"); 
108 like($c, qr!</html>!, "Check EOP");
109 ok($c =~ m!<pre>\s*(/[^>]+?)</pre>!s,"Check fileset");
110 print $1 if $verbose;
111 $agent->back(); ok($agent->success,"Return from fileset");
112
113 ok($agent->form_name("rerun"), "Find form");
114 $agent->click(); $c=$agent->content;
115 ok($agent->success, "ReRun job");
116 ok($agent->form_name("form1"), "Find form");
117 ok($c =~ m!<select name='job'>\s*<option value='(.+?)'!,"jobs");
118 ok($agent->field('job', $1), "set field job=1");
119 ok($c =~ m!<select name='client'>\s*<option value='(.+?)'!, "clients");
120 ok($agent->field('client', $1), "set field client=$1");
121 ok($c =~ m!<select name='storage'>\s*<option value='(.+?)'!, "storages");
122 ok($agent->field('storage', $1), "set field storage=$1");
123 ok($c =~ m!<select name='fileset'>\s*<option value='(.+?)'!, "filesets");
124 ok($agent->field('fileset', $1), "set field fileset=1");
125 ok($c =~ m!<select name='pool'>\s*<option value=''></option>\s*<option value='(.+?)'!, "pools");
126 $agent->field('pool', $1);
127 $agent->click_button(value => 'run_job_now');
128 ok($agent->success(), "submit");
129 sleep 2;
130 ok($agent->follow_link(text_regex=>qr/here/i), "follow link");
131 ok($agent->success(), "get job page"); $c=$agent->content;
132 like($c, qr/Using Device/, "Check job log");
133
134 # try to delete this job
135 $agent->get("$url?$job_url");
136 ok($agent->success,"Get job zoom");
137 ok($agent->form_name('delete'), "Find form");
138 $agent->click(); $c=$agent->content;
139 ok($agent->success, "Delete it"); 
140 like($c, qr!deleted!, "Check deleted message");
141
142 $agent->get("$url?$job_url");
143 ok($agent->success,"Get job zoom");
144 $c=$agent->content;
145 like($c, qr!An error has occurred!, "Check deleted job");
146
147 # list jobs
148 ok($agent->follow_link(text_regex=>qr/Defined Jobs/), "Go to Defined Jobs page");
149 $c=$agent->content;
150 like($c, qr/BackupCatalog/, "Check for BackupCatalog job");
151
152 ################################################################
153 # client tests
154 ################################################################
155
156 ok($agent->follow_link(text_regex=>qr/Clients/), "Go to Clients page");
157 $c=$agent->content;
158 ok($c =~ m!chkbox.value = '(.+?)';!, "get client name");
159 $cli = $1;
160
161 $agent->get("$url?action=client_status;client=$cli");
162 ok($agent->success(), "submit"); $c=$agent->content;
163 like($c, qr/Terminated Jobs/, "check for client status");
164
165 $agent->get("$url?action=job;client=$cli");
166 ok($agent->success(), "submit"); $c=$agent->content;
167 like($c, qr/'$cli'\).selected = true;/, "list jobs for this client");
168
169 ################################################################
170 # Test location basic functions
171 ################################################################
172
173 my $loc = "loc$$";
174 ok($agent->follow_link(text_regex=>qr/Location/), "Go to Location page");
175 ok($agent->form_number(2), "Find form");
176 $agent->click_button(value => 'location_add');
177 ok($agent->success(), "submit");
178 ok($agent->form_number(2), "Find form");
179 $agent->field("location", $loc);
180 ok($agent->field("cost", 20), "set field cost=20");
181 ok($agent->field("enabled", "yes"), "set field enabled=yes");
182 ok($agent->field("enabled", "no"), "try set field enabled=no");
183 ok($agent->field("enabled", "archived"), "try set field enabled=archived");
184 $agent->click_button(value => 'location_add');
185 ok($agent->success(), "submit"); $c=$agent->content;
186 like($c, qr/$loc/, "Check if location is ok");
187 like($c, qr/inflag2.png/, "Check if enabled is archived");
188
189 $agent->get("$url?location=$loc&action=location_edit");
190 ok($agent->success(), "Try to edit location"); $c=$agent->content;
191 like($c, qr/$loc/, "Check for location");
192 ok($agent->form_number(2), "Find form");
193 $agent->field("cost", 40);
194 $agent->field("enabled", "no");
195 $loc = "new$loc";
196 $agent->field("newlocation", $loc);
197 $agent->click_button(value => 'location_save');
198 ok($agent->success(), "submit to edit location"); $c=$agent->content;
199 like($c, qr/$loc/, "Check if location is ok");
200 like($c, qr/inflag0.png/, "Check if enabled is 'no'");
201 like($c, qr/40/, "Check for cost");
202
203 ################################################################
204 # Test media
205 ################################################################
206
207 ok($agent->follow_link(text_regex=>qr/All Media/), "Go to All Media page");
208 ok($agent->success(), "submit"); $c=$agent->content;
209 ok($c =~ m/chkbox.value = '(.+?)'/, "get first media");
210 my $vol = $1;
211
212 $agent->get("$url?media=$vol;action=update_media");
213 ok($agent->success(), "submit"); $c=$agent->content;
214 like($c, qr/$vol/, "Check if volume is ok");
215
216 ################################################################
217 # Test group basic functions
218 ################################################################
219
220 $agent->get("$url?action=client;notingroup=yes");
221 ok($agent->success(), "submit"); $c=$agent->content;
222 like($c, qr/$cli/, "check client=$cli is groupless");
223
224 # create a group
225 my $grp = "test$$";
226 ok($agent->follow_link(text_regex=>qr/Groups/), "Go to Groups page");
227 ok($agent->success(), "submit"); $c=$agent->content;
228 unlike($c, qr/error/i, "Check for group installation");
229 ok($agent->form_number(2), "Find form");
230 $agent->click_button(value => 'groups_edit');
231 ok($agent->success(), "submit action=groups_edit");
232 ok($agent->form_number(2), "Find form to create a group");
233 $agent->field("newgroup", $grp);
234 $agent->click_button(value => 'groups_save');
235 ok($agent->success(), "submit action=groups_save");
236 $c=$agent->content; 
237 like($c, qr/$grp/, "Check if group have been created");
238
239 # rename group (client is loss because it was set by javascript)
240 $agent->get("$url?client_group=$grp;action=groups_edit");
241 ok($agent->success(), "submit action=groups_edit"); $c=$agent->content;
242 like($c, qr/$grp/, "Check if group is present to rename it");
243 ok($agent->form_number(2), "Find form");
244 $grp = "newtest$$";
245 $agent->field("newgroup", $grp);
246 $agent->field("client", $cli);
247 $agent->click_button(value => 'groups_save');
248 ok($agent->success(), "submit"); $c=$agent->content;
249 like($c, qr/'$grp'/, "Check if newgroup is present");
250
251 # check if group is ok
252 $agent->get("$url?client_group=$grp;action=client");
253 ok($agent->success(), "submit"); $c=$agent->content;
254 like($c, qr/'$cli'/, "Check if client is present in newgrp");
255
256 $agent->get("$url?action=client;notingroup=yes");
257 ok($agent->success(), "check if client=$cli is already 'not in group'");
258 $c=$agent->content;
259 unlike($c, qr/$cli/, "check client=$cli");
260
261 $agent->get("$url?client_group=other$grp;action=groups_edit");
262 ok($agent->success(), "create an empty other$grp"); $c=$agent->content;
263 like($c, qr/'other$grp'/, "check if other$grp was created");
264
265 # view job by group
266 ok($agent->follow_link(text_regex=>qr/Jobs by group/), "Go to Job by group page");
267 ok($agent->success(), "Get it"); $c=$agent->content;
268 like($c, qr/"$grp"/, "check if $grp is here");
269
270 # view job overview
271 ok($agent->follow_link(text_regex=>qr/Jobs overview/), "Go to Job overview");
272 ok($agent->success(), "Get it"); $c=$agent->content;
273 like($c, qr/"$grp"/, "check if $grp is here");
274
275 # view next jobs
276 ok($agent->follow_link(text_regex=>qr/Next Jobs/), "Go to Next jobs");
277 ok($agent->success(), "Get it"); $c=$agent->content;
278 like($c, qr/'BackupCatalog'/, "check if BackupCatalog is here");
279
280 # Add media
281 ok($agent->follow_link(text_regex=>qr/Add Media/), "Go to Add Media");
282 ok($agent->success(), "Get it");
283 ok($agent->form_number(2), "Find form");
284 $agent->field('pool', 'Scratch');
285 $agent->field('storage', 'File');
286 $agent->field('nb', '3');
287 $agent->field('offset', '1');
288 $agent->field('media', "Vol$$");
289 $agent->click_button(value => 'add_media');
290 ok($agent->success(), "Create them"); $c=$agent->content;
291 like($c, qr/Vol${$}0001/, "Check if media are there");
292
293 # view pools
294 ok($agent->follow_link(text_regex=>qr/Pools/), "Go to Pool");
295 ok($agent->success(), "Get it"); $c=$agent->content;
296 like($c, qr/"Default"/, "check if Default pool is here");
297 like($c, qr/"Scratch"/, "check if Scratch pool is here");
298
299 ################################################################
300 # other checks and cleanup
301 ################################################################
302
303 # cleanup groups
304 $agent->get("$url?client_group=$grp;action=groups_del");
305 ok($agent->success(), "submit"); $c=$agent->content;
306 unlike($c, qr/'$grp'/, "Check if group was deleted");
307
308 $agent->get("$url?client_group=other$grp;action=groups_del");
309 ok($agent->success(), "submit"); $c=$agent->content;
310 unlike($c, qr/'other$grp'/, "Check if group was deleted");
311
312 # cleanup location
313 $agent->get("$url?location=$loc;action=location_del");
314 ok($agent->success(), "submit"); $c=$agent->content;
315 unlike($c, qr/$loc/, "Check if location was deleted");
316
317 exit 0;
318
319
320 __END__
321