Froody
view release on metacpan or search on metacpan
#!/usr/bin/perl -w
#########################################################################
# This tests loads an xml based API (Testobject::API) and makes sure that
# the right things are set up in the repository
#########################################################################
use strict;
use lib 't/lib';
use Data::Dumper;
# colourising the output if we want to
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
use Test::More tests => 49;
use Test::Exception;
use Test::Differences;
# this is where we keep our modules
use Froody::Repository;
use Test::Logger;
use Scalar::Util qw(blessed);
# load our test API
use_ok ('Testproject::API');
{
my @stuff = Testproject::API->load();
# Check we got our methods back
my @methods = grep { blessed($_) && $_->isa("Froody::Method") } @stuff;
my $methods = { map { $_->full_name => 1 } @methods };
# Check we got our error types back
my @et = grep { blessed($_) && $_->isa("Froody::ErrorType") } @stuff;
is(@et, 2, "got two error types back from the api");
my $et = { map { $_->name => 1 } @et };
is_deeply($et, { map { $_ => 1 } qw(
foo.fish
foo.fish.fred
)},"got the right error type names")
}
# ignore the previous methods, and just load up Testproject::Service
# that will register them for us
use_ok("Testproject::Object");
my $repos = Froody::Repository->new();
Testproject::Object->register_in_repository($repos);
# okay, so I removed the ability for the framework to be called on just
# method names, now you need to invoke with a proper Froody::Method. This
# makes sense from the way the API is now used (since nothing but the
# method object should really be calling invoke,) but makes testing a bit more
# painful.
my $email = $repos->get_method('testproject.object.email');
my $text = $repos->get_method('testproject.object.text');
my $sum = $repos->get_method('testproject.object.sum');
my $texttest = $repos->get_method('testproject.object.texttest');
my $extra = $repos->get_method('testproject.object.extra');
my $range = $repos->get_method('testproject.object.range');
my $range2 = $repos->get_method('testproject.object.range2');
my $params = $repos->get_method('testproject.object.params');
my $get = $repos->get_method('testproject.object.get');
foreach ($email, $text, $sum, $texttest, $extra, $range, $range2, $params)
{ isa_ok($_, 'Froody::Method') }
my $metadata = { repository => $repos, dispatcher => Froody::Dispatch->new };
{
my $resp = $email->call({ email_trim => 'test@fotango.com'}, $metadata);
is( $resp->status, 'ok' );
}
{
my $resp = $email->call({ email_trim => ' test@fotango.com '}, $metadata);
( run in 1.863 second using v1.01-cache-2.11-cpan-39bf76dae61 )