Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added author tests and fixed bulk requests

  • Loading branch information...
commit 4f51764685ace35619d858787f7ab6991daee1bc 1 parent 44cbee5
@rizen rizen authored
View
2  Changes
@@ -3,6 +3,8 @@
- We now send the Content-Length header with the response per the spec.
- Notification responses are removed from batch requests, and if only a notification is sent the HTTP response is 204 No Content per the spec.
- Removed extraneous result/error nodes per spec.
+ - Fixed bulk requests.
+ - Added author tests which put the whole system through it's paces.
0.0100 2009-12-19
- Initial public release.
View
44 author.t/test.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+use LWP::UserAgent;
+use Test::More tests=>8;
+
+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 eg/app.psgi before running these tests!";
+}
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping","id":"1"}')->content,
+ '{"jsonrpc":"2.0","id":"1","result":"pong"}',
+ 'ping test');
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"echo","params":["Hello World!"],"id":"1"}')->content,
+ '{"jsonrpc":"2.0","id":"1","result":"Hello World!"}',
+ 'echo 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');
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"guess","params":[5],"id":"1"}')->content,
+ '{"jsonrpc":"2.0","error":{"data":5,"message":"Too low.","code":987},"id":"1"}',
+ 'guess low test');
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"guess","params":[15],"id":"1"}')->content,
+ '{"jsonrpc":"2.0","error":{"data":15,"message":"Too high.","code":986},"id":"1"}',
+ 'guess high test');
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"guess","params":[10],"id":"1"}')->content,
+ '{"jsonrpc":"2.0","id":"1","result":"Correct!"}',
+ 'guess correct test');
+
+is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping"}')->code,
+ 204,
+ 'notification test');
+
+is($ua->post('http://localhost:5000/', Content=>'[{"jsonrpc":"2.0","method":"ping"},{"jsonrpc":"2.0","method":"guess","params":[10],"id":"1"},{"jsonrpc":"2.0","method":"guess","params":[5],"id":"1"}]')->content,
+ '[{"jsonrpc":"2.0","id":"1","result":"Correct!"},{"jsonrpc":"2.0","error":{"data":5,"message":"Too low.","code":987},"id":"1"}]',
+ 'bulk test');
+
+
View
1  dist.ini
@@ -12,7 +12,6 @@ Plack::Request = 0.09
Moose = 0.93
JSON = 2.16
Test::More = 0
-Test::Deep = 0
[PruneFiles]
filenames = author.t ; nobody needs these
View
15 lib/JSON/RPC/Dispatcher.pm
@@ -159,7 +159,7 @@ sub acquire_procedures_from_post {
if (ref $request eq 'ARRAY') {
my @procs;
foreach my $proc (@{$request}) {
- push @procs, $self->acquire_procedure_from_hashref($request);
+ push @procs, $self->acquire_procedure_from_hashref($proc);
}
return \@procs;
}
@@ -308,24 +308,11 @@ L<JSON>
L<Plack>
L<Plack::Request>
L<Test::More>
-L<Test::Deep>
=head1 TODO
-This module still needs some work.
-
-=over
-
-=item *
-
-It has no test suite, and that needs to be fixed up asap. Although, all of the examples in the eg folder have been tested and work.
-
-=item *
-
Once the JSON-RPC 2.0 spec is finalized, this module may need to change to support any last minute changes or additions.
-=back
-
=head1 SUPPORT
=over
Please sign in to comment.
Something went wrong with that request. Please try again.