#!/usr/bin/perl -w # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { sub POE::Kernel::ASSERT_SESSIONS {1} sub POE::Kernel::ASSERT_USAGE {1} sub POE::Kernel::ASSERT_RETURNS {1} } BEGIN { $| = 1; print "1..11\n"; } END {print "not ok 1\n" unless $loaded;} use lib qw(/home/fil/prive/perl5lib/lib/site_perl); use POE; use POE::Component::UPS::RSS; use Data::Dumper; $loaded = 1; print "ok 1\n"; use strict; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): POE::Component::UPS::RSS->spawn(); POE::Session->create( inline_states=>{ _start=>\&_start, input1=>\&input1, input2=>\&input2, }, ); sub _start { my($kernel, $heap)=@_[KERNEL, HEAP]; $kernel->alias_set('hello'); $kernel->post(UPS=>request=>input1=>1, HTTP::Request->new (GET => "https://www.ups.com/ups.app/xml/Rate")); } sub input1 { my($kernel, $id, $resp)=@_[KERNEL, ARG0, ARG1]; print "ok 3\n"; if($resp->{Error}) { # internal error print $resp->{Error}; print "not "; } elsif('HASH' eq ref $resp) { # should be HTTP::Response print "not "; } print "ok 4\n"; ################################### my $req={Shipper=>{PostalCode=>'J4Y 2R2', Country=>'CA'}, ShipTo=>{PostalCode=>'J4H 1W4', Country=>'CA', ResidentialAddress=>0}, Weight=>0.1, CustomerContext=>'The world is my oyster', AccessLicenseNumber=>'AB673E1FC77D1ABC', UserId=>'leblanc001', Password=>'leblancca' }; $kernel->post(UPS=>request=>input2=>1, $req); } sub input2 { my($kernel, $id, $resp)=@_[KERNEL, ARG0, ARG1]; print "ok 5\n"; use Data::Denter; my $q=6; unless('HASH' eq ref $resp) { # shouldn't be HTTP::Response die "Why didn't I get a hashref back? ", Dumper $resp; } elsif(not $resp->{Error}) { # no errors please print "ok ", $q++, "\n"; print Denter($resp); print "not " unless $resp->{CustomerContext} eq 'The world is my oyster'; print "ok ", $q++, "\n"; # TODO: we have to have an example to process } else { print Denter($resp); } foreach ($q..11) { print "not ok $_\n"; } } $poe_kernel->run(); __END__ my $foo=[ 'HTTP/1.1 200 OK', 'Server: Netscape-Enterprise/4.1', 'Date: Thu, 18 Oct 2001 20:39:28 GMT', 'Connection: close', 'Content-type: application/xml', 'Pragma: no-cache', 'Connection: close', '', '', '', ' ', ' ', ' 0', ' Failure', ' ', ' Hard', ' 250002', ' Invalid UserId/Password', ' ', ' ', '' ];