Project

General

Profile

1 1929 brooke
 #
2
 #  '$RCSfile$'
3
 #  Copyright: 2000 Regents of the University of California
4
 #
5
 #   '$Author$'
6
 #     '$Date$'
7
 # '$Revision$'
8
 #
9
 # This program is free software; you can redistribute it and/or modify
10
 # it under the terms of the GNU General Public License as published by
11
 # the Free Software Foundation; either version 2 of the License, or
12
 # (at your option) any later version.
13
 #
14
 # This program is distributed in the hope that it will be useful,
15
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 # GNU General Public License for more details.
18
 #
19
 # You should have received a copy of the GNU General Public License
20
 # along with this program; if not, write to the Free Software
21
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 #
23
24
# Before `make install' is performed this script should be runnable with
25
# `make test'. After `make install' it should work as `perl test.pl'
26
27
######################### We start with some black magic to print on failure.
28
29
# Change 1..1 below to 1..last_test_to_print .
30
# (It may become useful if the test is moved to ./t subdirectory.)
31
32
BEGIN { $| = 1; print "1..1\n"; }
33
END {print "not ok 1\n" unless $loaded;}
34
use Metacat;
35
$loaded = 1;
36
print "ok 1\n";
37
38
######################### End of black magic.
39
40
# Insert your test code below (better if it prints "ok 13"
41
# (correspondingly "not ok 13") depending on the success of chunk 13
42
# of the test code):
43
my $metacatUrl = "http://dev.nceas.ucsb.edu/jones/servlet/metacat";
44
my $username = 'jones';
45
my $password = 'your-pw-goes-here';
46
47
# Set up a date stamp
48
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
49
if ($min < 10) {
50
   $minstr = "0".$min;
51
} else {
52
   $minstr = $min;
53
}
54
if ($sec < 10) {
55
   $secstr = "0".$sec;
56
} else {
57
   $secstr = $sec;
58
}
59
my $thismon=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
60
my $timenow="$mday-$thismon-$year $hour:$minstr:$secstr";
61
62
# Set up a document accession number to use
63
my $docroot = "$thismon$mday.$minstr.";
64
my $docrev = 1;
65
66
# Chunk 2: Test metacat object creation
67
my $metacat = Metacat->new();
68
if ($metacat) {
69
  $metacat->set_options( metacatUrl => $metacatUrl );
70
  print "ok 2 metacat creation\n";
71
} else {
72
  print "not ok 2 metacat creation\n";
73
}
74
75
# Chunk 3: Test metacat login
76
my $response = $metacat->login($username, $password);
77
if ($response) {
78
  print "ok 3 login\n";
79
} else {
80
  print $metacat->getMessage();
81
  print "not ok 3 login\n";
82
}
83
84
# Chunk 4: Test metacat insert
85
my $xmldoc = "<?xml version=\"1.0\"?><moviedb><movie>Scream</movie></moviedb>";
86
my $response = $metacat->insert($docroot . $docrev, $xmldoc);
87
if ($response) {
88
  print "ok 4 insert\n";
89
} else {
90
  print $metacat->getMessage();
91
  print "not ok 4 insert\n";
92
}
93
94
# Chunk 5: Test metacat update
95
$xmldoc = "<?xml version=\"1.0\"?><moviedb><movie>Scream 2</movie></moviedb>";
96
$docrev++;
97
my $response = $metacat->update("$docroot" . "$docrev", $xmldoc);
98
if ($response) {
99
  print "ok 5 update\n";
100
} else {
101
  print $metacat->getMessage();
102
  print "not ok 5 update\n";
103
}
104
105
# Chunk 6: Test metacat read
106
my $response = $metacat->read("$docroot" . "$docrev");
107
if ($response) {
108
  print "ok 6 read\n";
109
} else {
110
  print $metacat->getMessage();
111
  print "not ok 6 read\n";
112
}
113
114
# Chunk 7: Test metacat squery
115
my $pathquery = "<?xml version=\"1.0\"?><pathquery version=\"1.1\"><querygroup operator=\"UNION\"><queryterm searchmode=\"contains\" casesensitive=\"false\"><value>Scream</value></queryterm></querygroup></pathquery>";
116
my $response = $metacat->squery($pathquery);
117
if ($response) {
118
  print "ok 7 squery\n";
119
} else {
120
  print $metacat->getMessage();
121
  print "not ok 7 squery\n";
122
}
123
124
# Chunk 8: Test metacat delete
125
my $response = $metacat->delete("$docroot" . "$docrev");
126
if ($response) {
127
  print "ok 8 delete\n";
128
} else {
129
  print $metacat->getMessage();
130
  print "not ok 8 delete\n";
131
}