use NRT::Helper; package Test; require Exporter; #@ISA = qw(Exporter); #@EXPORT = qw(get_countSuccess get_countFailure rq assertEqual assertNotEqual get_code); sub new { my ($classe, %config) = @_; my $this = {}; $classe = ref($classe) || $classe; bless ( $this, $classe ); $this->{url} = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}"; $this->{ua} = LWP::UserAgent->new(timeout => 10); $this->{ua}->env_proxy; $this->{countSuccess} = 0; $this->{countFailure} = 0; return $this; } sub rq { my $path = (exists $_[0])? $_[0] : ""; my $method = (exists $_[1])? $_[1] : ""; my $content = (exists $_[2])? $_[2] : ""; my $req = HTTP::Request->new("$method" => "$url$path"); $req->content_type('application/json'); $req->content("$content"); my $res = $ua->request($req); return $res->decoded_content; } sub assertEqual { my ($this, $value1, $value2, $equal ) = @_; $equal ||= 1; my $success = 0; my $test = ( $value1 eq $value2 ); $test = ( $equal )? $test : !$test; if( $test ) { $this->record_result( 1 ); print " $value1 "; Helper::printColor( "bright_blue", "equal"); print " $value2\n"; return 1; }else{ $this->record_result( 0 ); print " $value1 "; Helper::printColor( "bright_blue", "NOT equal"); print " $value2\n"; return 0; }; } sub assertNotEqual { my $this = shift; $this->assertEqual( $_[0], $_[1], 0 ); } sub get_code { my ($this, $path) = @_; if(!defined $path){ $path = ""; #exit 1; } my $response = $this->{ua}->get( "$this->{url}$path" ); if ($response->is_success) { return $response->decoded_content; }else{ return $response->status_line; } } sub record_result { my $this = shift ; my $status = (exists $_[0])? $_[0] : false; if( $status ){ Helper::printColor( "green", "Success :"); $this->{countSuccess}++; }else{ Helper::printColor( "red", "Failure :"); $this->{countFailure}++; } } sub json_parse { my $json_text = (exists $_[0])? $_[0] : ""; my $json = JSON->new; return $json->decode($json_text); } sub get_countSuccess { my $this = shift; return $this->{countSuccess} ; } sub get_countFailure{ return $countFailure ; } sub get_url{ my $this = shift; return $this->{url} ; } return 1;