File: 02-Test_Cases.t

package info (click to toggle)
libwebinject-perl 1.86-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 428 kB
  • ctags: 197
  • sloc: perl: 4,101; xml: 257; makefile: 7
file content (206 lines) | stat: -rw-r--r-- 8,021 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env perl

##################################################

use strict;
use Test::More;
use Data::Dumper;
use FindBin qw($Bin);
use lib 't';


if($ENV{TEST_AUTHOR}) {
    eval "use HTTP::Server::Simple::CGI";
    if($@) {
        plan skip_all => 'HTTP::Server::Simple::CGI required';
    }
    else{
        plan tests => 50;
    }
}
else{
    plan skip_all => 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
}


use_ok('Webinject');

my $webinject = Webinject->new();
isa_ok($webinject, "Webinject", 'Object is a Webinject');

require TestWebServer;
TestWebServer->start_webserver();

##################################################
# start our test cases
test_case_01();
test_case_02();
test_case_03_1();
test_case_03_2();
test_case_03_3();
test_case_04();
test_case_05();
test_case_06();
test_case_07();
test_case_08();
test_case_09();



##################################################
# SUBs
##################################################

##################################################
# Test File 01
sub test_case_01 {
    @ARGV = ($Bin."/data/01-response_codes.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '01-response_codes.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 1, '01-response_codes.xml - fail count');
    is($rc, 1, '01-response_codes.xml - return code');
}

##################################################
# Test File 02
sub test_case_02 {
    @ARGV = ($Bin."/data/02-string_verification.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 9, '02-string_verification.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '02-string_verification.xml - fail count');
    is($rc, 0, '02-string_verification - return code');
}

##################################################
# Test File 03 - 1
sub test_case_03_1 {
    @ARGV = ($Bin."/data/03-parse_response.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 3, '03-parse_response.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '03-parse_response.xml - fail count');
    is($rc, 0, '03-parse_response.xml - return code');
}

##################################################
# Test File 03 - 2
sub test_case_03_2 {
    @ARGV = ($Bin."/data/03-parse_response2.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '03-parse_response2.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '03-parse_response2.xml - fail count');
    is($rc, 1, '03-parse_response.xml - return code');
}

##################################################
# Test File 03 - 3
sub test_case_03_3 {
    @ARGV = ($Bin."/data/03-parse_response3.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '03-parse_response2.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '03-parse_response2.xml - fail count');
    is($rc, 0, '03-parse_response.xml - return code');
}

##################################################
# Test File 04
sub test_case_04 {
    @ARGV = ($Bin."/data/04-repeated_tests.xml");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 5, '04-repeated_tests.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 5, '04-repeated_tests.xml - fail count');
    is($rc, 1, '04-repeated_tests.xml - return code');
}

##################################################
# Reporttypes
sub test_case_05 {
    for my $type (qw/standard nagios mrtg external:t\/data\/external.pm/) {
        @ARGV = (
                 "-r", $type,
                 $Bin."/data/05-report_types.xml"
                );
        my $webinject = Webinject->new();
        $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
        my $rc = $webinject->engine();
        is($webinject->{'result'}->{'totalpassedcount'}, 1, 'reporttype: '.$type.' 05-report_types.xml - passed count');
        is($webinject->{'result'}->{'totalfailedcount'}, 1, 'reporttype: '.$type.' 05-report_types.xml - fail count');
        is($rc, 1, '05-report_types.xml - return code') if $type ne 'nagios';
        is($rc, 2, '05-report_types.xml - return code') if $type eq 'nagios';
    }
}

##################################################
# Test File 06
sub test_case_06 {
    @ARGV = ('-r', 'nagios', $Bin."/data/06-thresholds.xml", "testcases/case[1]");
    my $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 3, '06-thresholds.xml [1] - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '06-thresholds.xml [1] - fail count');
    is($rc, 0, '06-thresholds.xml [1] - return code');

    @ARGV = ('-r', 'nagios', $Bin."/data/06-thresholds.xml", "testcases/case[2]");
    $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 2, '06-thresholds.xml [2] - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 1, '06-thresholds.xml [2] - fail count');
    is($rc, 1, '06-thresholds.xml [2] - return code');

    @ARGV = ('-r', 'nagios', $Bin."/data/06-thresholds.xml", "testcases/case[3]");
    $webinject = Webinject->new();
    $webinject->{'config'}->{'baseurl'} = 'http://localhost:58080';
    $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '06-thresholds.xml [3] - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 2, '06-thresholds.xml [3] - fail count');
    is($rc, 2, '06-thresholds.xml [3] - return code');
}

##################################################
# Test Case 7 / File 01
sub test_case_07 {
    @ARGV = ("-s", "baseurl=http://localhost:58080", $Bin."/data/01-response_codes.xml");
    my $webinject = Webinject->new();
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '01-response_codes.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 1, '01-response_codes.xml - fail count');
    is($rc, 1, '01-response_codes.xml - return code');
}


##################################################
# Test Case 8 / File 08
sub test_case_08 {
    @ARGV = ("-s", "baseurl=http://localhost:58080", "-s", "code1=200", "-s", "code_500=500", "-s", "method=get", $Bin."/data/08-custom_var.xml");
    my $webinject = Webinject->new();
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 1, '08-custom_var.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 1, '08-custom_var.xml - fail count');
    is($rc, 1, '01-response_codes.xml - return code');
}


##################################################
# Test Case 9 / File 09
sub test_case_09 {
    @ARGV = ($Bin."/data/09-fileupload.xml");
    my $webinject = Webinject->new();
    my $rc = $webinject->engine();
    is($webinject->{'result'}->{'totalpassedcount'}, 4, '09-fileupload.xml - passed count');
    is($webinject->{'result'}->{'totalfailedcount'}, 0, '09-fileupload.xml - fail count');
    is($rc, 0, '09-fileupload.xml - return code');
}