1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use JSON::RPC::Common::Procedure::Call;
{
my $req_data = {
method => "hello",
id => "foo",
params => [ 1 .. 3 ],
};
my $req_obj = JSON::RPC::Common::Procedure::Call->inflate($req_data);
isa_ok( $req_obj, "JSON::RPC::Common::Procedure::Call" );
isa_ok( $req_obj, "JSON::RPC::Common::Procedure::Call::Version_1_0" );
is_deeply( $req_obj->deflate, $req_data, "round trip through deflate" );
is( $req_obj->version, "1.0", "version" );
ok( $req_obj->has_id, "has_id" );
is( $req_obj->id, "foo", "id value" );
ok( !$req_obj->is_notification, "not a notification" );
ok( !$req_obj->is_service, "not a service req" );
is_deeply( $req_obj->params, [ 1 .. 3 ], "params" );
is_deeply( [ $req_obj->params_list ], [ 1 .. 3 ], "params_list" );
my $res = $req_obj->return_result("moose");
isa_ok( $res, "JSON::RPC::Common::Procedure::Return" );
isa_ok( $res, "JSON::RPC::Common::Procedure::Return::Version_1_0" );
is_deeply( $res->deflate, { result => "moose", error => undef, id => "foo" }, "deflated" );
my $res_passthrough = JSON::RPC::Common::Procedure::Return->inflate($res->deflate);
isa_ok( $res_passthrough, "JSON::RPC::Common::Procedure::Return", "reinflate result" );
ok( !$res_passthrough->has_error, "no error" );
is( $res->id, "foo", "ID" );
is( $res->result, "moose", "result" );
}
{
my $req_data = {
method => "hello",
id => undef,
params => [ 1 .. 3 ],
};
my $req_obj = JSON::RPC::Common::Procedure::Call->inflate($req_data);
isa_ok( $req_obj, "JSON::RPC::Common::Procedure::Call" );
isa_ok( $req_obj, "JSON::RPC::Common::Procedure::Call::Version_1_0" );
is( $req_obj->version, "1.0", "version" );
ok( $req_obj->has_id, "has_id" );
ok( $req_obj->is_notification, "not a notification" );
}
|