Test::XML::RPC::Catalyst - Testing of Catalyst based XMLRPC applications


Test-XML-RPC-Catalyst documentation Contained in the Test-XML-RPC-Catalyst distribution.

Index


Code Index:

NAME

Top

Test::XML::RPC::Catalyst - Testing of Catalyst based XMLRPC applications

SYNOPSIS

Top

  use Test::XML::RPC::Catalyst qw/Catty/;

  my $xmlrpc = Test::XML::RPC::Catalyst->new;

  ok ($xmlrpc->call ('system.listMethods'));

DESCRIPTION

Top

This module merges Test::WWW::Mechanize::Catalyst and XML::RPC in order to provide test functionality for Catalyst based XMLRPC applications.

OVERRIDDEN METHODS

Top

new

Takes the same arguments as the constructor of XML::RPC, but is overridden to provide default arguments. If no url is specified as first argument, a default of 'http://localhost/rpc' is used. Keep in mind when specifying an url that no actual connections are made, your application is used directly so the url is only useful for specifying what path the XMLRPC access point is which by default is '/rpc'.

METHODS

Top

can_xmlrpc_methods
  $xmlrpc->can_xmlrpc_methods ([qw/foo.bar foo.baz/],'Supports my xmlrpc methods');

Tests if methods given as an arrayref in the first argument exists on the server.

For methods inherited from the superclass, see XML::RPC.

SEE ALSO

Top

Test::WWW::Mechanize::Catalyst
XML::RPC

BUGS

Top

Most software has bugs. This module probably isn't an exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Top

Anders Nor Berle <berle@cpan.org>

COPYRIGHT AND LICENSE

Top


Test-XML-RPC-Catalyst documentation Contained in the Test-XML-RPC-Catalyst distribution.

package Test::XML::RPC::Catalyst;

use strict;
use warnings;

use Test::Builder ();
use Test::WWW::Mechanize::Catalyst ();

use base qw/XML::RPC/;

our $VERSION = '0.01';

my $Test = Test::Builder->new;

sub new {
  my ($class,$uri,%attrs) = @_;

  $uri ||= 'http://localhost/rpc';

  $attrs{lwp_useragent} ||= Test::WWW::Mechanize::Catalyst->new;

  my $self = $class->SUPER::new ($uri,%attrs);

  return $self;
};

sub import { Test::WWW::Mechanize::Catalyst::import (@_) }

sub can_xmlrpc_methods {
  my ($self,$can_methods,$message) = @_;

  die "Method list must be an arrayref!\n" unless ref $can_methods eq 'ARRAY';

  $message ||= 'can XMLRPC methods';

  my $server_methods = $self->call ('system.listMethods');

  unless (ref $server_methods eq 'ARRAY') {
    $Test->ok (0,$message);

    $Test->diag ('I was unable to retrieve a method list from the server');

    return;
  }

  my %server_method_map = map { $_ => 1 } @$server_methods;

  for my $can_method (@$can_methods) {
    return $Test->ok (0,$message) unless exists $server_method_map{$can_method};
  }

  $Test->ok (1,$message);

  return;
}

1;

__END__