From 08f424824c1231b0ba8595f21c53e66163766a2a Mon Sep 17 00:00:00 2001 From: dvz5 Date: Sun, 1 Nov 2015 23:14:22 +0100 Subject: [PATCH] Update 02_store_api.t --- samples/client/petstore/perl/t/02_store_api.t | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/samples/client/petstore/perl/t/02_store_api.t b/samples/client/petstore/perl/t/02_store_api.t index f4687daad41..c731273271d 100644 --- a/samples/client/petstore/perl/t/02_store_api.t +++ b/samples/client/petstore/perl/t/02_store_api.t @@ -1,4 +1,4 @@ -use Test::More tests => 22; +use Test::More tests => 42; use Test::Exception; use lib 'lib'; @@ -12,6 +12,8 @@ use_ok('WWW::SwaggerClient::ApiClient'); use_ok('WWW::SwaggerClient::Object::Pet'); use_ok('WWW::SwaggerClient::Object::Tag'); use_ok('WWW::SwaggerClient::Object::Category'); +use_ok('WWW::SwaggerClient::Object::User'); + my $api_client = WWW::SwaggerClient::ApiClient->new(); my $store_api = WWW::SwaggerClient::StoreApi->new('api_client' => $api_client); @@ -53,6 +55,7 @@ is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{category}->{ is ref $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object"; is ref $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{tags}[0], "WWW::SwaggerClient::Object::Tag", "get the Tag of the Pet object"; is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{tags}[0]->{name}, "tag string", "get the Tag name of the Pet object"; +is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{photo_urls}->[0], "string", "get the photoUrl from the Pet object"; my $array_json = <deserialize("ARRAY[Pet]", $array_json)->[0]->{category}->{name}, is ref $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object"; is ref $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{tags}->[0], "WWW::SwaggerClient::Object::Tag", "get the Tag[0] the Pet object"; is $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{tags}->[0]->{name}, "tag string", "get the tag name the Pet object"; +is $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{photo_urls}->[0], "string", "get the photoUrl from the Pet object"; + +my $pet_json_nopet = <deserialize("Pet", $pet_json_nopet), "WWW::SwaggerClient::Object::Pet", "get Pet object via from_hash()"; +is $api_client->deserialize("Pet", $pet_json_nopet)->{name}, "doggie", "get the name of the Pet object"; +is $api_client->deserialize("Pet", $pet_json_nopet)->{category}->{name}, "string", "get the category name of the Pet object"; +is ref $api_client->deserialize("Pet", $pet_json_nopet)->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object"; +is ref $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0], "WWW::SwaggerClient::Object::Tag", "get the Tag[0] the Pet object"; +is $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0]->{name}, "tag string", "get the tag name the Pet object"; +is $api_client->deserialize("Pet", $pet_json_nopet)->{photo_urls}->[0], "string", "get the photoUrl from the Pet object"; + + +my %userdata = ( + id => 4000, + username => "tony", + firstName => "Tony", + lastName => "Tiger", + email => 'tony@fail.com', + password => "XXXXXXXXXXX", + phone => "408-867-5309", + userStatus => 1, + ); + +my $user = WWW::SwaggerClient::Object::User->new->from_hash(\%userdata); +is ref $user, 'WWW::SwaggerClient::Object::User', "built a User object via from_hash()"; +is $user->{id}, $userdata{id}, "got the id of the User object"; +is $user->{username}, $userdata{username}, "got the username of the User object"; +is $user->{first_name}, $userdata{firstName}, "got the firstName of the User object"; +is $user->{last_name}, $userdata{lastName}, "got the lastName of the User object"; +is $user->{email}, $userdata{email}, "got the email of the User object"; +is $user->{password}, $userdata{password}, "got the password of the User object"; +is $user->{phone}, $userdata{phone}, "got the phone of the User object"; +is $user->{user_status}, $userdata{userStatus}, "got the userStatus of the User object";