@@ -1,5 +1,8 @@
Revision history for Perl extension Catalyst::Plugin::XMLRPC
+0.06 Sun Nov 20 00:00:00 2005
+ - Added live tests
+
0.05 Sun Nov 20 00:00:00 2005
- Fixed bugs
@@ -5,5 +5,8 @@ README
t/01use.t
t/02pod.t
t/03podcoverage.t
+t/04live.t
+t/lib/TestApp.pm
+t/lib/TestApp/Controller/Plugin/XMLRPC.pm
XMLRPC.pm
META.yml Module meta-data (added by MakeMaker)
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Catalyst-Plugin-XMLRPC
-version: 0.05
+version: 0.06
version_from: XMLRPC.pm
installdirs: site
requires:
@@ -8,7 +8,7 @@ use RPC::XML::Parser;
use Catalyst::Action;
use Catalyst::Utils;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
__PACKAGE__->mk_classdata('_xmlrpc_parser');
__PACKAGE__->_xmlrpc_parser( RPC::XML::Parser->new );
@@ -178,11 +178,12 @@ L<Catalyst::Response>, L<Catalyst::Helper>, L<RPC::XML>
Sebastian Riedel, C<sri@oook.de>
Marcus Ramberg, C<mramberg@cpan.org>
Christian Hansen
+Yoshinori Sano
=head1 LICENSE
-This library is free software . You can redistribute it and/or modify
-it under the same terms as perl itself.
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
=cut
@@ -0,0 +1,66 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 8;
+use Catalyst::Test 'TestApp';
+use RPC::XML;
+
+BEGIN {
+ no warnings 'redefine';
+
+ * Catalyst::Test::local_request = sub {
+ my ( $class, $request ) = @_;
+
+ require HTTP::Request::AsCGI;
+ my $cgi = HTTP::Request::AsCGI->new($request, %ENV)->setup;
+
+ $class->handle_request;
+
+ return $cgi->restore->response;
+ };
+}
+
+# init
+$RPC::XML::ENCODING='UTF-8';
+my $entrypoint = 'http://localhost/rpc';
+
+run_tests();
+
+sub run_tests {
+ # test echo
+ {
+ my $content = RPC::XML::request->new( 'echo', 'hello' )->as_string;
+ my $request = HTTP::Request->new( POST => $entrypoint );
+ $request->header( 'Content-Length' => length($content) );
+ $request->header( 'Content-Type' => 'text/xml' );
+ $request->content( $content );
+
+ ok ( my $response = request( $request ), 'Request' );
+ ok ( $response->is_success, 'Response Successful 2xx' );
+ is ( $response->code, 200, 'Response Code' );
+
+ my $expected = RPC::XML::response->new( 'hello' )->as_string;
+ is ( $response->content, $expected, 'Content OK' );
+ }
+
+ # test add
+ {
+ my $content = RPC::XML::request->new( 'add', (1, 2) )->as_string;
+ my $request = HTTP::Request->new( POST => $entrypoint );
+ $request->header( 'Content-Length' => length($content) );
+ $request->header( 'Content-Type' => 'text/xml' );
+ $request->content( $content );
+
+ ok ( my $response = request( $request ), 'Request' );
+ ok ( $response->is_success, 'Response Successful 2xx' );
+ is ( $response->code, 200, 'Response Code' );
+
+ my $expected = RPC::XML::response->new( '3' )->as_string;
+ is ( $response->content, $expected, 'Content OK' );
+ }
+}
@@ -0,0 +1,26 @@
+package TestApp::Controller::Plugin::XMLRPC;
+
+use strict;
+use base 'Catalyst::Controller';
+
+sub begin : Private {
+ my ( $self, $c ) = @_;
+ $c->res->header( 'X-Test-Class' => ref($self) );
+}
+
+sub rpc : Global {
+ my ( $self, $c ) = @_;
+ $c->xmlrpc;
+}
+
+sub echo : Remote {
+ my ( $self, $c, @args ) = @_;
+ return join ' ', @args;
+}
+
+sub add : Remote {
+ my ( $self, $c, $a, $b) = @_;
+ return $a + $b;
+}
+
+1;
@@ -0,0 +1,12 @@
+package TestApp;
+
+use strict;
+use Catalyst qw/XMLRPC/;
+
+our $VERSION = '0.01';
+
+TestApp->config( name => 'TestApp', root => '/some/dir' );
+
+TestApp->setup;
+
+1;