forked from loafle/openapi-generator-original
[Perl] remove singleton (#5353)
- removed Singleton from ApiClient fixes #5336
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use Test::More tests => 38;
|
||||
use Test::More tests => 37;
|
||||
use Test::Exception;
|
||||
|
||||
use lib 'lib';
|
||||
@@ -11,19 +11,15 @@ use_ok('WWW::SwaggerClient::Object::Pet');
|
||||
use_ok('WWW::SwaggerClient::Object::Tag');
|
||||
use_ok('WWW::SwaggerClient::Object::Category');
|
||||
|
||||
my $api_client = WWW::SwaggerClient::ApiClient->instance('base_url' => 'http://testing');
|
||||
my $pet_api = WWW::SwaggerClient::PetApi->new('api_client' => $api_client);
|
||||
is $pet_api->{api_client}->{base_url}, 'http://testing', 'get the proper base URL from api client';
|
||||
|
||||
my $api = WWW::SwaggerClient::PetApi->new();
|
||||
|
||||
is $api->{api_client}->{base_url}, 'http://testing', 'we still get the original base URL from api client, because it\'s a singleton';
|
||||
my $api_client = WWW::SwaggerClient::ApiClient->new('base_url' => 'http://testing');
|
||||
my $api = WWW::SwaggerClient::PetApi->new($api_client);
|
||||
is $api->{api_client}{config}{base_url}, 'http://testing', 'get the proper base URL from api client';
|
||||
|
||||
# reset the base_url - no direct access because an application shouldn't be changing
|
||||
# its base URL halfway through
|
||||
$api->{api_client}->{base_url} = 'http://petstore.swagger.io/v2';
|
||||
$api->{api_client}{config}{base_url} = 'http://petstore.swagger.io/v2';
|
||||
|
||||
is $api->{api_client}->{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client';
|
||||
is $api->{api_client}{config}{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client';
|
||||
|
||||
# test select_header_content_type
|
||||
is $api->{api_client}->select_header_content_type('application/xml', 'Application/JSON'), 'application/json', 'get the proper content type application/json but not application/xml';
|
||||
|
||||
@@ -15,10 +15,10 @@ use_ok('WWW::SwaggerClient::Object::Category');
|
||||
use_ok('WWW::SwaggerClient::Object::User');
|
||||
|
||||
|
||||
my $api_client = WWW::SwaggerClient::ApiClient->instance();
|
||||
my $store_api = WWW::SwaggerClient::StoreApi->new('api_client' => $api_client);
|
||||
my $api_client = WWW::SwaggerClient::ApiClient->new();
|
||||
my $store_api = WWW::SwaggerClient::StoreApi->new($api_client);
|
||||
|
||||
is $store_api->{api_client}->{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client';
|
||||
is $store_api->{api_client}{config}{base_url}, 'http://petstore.swagger.io:80/v2', 'get the default base URL from api client';
|
||||
|
||||
my $get_inventory_response = $store_api->get_inventory();
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ use_ok('WWW::SwaggerClient::ApiFactory');
|
||||
my $api_factory = WWW::SwaggerClient::ApiFactory->new('base_url' => 'http://testing');
|
||||
my $pet_api = $api_factory->get_api('Pet');
|
||||
isa_ok($pet_api, 'WWW::SwaggerClient::PetApi');
|
||||
is $pet_api->{api_client}->{base_url}, 'http://testing', 'get the proper base URL from api client';
|
||||
is $pet_api->{api_client}{config}{base_url}, 'http://testing', 'get the proper base URL from api client';
|
||||
|
||||
$api_factory = WWW::SwaggerClient::ApiFactory->new;
|
||||
$pet_api = $api_factory->get_api('Pet');
|
||||
|
||||
# reset the base_url - no direct access because an application shouldn't be changing
|
||||
# its base URL halfway through
|
||||
$pet_api->{api_client}->{base_url} = 'http://petstore.swagger.io/v2';
|
||||
is $pet_api->{api_client}->{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client';
|
||||
$pet_api->{api_client}{config}{base_url} = 'http://petstore.swagger.io/v2';
|
||||
is $pet_api->{api_client}{config}{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client';
|
||||
|
||||
# test accessor methods
|
||||
my $pet_id = 10008;
|
||||
|
||||
@@ -95,26 +95,26 @@ my $tokens = {
|
||||
|
||||
$api->_cfg->accept_tokens({%$tokens}); # pass a copy
|
||||
no warnings 'once';
|
||||
is $WWW::SwaggerClient::Configuration::username, 'UserName', 'accept_tokens() correctly set the username';
|
||||
is $WWW::SwaggerClient::Configuration::password, 'PassWord', 'accept_tokens() correctly set the password';
|
||||
is $WWW::SwaggerClient::Configuration::access_token, 'OAuth_token', 'accept_tokens() correctly set the oauth';
|
||||
is $api->_cfg->{username}, 'UserName', 'accept_tokens() correctly set the username';
|
||||
is $api->_cfg->{password}, 'PassWord', 'accept_tokens() correctly set the password';
|
||||
is $api->_cfg->{access_token}, 'OAuth_token', 'accept_tokens() correctly set the oauth';
|
||||
|
||||
my $api_key_href = {
|
||||
'anotherKey' => 'another_key_token',
|
||||
'someKey' => 'some_key_token'
|
||||
};
|
||||
cmp_deeply( $WWW::SwaggerClient::Configuration::api_key, $api_key_href, 'accept_tokens() correctly set api_key' );
|
||||
cmp_deeply( $api->_cfg->{api_key}, $api_key_href, 'accept_tokens() correctly set api_key' );
|
||||
|
||||
my $api_key_prefix_href = {
|
||||
'someKey' => 'some_key_prefix'
|
||||
};
|
||||
cmp_deeply( $WWW::SwaggerClient::Configuration::api_key_prefix, $api_key_prefix_href, 'accept_tokens() correctly set api_key_prefix' );
|
||||
cmp_deeply( $api->_cfg->{api_key_prefix}, $api_key_prefix_href, 'accept_tokens() correctly set api_key_prefix' );
|
||||
|
||||
my $api_key_in = {
|
||||
'someKey' => 'query',
|
||||
'anotherKey' => 'head'
|
||||
};
|
||||
cmp_deeply( $WWW::SwaggerClient::Configuration::api_key_in, $api_key_in, 'accept_tokens() correctly set api_key_in' );
|
||||
cmp_deeply( $api->_cfg->{api_key_in}, $api_key_in, 'accept_tokens() correctly set api_key_in' );
|
||||
|
||||
use warnings 'once';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user