view release on metacpan or search on metacpan
use 5.006;
use strict;
use warnings FATAL => 'all';
use Module::Build;
my $builder = Module::Build->new(
module_name => 'APP::REST::RestTestSuite',
license => 'artistic_2',
dist_author => q{Mithun Radhakrishnan <rkmithun@cpan.org>},
dist_version_from => 'lib/APP/REST/RestTestSuite.pm',
dist_abstract => 'rest-client => Test automation tool for restful web services',
release_status => 'stable',
script_files => [
'script/rest-client',
],
meta_merge => {
resources => {
repository => 'https://github.com/rkmithun/APP-REST-RestTestSuite'
}
},
configure_requires => {
'Module::Build' => 0,
},
build_requires => {
'Test::More' => 0,
},
requires => {
'LWP::Parallel::UserAgent' => 0,
'LWP::UserAgent' => 0,
'HTTP::Request' => 0,
'File::Path' => 0,
'File::Basename' => 0,
'Time::HiRes' => 0,
'Getopt::Long' => 0,
},
add_to_cleanup => [ 'APP-REST-RestTestSuite-*' ],
create_makefile_pl => 'traditional',
);
$builder->create_build_script();
Revision history for APP-REST-RestTestSuite
0.02 24/02/2014
Integrated all scripts to single rest-client client
Implemented GetOptions in client for easy usage.
updated Build scripts to install the scripts to bin dir.
Made rest-client as a CLI rest client
0.01 20/02/2014
First version, released on an unsuspecting world.
RestTestSuite module with scripts.
Installation to scripts to custom directory.
Build.PL
Changes
ignore.txt
lib/APP/REST/ParallelMyUA.pm
lib/APP/REST/RestTestSuite.pm
Makefile.PL
MANIFEST This list of files
META.json
META.yml
README
README.md
script/rest-client
t/00-load.t
t/boilerplate.t
t/manifest.t
{
"abstract" : "rest-client => Test automation tool for restful web services",
"author" : [
"Mithun Radhakrishnan <rkmithun@cpan.org>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.4206",
"license" : [
"artistic_2"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "APP-REST-RestTestSuite",
"prereqs" : {
"build" : {
"requires" : {
"Test::More" : "0"
}
},
"configure" : {
"requires" : {
"Module::Build" : "0"
}
},
"runtime" : {
"requires" : {
"File::Basename" : "0",
"LWP::UserAgent" : "0",
"Time::HiRes" : "0"
}
}
},
"provides" : {
"APP::REST::ParallelMyUA" : {
"file" : "lib/APP/REST/ParallelMyUA.pm",
"version" : "0.03"
},
"APP::REST::RestTestSuite" : {
"file" : "lib/APP/REST/RestTestSuite.pm",
"version" : "0.03"
}
},
"release_status" : "stable",
"resources" : {
"license" : [
"http://opensource.org/licenses/artistic-license-2.0.php"
],
"repository" : {
"url" : "https://github.com/rkmithun/APP-REST-RestTestSuite"
}
},
"version" : "0.03"
}
---
abstract: 'rest-client => Test automation tool for restful web services'
author:
- 'Mithun Radhakrishnan <rkmithun@cpan.org>'
build_requires:
Test::More: 0
configure_requires:
Module::Build: 0
dynamic_config: 1
generated_by: 'Module::Build version 0.4206, CPAN::Meta::Converter version 2.120921'
license: artistic_2
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: APP-REST-RestTestSuite
provides:
APP::REST::ParallelMyUA:
file: lib/APP/REST/ParallelMyUA.pm
version: 0.03
APP::REST::RestTestSuite:
file: lib/APP/REST/RestTestSuite.pm
version: 0.03
requires:
File::Basename: 0
File::Path: 0
Getopt::Long: 0
HTTP::Request: 0
LWP::Parallel::UserAgent: 0
LWP::UserAgent: 0
Time::HiRes: 0
resources:
license: http://opensource.org/licenses/artistic-license-2.0.php
repository: https://github.com/rkmithun/APP-REST-RestTestSuite
version: 0.03
Makefile.PL view on Meta::CPAN
# Note: this file was auto-generated by Module::Build::Compat version 0.4206
use ExtUtils::MakeMaker;
WriteMakefile
(
'EXE_FILES' => [
'script/rest-client'
],
'NAME' => 'APP::REST::RestTestSuite',
'PL_FILES' => {},
'PREREQ_PM' => {
'HTTP::Request' => 0,
'File::Path' => 0,
'Time::HiRes' => 0,
'Test::More' => 0,
'Getopt::Long' => 0,
'LWP::Parallel::UserAgent' => 0,
'LWP::UserAgent' => 0,
'File::Basename' => 0
},
'VERSION_FROM' => 'lib/APP/REST/RestTestSuite.pm',
'INSTALLDIRS' => 'site'
)
;
APP-REST-RestTestSuite
The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.
A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
- For RPM based ( e.g RHEL, CentOS) run below command
yum -y install openssl-devel
===================================================
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc APP::REST::RestTestSuite
You can also look for information at:
RT, CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=APP-REST-RestTestSuite
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/APP-REST-RestTestSuite
CPAN Ratings
http://cpanratings.perl.org/d/APP-REST-RestTestSuite
Search CPAN
http://search.cpan.org/dist/APP-REST-RestTestSuite/
LICENSE AND COPYRIGHT
Copyright (C) 2014 Mithun Radhakrishnan
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
APP-REST-RestTestSuite
======================
This is my pet project on creating test automation tool for restfull services
.build/
_build/
cover_db/
blib/
inc/
.lwpcookies
.last_cover_stats
nytprof.out
pod2htm*.tmp
pm_to_blib
APP-REST-RestTestSuite-*
APP-REST-RestTestSuite-*.tar.gz
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
package APP::REST::RestTestSuite;
use 5.006;
use strict;
use warnings FATAL => 'all';
use Data::Dumper;
use HTTP::Request;
use Time::HiRes qw( time sleep );
use File::Path;
use Cwd;
use LWP::UserAgent;
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
use constant LOG_FILE => 'rest_client.log';
use constant ERR_LOG_FILE => 'rest_client_error.log';
use constant LINE => '=' x 50;
$| = 1; #make the pipe hot
$Data::Dumper::Indent = 1;
=head1 NAME
APP::REST::RestTestSuite - Suite for testing restful web services
=head1 VERSION
Version 0.03
=cut
our $VERSION = '0.03';
=head1 SYNOPSIS
use APP::REST::RestTestSuite;
my $suite = APP::REST::RestTestSuite->new();
$suite->execute_test_cases( $suite->get_test_cases() );
my ( $cases_in_config, $executed, $skipped, $passed, $failed ) =
$suite->get_result_summary();
#OR
use APP::REST::RestTestSuite;
# overrides the default config and log file paths
my $suite = APP::REST::RestTestSuite->new(
REST_CONFIG_FILE => <config file>,
LOG_FILE_PATH => <path>,
);
$suite->execute_test_cases( $suite->get_test_cases() );
my ( $cases_in_config, $executed, $skipped, $passed, $failed ) =
$suite->get_result_summary();
=head1 DESCRIPTION
APP::REST::RestTestSuite object is instantiated with the data in config file.
Default config file format is defined in __DATA__ and that can be overridden
by passing the config file as an argument to the class.
Default LOG file path is the current working directory of the script which
calls this module
=head1 SUBROUTINES/METHODS
=head2 new
Object Constructor
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
sub validate_test_cases {
my ($self) = shift;
my $err = undef;
unless (@_) {
$err = "There is no test cases defined to execute.\n";
} elsif ( ( (@_) % 2 ) == 1 ) {
$err =
"Test cases are not properly configured in '"
. $self->get_config_file()
. "'\nDefine test cases properly.\nPlease see the README file for more info.\n";
}
return $err if ($err);
my %test_cases = @_;
my @spec = sort qw(
test_case
uri
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
#below two are not mandatory for a test case as of now; if required add them to above array
# response_header
# response_body
foreach my $count ( sort { $a <=> $b } keys(%test_cases) ) {
my $tc = $test_cases{$count};
my @keys = sort keys %{$tc};
no warnings;
$err .= "Test case '$tc->{test_case}' not properly defined\n"
unless ( _compare_arrays( \@spec, \@keys ) );
}
$err .= "Please see the README file to see the correct format.\n" if ($err);
return $err;
}
=head2 execute_test_cases
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
&& ( $self->{html_log_required} =~ /yes/i ) )
{
print $fh
qq|<HTML> <HEAD> <TITLE>LOG for $self->{endpoint}</TITLE> </HEAD>|
. qq|<BODY><textarea rows="999999" cols="120" style="border:none;">|;
print $err_fh
qq|<HTML> <HEAD> <TITLE>ERROR LOG for $self->{endpoint}</TITLE> </HEAD>|
. qq|<BODY><textarea rows="999999" cols="120" style="border:none;">|;
}
print STDERR "\nTest Suite executed on $self->{endpoint}\n";
print $fh "\nTest Suite executed on $self->{endpoint}\n";
print $err_fh "\nTest Suite executed on $self->{endpoint}\n";
foreach my $count ( sort { $a <=> $b } keys(%test_cases) ) {
my $tc = $test_cases{$count};
$config++;
print $fh "\n", LINE, "\n";
if ( $tc->{execute} && ( $tc->{execute} =~ /no/i ) ) {
print $fh "\nSkipping Test case $count => $tc->{test_case} \n";
$skip++;
next;
}
$uri = qq|$self->{rest_uri_base}| . qq|$tc->{uri}|;
$method = uc( $tc->{request_method} );
$req_content_type = $tc->{request_content_type};
$req_body = $tc->{request_body} || 0;
$status = $tc->{response_status};
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
if ( $username && $password );
} else {
$request =
HTTP::Request->new( $method, $uri, new HTTP::Headers, $req_body );
$request->authorization_basic( $username, $password )
if ( $username && $password );
$request->content_type($req_content_type);
$request->content_length( length($req_body) );
}
print STDERR "Executing Test case $count => $tc->{test_case}";
print $fh "Executing Test case $count => $tc->{test_case}";
my $start_time = time;
$response = $ua->request($request);
$total++;
my $exec_time = $self->delta_time( start_time => $start_time );
$total_response_time += $exec_time;
$exec_time = sprintf( "%.2f", $exec_time );
print STDERR " [Completed in $exec_time ms]\n";
print $fh " [Completed in $exec_time ms]\n";
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
#my $respose_content_type = $response->{_headers}->content_type;
my $respose_content_type = $response->header('Content-Type');
unless ( defined $respose_content_type ) {
$failed = 1;
} elsif ( $expected_response_content_type !~
m/$respose_content_type/ )
{
$failed = 1;
print $err_fh "\n", LINE, "\n";
print $err_fh
"Executing Test case $count => $tc->{test_case}";
print $err_fh
"\n*********ATTENTION CONTENT TYPE ERROR ******";
print $err_fh
"\n\nExpected content_type is $expected_response_content_type\n";
print $err_fh
"content_type recieved in response is $respose_content_type\n";
print $err_fh
"\n*********ATTENTION CONTENT TYPE ERROR ******";
$self->_print_logs(
fh => $err_fh,
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
fh => $err_fh,
res => $response,
exec_time => $exec_time,
);
}
}
($failed) ? $fail++ : $pass++;
} else {
$fail++;
print $err_fh "\n", LINE, "\n";
print $err_fh "Executing Test case $count => $tc->{test_case}";
$self->_print_logs(
fh => $err_fh,
uri => $uri,
method => $method,
req_body => $req_body,
);
$self->_print_logs(
fh => $err_fh,
res => $response,
exec_time => $exec_time,
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
my $fh = $self->get_log_file_handle();
if ( $self->{html_log_required}
&& ( $self->{html_log_required} =~ /yes/i ) )
{
print $fh
qq|<HTML> <HEAD> <TITLE>LOG for $self->{endpoint}</TITLE> </HEAD>|
. qq|<BODY><textarea rows="999999" cols="120" style="border:none;">|;
}
print STDERR "\nTest Suite executed on $self->{endpoint}\n";
print $fh "\nTest Suite executed on $self->{endpoint}\n";
my @reqs;
foreach my $count ( sort { $a <=> $b } keys(%test_cases) ) {
my $tc = $test_cases{$count};
$config++;
if ( $tc->{execute} =~ /no/i ) {
print $fh "\nSkipping Test case $count => $tc->{test_case} \n";
$skip++;
next;
}
$uri = qq|$self->{rest_uri_base}| . qq|$tc->{uri}|;
#Support only GET methods at present
if ( $tc->{request_method} =~ /get/i ) {
# Create HTTP request pool for later execution by parallel useragent
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
sub _init_config_file_handle {
my ( $self, %args ) = @_;
$self->_init_config_files(%args);
my $file = $self->{file};
if ( $file->{config_file} ) {
$file->{config_file_handle} =
$self->_open_fh( FILE => $file->{config_file}, MODE => 'READ' );
} else {
$file->{config_file_handle} = \*APP::REST::RestTestSuite::DATA;
}
$self->{file} = $file;
}
sub _init_log_file_handle {
my ( $self, %args ) = @_;
$self->_init_log_files(%args)
; #Make compatible with windows and linux logging
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
print $fh "\n";
print $fh "Response code => ";
print $fh $res->code;
print $fh " [ ";
print $fh ( exists $self->{http_status_code}->{ $res->code } )
? $self->{http_status_code}->{ $res->code }
: $define;
print $fh " ]\n";
print $fh "\n\nResponse Content =>\n";
print $fh $res->content;
print $fh "\n\nTest execution time => ";
print $fh $args{exec_time};
print $fh " milli seconds";
print $fh "\n", LINE, "\n";
}
}
sub _compare_arrays {
my ( $first, $second ) = @_;
no warnings; # silence spurious -w undef complaints
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
Mithun Radhakrishnan, C<< <rkmithun at cpan.org> >>
=head1 BUGS
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc APP::REST::RestTestSuite
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2014 Mithun Radhakrishnan.
This program is free software; you can redistribute it and/or modify it
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
=head1 REPOSITORY
L<https://github.com/rkmithun/APP-REST-RestTestSuite>
=cut
1; # End of APP::REST::RestTestSuite
__DATA__
# RestTestSuite supports config file of below format.
# All values in LHS of ':' are case sensitive.
# Every test case should be within the '#START_TEST_CASE' and '#END_TEST_CASE' block.
# Create application specific config file in below format and pass the
# full path of file as an argument to the constructor
# for POST and PUT methods you need to supply the request body within
# [START] and [END] tags
# request_body :
# [START]
# xml or json or form based
# [END]
script/rest-client view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use POSIX;
use APP::REST::RestTestSuite;
use Data::Dumper;
$Data::Dumper::Indent = 1;
my ( $config_file, $log_dir, $action, $suite );
my $client = File::Basename::basename($0);
my %options = (
'c|configfile=s' => \$config_file,
'l|logdir=s' => \$log_dir,
'r|run-test-suite' => \$action->{runtestsuite},
't|test-load=s' => \$action->{testload},
's|get-sample-config' => \$action->{getsampleconfig},
'd|debug' => \$action->{debug},
'h|help' => \&usage,
'V|version' =>
sub { print "Version : ", APP::REST::RestTestSuite->VERSION, "\n"; exit; },
);
mini_usage() unless @ARGV;
GetOptions(%options) or mini_usage();
sub mini_usage {
print STDERR <<HELP;
Usage: $client [options] command [...]
script/rest-client view on Meta::CPAN
sub usage {
print STDERR <<HELP;
Usage: $client [options] command [...]
Options:
-h,--help Display this usage.
-V,--version Print the version of the tool.
-c,--configfile=<file> Input the config file with full path.
-l,--logdir=<dir> Input full path of the directory where you want to log the test results.
-t,--test-load=n Test the average response time by simulating 'n' number of requests on the web server.
Commands:
-r,--run-test-suite Test the configured web services defined in the config file.
-g,--get-sample-config Get a sample config file to configure your web services as test suite.
***Note:
By default tool uses the sample-config file. You need to get that and configure the suite.
Examples:
$client --get-sample-config
# Get sample config file for configuring web services in the current directory.
$client --run-test-suite --configfile=<rest_config_file>
script/rest-client view on Meta::CPAN
$client --run-test-suite --configfile=<rest_config_file> --logdir=<log-directory-path>
$client --test-load=10 --configfile=<rest_config_file> --logdir=<log-directory-path>
# Create LOG files in the path specified by executing the test cases.
HELP
exit;
}
print
"\n===============================Rest Test Automation Tool=============================\n";
if ( $^O =~ /Win/ ) {
$config_file =~ s/\//\\/g if ($config_file);
$log_dir =~ s/\//\\/g if ($log_dir);
}
if ( $config_file && $log_dir ) {
print "Parsing Config File : $config_file\n";
print "Using log dir as : $log_dir\n";
$suite = new APP::REST::RestTestSuite(
REST_CONFIG_FILE => $config_file,
LOG_FILE_PATH => $log_dir,
);
} elsif ($config_file) {
print "Parsing Config File : $config_file\n\n";
$suite = new APP::REST::RestTestSuite( REST_CONFIG_FILE => $config_file, );
} elsif ($log_dir) {
print <<HELP;
Using log dir as : $log_dir
Using the default test suite. This is just for a demo purpose.
Use below options to specify the config file and log path.
$client --configfile=<rest_config_file> --logdir=<log-directory-path>
HELP
$suite = new APP::REST::RestTestSuite( LOG_FILE_PATH => $log_dir, );
} else {
unless ( $action->{getsampleconfig} ) {
print <<HELP;
Using the default test suite. This is just for a demo purpose.
Use below options to specify the config file and log path.
$client --configfile=<rest_config_file> --logdir=<log-directory-path>
Use below option to get a sample config. Edit the config file to configure your web services
$client --get-sample-config
HELP
}
$suite = new APP::REST::RestTestSuite();
}
if ( $action->{debug} ) {
print Dumper $suite;
exit;
} elsif ( $action->{runtestsuite} ) {
$suite->execute_test_cases( $suite->get_test_cases() );
script/rest-client view on Meta::CPAN
print "\nUse below options to execute the test cases\n\n";
print "$client --configfile=<rest_config_file> --run-test-suite\n\n";
exit;
}
__END__
=head1 NAME
rest-client - Test automation tool for restful web services
=head1 SYNOPSIS
Usage: rest-client [options] command [...]
Options:
-h,--help Display this usage.
-V,--version Print the version of the tool.
-c,--configfile=<file> Input the config file with full path.
-l,--logdir=<dir> Input full path of the directory where you want to log the test results.
-t,--test-load=n Test the average response time by simulating 'n' number of requests on the web server.
Commands:
-r,--run-test-suite Test the configured web services defined in the config file.
-g,--get-sample-config Get a sample config file to configure your web services as test suite.
***Note:
By default tool uses the sample-config file. You need to get that and configure the suite.
Examples:
rest-client --get-sample-config
# Get sample config file for configuring web services in the current directory.
rest-client --run-test-suite --configfile=<rest_config_file>
script/rest-client view on Meta::CPAN
# Send parallel requests (10* number of web services configured in config file).
# Give average response time by simulating huge traffic in the web server.
rest-client --run-test-suite --configfile=<rest_config_file> --logdir=<log-directory-path>
rest-client --test-load=10 --configfile=<rest_config_file> --logdir=<log-directory-path>
# Create LOG files in the path specified by executing the test cases.
=head1 SEE ALSO
L<https://github.com/rkmithun/APP-REST-RestTestSuite>
=cut
t/00-load.t view on Meta::CPAN
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'APP::REST::RestTestSuite' ) || print "Bail out!\n";
}
diag( "Testing APP::REST::RestTestSuite $APP::REST::RestTestSuite::VERSION, Perl $], $^X" );
t/boilerplate.t view on Meta::CPAN
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
plan tests => 3;
sub not_in_file_ok {
my ($filename, %regex) = @_;
open( my $fh, '<', $filename )
or die "couldn't open $filename for reading: $!";
my %violated;
t/boilerplate.t view on Meta::CPAN
not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
);
not_in_file_ok(Changes =>
"placeholder date/time" => qr(Date/time)
);
module_boilerplate_ok('lib/APP/REST/RestTestSuite.pm');
}
t/manifest.t view on Meta::CPAN
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
unless ( $ENV{RELEASE_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
}
my $min_tcm = 0.9;
eval "use Test::CheckManifest $min_tcm";
plan skip_all => "Test::CheckManifest $min_tcm required" if $@;
ok_manifest();
t/pod-coverage.t view on Meta::CPAN
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
# Ensure a recent version of Test::Pod::Coverage
my $min_tpc = 1.08;
eval "use Test::Pod::Coverage $min_tpc";
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
if $@;
# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
# but older versions don't recognize some common documentation styles
my $min_pc = 0.18;
eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
all_pod_coverage_ok();
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
# Ensure a recent version of Test::Pod
my $min_tp = 1.22;
eval "use Test::Pod $min_tp";
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
all_pod_files_ok();