Changeset 6584
- Timestamp:
- Mar 14, 2006, 1:24:05 PM (20 years ago)
- Location:
- trunk/DataStore
- Files:
-
- 2 edited
-
lib/DataStore/Product.pm (modified) (3 diffs)
-
t/05_product.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/lib/DataStore/Product.pm
r6538 r6584 1 1 # Copyright (C) 2006 Joshua Hoblitt 2 2 # 3 # $Id: Product.pm,v 1. 2 2006-03-08 00:02:43jhoblitt Exp $3 # $Id: Product.pm,v 1.3 2006-03-14 23:24:05 jhoblitt Exp $ 4 4 5 5 package DataStore::Product; … … 14 14 15 15 use Carp qw( carp ); 16 use DataStore::FileSet::Parser; 16 17 use DataStore::Record; 18 use DataStore::Response; 19 use LWP::UserAgent; 17 20 use Params::Validate qw( validate SCALAR); 18 21 … … 108 111 sub request 109 112 { 113 my $self = shift; 110 114 115 # no params 116 validate(@_, {}); 117 118 # make request 119 my $ua = LWP::UserAgent->new; 120 my $request = HTTP::Request->new(GET => $self->uri); 121 my $response = $ua->request($request); 122 123 if (! $response->is_success) { 124 carp $response->status_line; 125 return undef; 126 } 127 128 # parse document 129 my $parser = DataStore::FileSet::Parser->new; 130 131 my $data = $parser->parse($response->content); 132 133 unless ($data) { 134 carp "Product contains no FileSets"; 135 return undef; 136 } 137 138 139 # return DS::Response object 140 my $dsr = DataStore::Response->new( 141 is_success => 1, 142 code => $response->code, 143 status_line => $response->status_line, 144 data => $data, 145 request => $self, 146 ); 111 147 } 112 113 148 114 149 1; -
trunk/DataStore/t/05_product.t
r6538 r6584 3 3 # Copyright (C) 2006 Joshua Hoblitt 4 4 # 5 # $Id: 05_product.t,v 1. 1 2006-03-08 00:02:43jhoblitt Exp $5 # $Id: 05_product.t,v 1.2 2006-03-14 23:24:05 jhoblitt Exp $ 6 6 7 7 use strict; … … 10 10 use lib qw( ./lib ./t ); 11 11 12 use Test::More tests => 10;12 use Test::More tests => 21; 13 13 14 14 =head1 NAME … … 99 99 # ->request() 100 100 101 use Net::HTTPServer; 102 103 sub bar 104 { 105 my $req = shift; # Net::HTTPServer::Request object 106 my $res = $req->Response(); # Net::HTTPServer::Response object 107 108 my $string = <<END; 109 # filesetID|time registered |type |telescope pointing |etime|f|airmass| 110 otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23 | 111 otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23 | 112 otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23 | 113 otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23 | 114 END 115 116 $res->Print($string); 117 118 return $res; 119 } 120 121 $|++; 122 123 $SIG{CHLD} = 'IGNORE'; 124 my $pid = open(my $child, "-|"); 125 126 unless ($pid) { 127 my $server = new Net::HTTPServer( port => 'scan' ); 128 129 # send port number to parent 130 print $server->Start(), "\n"; 131 132 $server->RegisterURL('/', \&bar); 133 $server->Process(); # Run forever 134 135 exit -1; 136 } 137 138 my $port = <$child>; 139 chomp $port; 140 141 { 142 my $dsp = DataStore::Product->new( uri => "http://localhost:$port/" ); 143 144 isa_ok($dsp->request, 'DataStore::Response'); 145 } 146 147 { 148 my $dsp = DataStore::Product->new( uri => "http://localhost:$port/" ); 149 150 my $dsr = $dsp->request; 151 152 ok($dsr->is_success, "response->is_success() is correct"); 153 is($dsr->code, 200, "response->code() is correct"); 154 is($dsr->status_line, "200 OK", "response->status_line() is correct"); 155 is(ref $dsr->data, 'ARRAY', "response->data is arrayref is correct"); 156 isa_ok($dsr->request, 'DataStore::Record'); 157 158 my $data = $dsr->data; 159 is(scalar @$data, 4, "data has the correct number of rows"); 160 isa_ok(@$data[0], 'DataStore::FileSet', "data has correct type of rows"); 161 isa_ok(@$data[1], 'DataStore::FileSet', "data has correct type of rows"); 162 isa_ok(@$data[2], 'DataStore::FileSet', "data has correct type of rows"); 163 isa_ok(@$data[3], 'DataStore::FileSet', "data has correct type of rows"); 164 } 165 166 # cleanup HTTP server 167 kill 9, $pid;
Note:
See TracChangeset
for help on using the changeset viewer.
