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 69
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use warnings;
use strict;
use Test::More tests => 8;
BEGIN { use_ok('Net::Amazon') };
use Net::Amazon::Request::UPC;
use Net::Amazon::Response::UPC;
use File::Spec;
my $CANNED = "canned";
$CANNED = File::Spec->catfile("t", "canned") unless -d $CANNED;
#Only for debugging
#use Log::Log4perl qw(:easy);
#Log::Log4perl->easy_init($DEBUG);
######################################################################
# Successful UPC fetch
######################################################################
canned("upc_zwan.xml");
my $ua = Net::Amazon->new(
token => 'YOUR_AMZN_TOKEN',
);
my $req = Net::Amazon::Request::UPC->new(
upc => '093624843627',
mode => 'music',
);
# Response is of type Net::Amazon::UPC::Response
my $resp = $ua->request($req);
ok($resp->is_success(), "Successful fetch");
like($resp->as_string(), qr#Mary Star of the Sea#, "Found Zwan");
like($resp->as_string(), qr#Zwan#, "Found Zwan");
######################################################################
# Parameters
######################################################################
my $p = ($resp->properties)[0];
is($p->artist(), "Zwan", "Artist is Zwan");
is($p->album(), "Mary Star of the Sea", "Album is Mary Star of the Sea");
is($p->year(), "2003", "Year is 2003");
is($p->label(), "Warner Brothers", "Label is Warner Brothers");
######################################################################
# handle canned responses
######################################################################
sub canned {
my($file) = @_;
if(! exists $ENV{NET_AMAZON_LIVE_TESTS} ) {
$file = File::Spec->catfile($CANNED, $file);
open FILE, "<$file" or die "Cannot open $file";
my $data = join '', <FILE>;
close FILE;
push @Net::Amazon::CANNED_RESPONSES, $data;
}
}
|