File: object.t

package info (click to toggle)
libjson-rpc-common-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 244 kB
  • sloc: perl: 1,481; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More 'no_plan';

use JSON::RPC::Common::Procedure::Call;

{
	package Foo;
	use Moose;

	sub hello {
		my ( $self, %args ) = @_;
		return "hello " . $args{greet};
	}
}

{
	my $call = JSON::RPC::Common::Procedure::Call->new(
		method => "hello",
		params  => { greet => "world" },
	);

	isa_ok( $call, "JSON::RPC::Common::Procedure::Call" );

	can_ok( $call, "call" );

	my $res = $call->call( Foo->new );

	isa_ok( $res, "JSON::RPC::Common::Procedure::Return" );

	ok( $res->has_result, "has result" );
	is( $res->result, "hello world", "result" );

	ok( !$res->has_error, "no error" );
}

{
	my $call = JSON::RPC::Common::Procedure::Call->new(
		method => "does_not_exist",
		params => { },
	);

	my $res = $call->call( Foo->new );

	isa_ok( $res, "JSON::RPC::Common::Procedure::Return" );

	ok( !$res->has_result, "no result" );
	ok( $res->has_error, "has error" );

	isa_ok( $res->error, "JSON::RPC::Common::Procedure::Return::Error" );

	like( $res->error->message, qr/does_not_exist/, "error talks about non existent method" );
}