Skip to content

[Perl] generate files for unit testing models and API files #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public PerlClientCodegen() {
outputFolder = "generated-code" + File.separatorChar + "perl";
modelTemplateFiles.put("object.mustache", ".pm");
apiTemplateFiles.put("api.mustache", ".pm");
modelTestTemplateFiles.put("object_test.mustache", ".t");
apiTestTemplateFiles.put("api_test.mustache", ".t");
embeddedTemplateDir = templateDir = "perl";


Expand Down Expand Up @@ -142,6 +144,17 @@ public String modelFileFolder() {
return (outputFolder + "/lib/" + modulePathPart + modelPackage()).replace('/', File.separatorChar);
}


@Override
public String apiTestFileFolder() {
return (outputFolder + "/t").replace('/', File.separatorChar);
}

@Override
public String modelTestFileFolder() {
return (outputFolder + "/t").replace('/', File.separatorChar);
}

@Override
public String getTypeDeclaration(Property p) {
if (p instanceof ArrayProperty) {
Expand Down Expand Up @@ -218,6 +231,16 @@ public String toModelFilename(String name) {
return toModelName(name);
}

@Override
public String toModelTestFilename(String name) {
return toModelFilename(name) + "Test";
}

@Override
public String toApiTestFilename(String name) {
return toApiFilename(name) + "Test";
}

@Override
public String toApiFilename(String name) {
// replace - with _ e.g. created-at => created_at
Expand Down
46 changes: 46 additions & 0 deletions modules/swagger-codegen/src/main/resources/perl/api_test.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright 2016 SmartBear Software
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# NOTE: This class is auto generated by the swagger code generator program.
# Do not edit the class manually.
#
use Test::More tests => 1; #TODO update number of test cases
use Test::Exception;

use lib 'lib';
use strict;
use warnings;

use_ok('{{moduleName}}::{{classname}}');

my $api = {{moduleName}}::{{classname}}->new();
isa_ok($api, '{{moduleName}}::{{classname}}');

{{#operations}}
{{#operation}}
#
# {{{nickname}}} test
#
{
{{#allParams}} my ${{paramName}} = undef; # replace NULL with a proper value
{{/allParams}}
my $result = $api->{{nickname}}({{#allParams}}{{paramName}} => ${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
}

{{/operation}}
{{/operations}}

1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use Test::More tests => 2;
use Test::Exception;

use lib 'lib';
use strict;
use warnings;

{{#models}}
{{#model}}

use_ok('{{moduleName}}::Object::{{classname}}');

my $instance = {{moduleName}}::Object::{{classname}}->new();

isa_ok($instance, '{{moduleName}}::Object::{{classname}}');

{{/model}}
{{/models}}
2 changes: 1 addition & 1 deletion samples/client/petstore/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WWW::SwaggerClient::Role - a Moose role for the Swagger Petstore

Automatically generated by the Perl Swagger Codegen project:

- Build date: 2016-01-17T19:21:19.346+08:00
- Build date: 2016-02-11T08:22:52.982+08:00
- Build package: class io.swagger.codegen.languages.PerlClientCodegen
- Codegen version:

Expand Down
10 changes: 5 additions & 5 deletions samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,10 @@ sub upload_file {
__PACKAGE__->method_documentation->{ get_pet_by_id_with_byte_array } = {
summary => 'Fake endpoint to test byte array return by 'Find pet by ID'',
params => $params,
returns => 'binary',
returns => 'string',
};
}
# @return binary
# @return string
#
sub get_pet_by_id_with_byte_array {
my ($self, %args) = @_;
Expand Down Expand Up @@ -732,7 +732,7 @@ sub get_pet_by_id_with_byte_array {
if (!$response) {
return;
}
my $_response_object = $self->{api_client}->deserialize('binary', $response);
my $_response_object = $self->{api_client}->deserialize('string', $response);
return $_response_object;

}
Expand All @@ -742,11 +742,11 @@ sub get_pet_by_id_with_byte_array {
#
# Fake endpoint to test byte array in body parameter for adding a new pet to the store
#
# @param binary $body Pet object in the form of byte array (optional)
# @param string $body Pet object in the form of byte array (optional)
{
my $params = {
'body' => {
data_type => 'binary',
data_type => 'string',
description => 'Pet object in the form of byte array',
required => '0',
},
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ has version_info => ( is => 'ro',
default => sub { {
app_name => 'Swagger Petstore',
app_version => '1.0.0',
generated_date => '2016-01-17T19:21:19.346+08:00',
generated_date => '2016-02-11T08:22:52.982+08:00',
generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen',
} },
documentation => 'Information about the application version and the codegen codebase version'
Expand Down Expand Up @@ -103,7 +103,7 @@ Automatically generated by the Perl Swagger Codegen project:

=over 4

=item Build date: 2016-01-17T19:21:19.346+08:00
=item Build date: 2016-02-11T08:22:52.982+08:00

=item Build package: class io.swagger.codegen.languages.PerlClientCodegen

Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/perl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<configuration>
<executable>perl</executable>
<arguments>
<argument>t/01_pet_api.t</argument>
<argument>tests/01_pet_api.t</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -48,7 +48,7 @@
<configuration>
<executable>perl</executable>
<arguments>
<argument>t/02_store_api.t</argument>
<argument>tests/02_store_api.t</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -61,7 +61,7 @@
<configuration>
<executable>perl</executable>
<arguments>
<argument>t/03_api_factory.t</argument>
<argument>tests/03_api_factory.t</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -74,7 +74,7 @@
<configuration>
<executable>perl</executable>
<arguments>
<argument>t/04_role.t</argument>
<argument>tests/04_role.t</argument>
</arguments>
</configuration>
</execution>
Expand Down
14 changes: 14 additions & 0 deletions samples/client/petstore/perl/t/CategoryTest.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use Test::More tests => 2;
use Test::Exception;

use lib 'lib';
use strict;
use warnings;


use_ok('WWW::SwaggerClient::Object::Category');

my $instance = WWW::SwaggerClient::Object::Category->new();

isa_ok($instance, 'WWW::SwaggerClient::Object::Category');

14 changes: 14 additions & 0 deletions samples/client/petstore/perl/t/OrderTest.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use Test::More tests => 2;
use Test::Exception;

use lib 'lib';
use strict;
use warnings;


use_ok('WWW::SwaggerClient::Object::Order');

my $instance = WWW::SwaggerClient::Object::Order->new();

isa_ok($instance, 'WWW::SwaggerClient::Object::Order');

118 changes: 118 additions & 0 deletions samples/client/petstore/perl/t/PetApiTest.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Copyright 2016 SmartBear Software
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# NOTE: This class is auto generated by the swagger code generator program.
# Do not edit the class manually.
#
use Test::More tests => 1; #TODO update number of test cases
use Test::Exception;

use lib 'lib';
use strict;
use warnings;

use_ok('WWW::SwaggerClient::PetApi');

my $api = WWW::SwaggerClient::PetApi->new();
isa_ok($api, 'WWW::SwaggerClient::PetApi');

#
# update_pet test
#
{
my $body = undef; # replace NULL with a proper value
my $result = $api->update_pet(body => $body);
}

#
# add_pet test
#
{
my $body = undef; # replace NULL with a proper value
my $result = $api->add_pet(body => $body);
}

#
# find_pets_by_status test
#
{
my $status = undef; # replace NULL with a proper value
my $result = $api->find_pets_by_status(status => $status);
}

#
# find_pets_by_tags test
#
{
my $tags = undef; # replace NULL with a proper value
my $result = $api->find_pets_by_tags(tags => $tags);
}

#
# get_pet_by_id test
#
{
my $pet_id = undef; # replace NULL with a proper value
my $result = $api->get_pet_by_id(pet_id => $pet_id);
}

#
# update_pet_with_form test
#
{
my $pet_id = undef; # replace NULL with a proper value
my $name = undef; # replace NULL with a proper value
my $status = undef; # replace NULL with a proper value
my $result = $api->update_pet_with_form(pet_id => $pet_id, name => $name, status => $status);
}

#
# delete_pet test
#
{
my $pet_id = undef; # replace NULL with a proper value
my $api_key = undef; # replace NULL with a proper value
my $result = $api->delete_pet(pet_id => $pet_id, api_key => $api_key);
}

#
# upload_file test
#
{
my $pet_id = undef; # replace NULL with a proper value
my $additional_metadata = undef; # replace NULL with a proper value
my $file = undef; # replace NULL with a proper value
my $result = $api->upload_file(pet_id => $pet_id, additional_metadata => $additional_metadata, file => $file);
}

#
# get_pet_by_id_with_byte_array test
#
{
my $pet_id = undef; # replace NULL with a proper value
my $result = $api->get_pet_by_id_with_byte_array(pet_id => $pet_id);
}

#
# add_pet_using_byte_array test
#
{
my $body = undef; # replace NULL with a proper value
my $result = $api->add_pet_using_byte_array(body => $body);
}


1;
14 changes: 14 additions & 0 deletions samples/client/petstore/perl/t/PetTest.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use Test::More tests => 2;
use Test::Exception;

use lib 'lib';
use strict;
use warnings;


use_ok('WWW::SwaggerClient::Object::Pet');

my $instance = WWW::SwaggerClient::Object::Pet->new();

isa_ok($instance, 'WWW::SwaggerClient::Object::Pet');

Loading