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 |
8265
|
leinfelder
|
my $metacatUrl = "http://snow.joneseckert.org:8080/metacat/metacat";
|
44 |
1953
|
jones
|
my $username = 'uid=jones,o=NCEAS,dc=ecoinformatics,dc=org';
|
45 |
1929
|
brooke
|
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 |
1953
|
jones
|
my $scope = "$thismon$mday";
|
64 |
|
|
my $docroot = "$scope.$minstr.";
|
65 |
1929
|
brooke
|
my $docrev = 1;
|
66 |
|
|
|
67 |
|
|
# Chunk 2: Test metacat object creation
|
68 |
|
|
my $metacat = Metacat->new();
|
69 |
|
|
if ($metacat) {
|
70 |
|
|
$metacat->set_options( metacatUrl => $metacatUrl );
|
71 |
|
|
print "ok 2 metacat creation\n";
|
72 |
|
|
} else {
|
73 |
|
|
print "not ok 2 metacat creation\n";
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
# Chunk 3: Test metacat login
|
77 |
|
|
my $response = $metacat->login($username, $password);
|
78 |
|
|
if ($response) {
|
79 |
|
|
print "ok 3 login\n";
|
80 |
|
|
} else {
|
81 |
|
|
print $metacat->getMessage();
|
82 |
|
|
print "not ok 3 login\n";
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
# Chunk 4: Test metacat insert
|
86 |
|
|
my $xmldoc = "<?xml version=\"1.0\"?><moviedb><movie>Scream</movie></moviedb>";
|
87 |
|
|
my $response = $metacat->insert($docroot . $docrev, $xmldoc);
|
88 |
|
|
if ($response) {
|
89 |
|
|
print "ok 4 insert\n";
|
90 |
|
|
} else {
|
91 |
|
|
print $metacat->getMessage();
|
92 |
|
|
print "not ok 4 insert\n";
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
# Chunk 5: Test metacat update
|
96 |
|
|
$xmldoc = "<?xml version=\"1.0\"?><moviedb><movie>Scream 2</movie></moviedb>";
|
97 |
|
|
$docrev++;
|
98 |
|
|
my $response = $metacat->update("$docroot" . "$docrev", $xmldoc);
|
99 |
|
|
if ($response) {
|
100 |
|
|
print "ok 5 update\n";
|
101 |
|
|
} else {
|
102 |
|
|
print $metacat->getMessage();
|
103 |
|
|
print "not ok 5 update\n";
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
# Chunk 6: Test metacat read
|
107 |
|
|
my $response = $metacat->read("$docroot" . "$docrev");
|
108 |
|
|
if ($response) {
|
109 |
|
|
print "ok 6 read\n";
|
110 |
|
|
} else {
|
111 |
|
|
print $metacat->getMessage();
|
112 |
|
|
print "not ok 6 read\n";
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
# Chunk 7: Test metacat squery
|
116 |
|
|
my $pathquery = "<?xml version=\"1.0\"?><pathquery version=\"1.1\"><querygroup operator=\"UNION\"><queryterm searchmode=\"contains\" casesensitive=\"false\"><value>Scream</value></queryterm></querygroup></pathquery>";
|
117 |
|
|
my $response = $metacat->squery($pathquery);
|
118 |
|
|
if ($response) {
|
119 |
|
|
print "ok 7 squery\n";
|
120 |
|
|
} else {
|
121 |
|
|
print $metacat->getMessage();
|
122 |
|
|
print "not ok 7 squery\n";
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
# Chunk 8: Test metacat delete
|
126 |
|
|
my $response = $metacat->delete("$docroot" . "$docrev");
|
127 |
|
|
if ($response) {
|
128 |
|
|
print "ok 8 delete\n";
|
129 |
|
|
} else {
|
130 |
|
|
print $metacat->getMessage();
|
131 |
|
|
print "not ok 8 delete\n";
|
132 |
|
|
}
|
133 |
1953
|
jones
|
|
134 |
|
|
# Chunk 9: Test metacat getlastid
|
135 |
|
|
my $response = $metacat->getLastId("$scope");
|
136 |
|
|
if ($response) {
|
137 |
|
|
print "ok 9 getlastid ($response)\n";
|
138 |
|
|
} else {
|
139 |
|
|
print $metacat->getMessage();
|
140 |
|
|
print "not ok 9 getlastid\n";
|
141 |
|
|
}
|