Merge pull request #749 from wing328/perl_add_unittest

Add unit testing for Perl
This commit is contained in:
Tony Tam 2015-05-16 06:56:53 -07:00
commit 472e2afd8e
2 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>PerlPetstoreClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Perl Swagger Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>Test::More</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>perl</executable>
<arguments>
<argument>t/01_pet_api.t</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,59 @@
use Test::More tests => 25;
use Test::Exception;
use lib 'lib';
use strict;
use warnings;
use_ok('WWW::SwaggerClient::PetApi');
use_ok('WWW::SwaggerClient::APIClient');
use_ok('WWW::SwaggerClient::Object::Pet');
use_ok('WWW::SwaggerClient::Object::Tag');
use_ok('WWW::SwaggerClient::Object::Category');
my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 10008;
my $category = WWW::SwaggerClient::Object::Category->new('id' => '22', 'name' => 'perl');
my $tag = WWW::SwaggerClient::Object::Tag->new('id' => '11', 'name' => 'just kidding');
my $pet = WWW::SwaggerClient::Object::Pet->new('id' => $pet_id, 'name' => 'perl test',
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending', 'category' => $category);
isa_ok($api, 'WWW::SwaggerClient::PetApi');
isa_ok($category, 'WWW::SwaggerClient::Object::Category');
isa_ok($tag, 'WWW::SwaggerClient::Object::Tag');
isa_ok($pet, 'WWW::SwaggerClient::Object::Pet');
my $pet_hash = $pet->to_hash;
is $pet_hash->{category}->{id}, '22', 'get the proper category id';
is $pet_hash->{category}->{name}, 'perl', 'get the proper category name';
is $pet_hash->{tags}[0]->{name}, 'just kidding', 'get the proper tag name';
is $pet_hash->{tags}[0]->{id}, '11', 'get the proper tag id';
my $add_pet = $api->add_pet(body => $pet);
my $get_pet = $api->get_pet_by_id(pet_id => $pet_id);
my $get_pet_hash = $get_pet->to_hash;
is $get_pet_hash->{name}, 'perl test', 'get the proper pet name from get_pet_by_id';
is $get_pet_hash->{id}, '10008', 'get the proper pet id from get_pet_by_id';
is $get_pet_hash->{category}->{name}, 'perl', 'get the proper category name from get_pet_by_id';
is $get_pet_hash->{category}->{id}, '22', 'get the proper category id from get_pet_by_id';
is $get_pet_hash->{category}->{name}, 'perl', 'get the proper category from get_pet_by_id';
is $get_pet_hash->{tags}[0]->{name}, 'just kidding', 'get the proper tag from get_pet_by_id';
is $get_pet_hash->{tags}[0]->{id}, '11', 'get the proper tag id from get_pet_by_id';
my $update_pet_with_form = $api->update_pet_with_form(pet_id => $pet_id, name => 'test_name', status => 'sold');
is $update_pet_with_form, undef, 'get the null response from update_pet_wth_form';
my $get_pet_after_update = $api->get_pet_by_id(pet_id => $pet_id);
is $get_pet_after_update->{status}, 'sold', 'get the updated status after update_pet_with_form';
my $upload_pet = $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => 'test.pl');
is $upload_pet, undef, 'get the null response from upload_pet';
my $delete_pet = $api->delete_pet(pet_id => $pet_id);
is $delete_pet, undef, 'get the null response from delete_pet';
throws_ok{$api->get_pet_by_id(pet_id => $pet_id)} qr/API Exception\(404\): Not Found/, "throw 404 error about pet not found after delete";
#is $get_pet_after_delete->{status}, undef, 'get the updated status after update_pet_with_form';