3 use Test::More tests => 14;
5 diag("Test circulation of item CONC70000345 against the admin user.");
7 use constant WORKSTATION_NAME => 'BR4-test-02-simple-circ.t';
8 use constant WORKSTATION_LIB => 7;
9 use constant ITEM_BARCODE => 'CONC70000345';
10 use constant ITEM_ID => 310;
16 use OpenSRF::AppSession;
17 use Digest::MD5 qw(md5_hex);
18 use OpenILS::Utils::Fieldmapper;
19 use OpenILS::Application::AppUtils;
20 use OpenSRF::Utils::SettingsClient;
23 our $cache = "OpenSRF::Utils::Cache";
24 our $apputils = "OpenILS::Application::AppUtils";
29 #----------------------------------------------------------------
31 #----------------------------------------------------------------
33 my ($pkg, $file, $line, $sub) = _caller();
35 die "Script halted with error ".
36 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
39 #----------------------------------------------------------------
40 # This is not the function you're looking for
41 #----------------------------------------------------------------
43 my ($pkg, $file, $line, $sub) = caller(2);
45 ($pkg, $file, $line) = caller(1);
48 return ($pkg, $file, $line, $sub);
51 #----------------------------------------------------------------
52 # Connect to the servers
53 #----------------------------------------------------------------
55 my $config = `osrf_config --sysconfdir`;
57 $config .= '/opensrf_core.xml';
58 err("Bootstrap config required") unless $config;
59 OpenSRF::System->bootstrap_client( config_file => $config );
60 Fieldmapper->import(IDL =>
61 OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
64 #----------------------------------------------------------------
65 # Is the given object an OILS event?
66 #----------------------------------------------------------------
69 if( $e and ref($e) eq 'HASH' ) {
70 return 1 if defined($e->{ilsevent});
75 #----------------------------------------------------------------
76 # If the given object is an event, this prints the event info
77 # and exits the script
78 #----------------------------------------------------------------
81 my ($pkg, $file, $line, $sub) = _caller();
82 if(oils_is_event($evt)) {
83 if($evt->{ilsevent}) {
84 diag("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
90 #----------------------------------------------------------------
91 # Login to the auth server and set the global $authtoken var
92 #----------------------------------------------------------------
94 my( $username, $password, $type, $ws ) = @_;
98 my $seed = $apputils->simplereq( 'open-ils.auth',
99 'open-ils.auth.authenticate.init', $username );
100 err("No auth seed") unless $seed;
102 my $response = $apputils->simplereq( 'open-ils.auth',
103 'open-ils.auth.authenticate.complete',
104 { username => $username,
105 password => md5_hex($seed . md5_hex($password)),
106 type => $type, workstation => $ws });
108 err("No auth response returned on login") unless $response;
110 oils_event_die($response);
112 $authtime = $response->{payload}->{authtime};
113 $authtoken = $response->{payload}->{authtoken};
114 diag("authtime is $authtime, authtoken is $authtoken");
118 #----------------------------------------------------------------
119 # Destroys the login session on the server
120 #----------------------------------------------------------------
122 $apputils->simplereq(
124 'open-ils.auth.session.delete', (@_ ? shift : $authtoken) );
127 #----------------------------------------------------------------
128 # var $response = simplereq( $service, $method, @params );
129 #----------------------------------------------------------------
130 sub simplereq { return $apputils->simplereq(@_); }
131 sub osrf_request { return $apputils->simplereq(@_); }
133 #----------------------------------------------------------------
135 sub register_workstation {
136 my $resp = osrf_request(
138 'open-ils.actor.workstation.register',
139 $authtoken, WORKSTATION_NAME, WORKSTATION_LIB);
144 my( $patronid, $barcode ) = @_;
145 my $args = { patron => $patronid, barcode => $barcode };
146 my $resp = osrf_request(
148 'open-ils.circ.checkout.full', $authtoken, $args );
154 my $args = { barcode => $barcode };
155 my $resp = osrf_request(
157 'open-ils.circ.checkin', $authtoken, $args );
161 #----------------------------------------------------------------
162 # The tests... assumes stock sample data, full-auto install by
163 # eg_wheezy_installer.sh, etc.
164 #----------------------------------------------------------------
167 my $storage_ses = OpenSRF::AppSession->create('open-ils.storage');
169 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
170 if (my $user_resp = $user_req->recv) {
171 if (my $user = $user_resp->content) {
174 'Fieldmapper::actor::user',
175 'open-ils.storage.direct.actor.user.retrieve returned aou object'
180 'User with id = 1 is admin user'
185 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
186 if (my $item_resp = $item_req->recv) {
187 if (my $item = $item_resp->content) {
190 'Fieldmapper::asset::copy',
191 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
196 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
199 $item->status == 7 || $item->status == 0,
200 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
205 oils_login('admin','demo123','staff');
210 my $ws = register_workstation();
213 'Registered a new workstation'
217 oils_login('admin','demo123','staff',WORKSTATION_NAME);
220 'Have an authtoken associated with the workstation'
223 my $checkout_resp = do_checkout(1, ITEM_BARCODE);
227 'Checkout request returned a HASH'
230 $checkout_resp->{ilsevent},
232 'Checkout returned a SUCCESS event'
235 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', 310);
236 if (my $item_resp = $item_req->recv) {
237 if (my $item = $item_resp->content) {
241 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
246 my $checkin_resp = do_checkin(ITEM_BARCODE);
250 'Checkin request returned a HASH'
253 $checkin_resp->{ilsevent},
255 'Checkin returned a SUCCESS event'
258 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
259 if (my $item_resp = $item_req->recv) {
260 if (my $item = $item_resp->content) {
262 $item->status == 7 || $item->status == 0,
263 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'