Skip to content

Commit

Permalink
added tests for inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Mar 3, 2010
1 parent 6aac8bd commit beb8052
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
9 changes: 9 additions & 0 deletions author.t/app.psgi
@@ -0,0 +1,9 @@
use strict;
use lib 'lib';
use Foo;

Foo->new->to_app;




15 changes: 15 additions & 0 deletions author.t/app.t
@@ -0,0 +1,15 @@
use LWP::UserAgent;
use Test::More tests=>1;

my $ua = LWP::UserAgent->new;

#unless ($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping","id":"1"}')->is_success) {
# die "You need to 'plackup -E prod eg/app.psgi' before running these tests!";
#}

is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}')->content,
'{"jsonrpc":"2.0","id":"1","result":10}',
'sum test - using an inherited method');



9 changes: 9 additions & 0 deletions author.t/inheritance.psgi
@@ -0,0 +1,9 @@
use strict;
use lib 'lib';
use Bar;

Bar->new->to_app;




23 changes: 23 additions & 0 deletions author.t/inheritance.t
@@ -0,0 +1,23 @@
use LWP::UserAgent;
use Test::More tests=>3;

my $ua = LWP::UserAgent->new;

#unless ($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping","id":"1"}')->is_success) {
# die "You need to 'plackup -E prod eg/app.psgi' before running these tests!";
#}

is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"concat_with_spaces","params":["hello","world"],"id":"1"}')->content,
'{"jsonrpc":"2.0","id":"1","result":"hello world"}',
'concat with spaces test');

is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"rpc_method_names","id":"1"}')->content,
'{"jsonrpc":"2.0","id":"1","result":["sum","concat_with_spaces","rpc_method_names"]}',
'method names test');

is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}')->content,
'{"jsonrpc":"2.0","id":"1","result":10}',
'sum test - using an inherited method');



19 changes: 19 additions & 0 deletions author.t/lib/Bar.pm
@@ -0,0 +1,19 @@
package Bar;

use Moose;
extends 'Foo';

sub concat_with_spaces {
my ($self, @params) = @_;
return join " ", @params;
}

sub rpc_method_names {
my ($self) = @_;
return [$self->_rpc_method_names];
}


__PACKAGE__->register_rpc_method_names( qw( concat_with_spaces rpc_method_names ) );

1;
20 changes: 20 additions & 0 deletions author.t/lib/Foo.pm
@@ -0,0 +1,20 @@
package Foo;

use lib '../lib';

use Moose;
extends 'JSON::RPC::Dispatcher::App';

sub sum {
my ($self, @params) = @_;
my $sum = 0;
$sum += $_ for @params;
return $sum;
}




__PACKAGE__->register_rpc_method_names( qw( sum ) );

1;

0 comments on commit beb8052

Please sign in to comment.