Revision 6005
Added by Chris Jones over 13 years ago
test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java | ||
---|---|---|
28 | 28 |
import java.util.*; |
29 | 29 |
|
30 | 30 |
import edu.ucsb.nceas.MCTestCase; |
31 |
import edu.ucsb.nceas.metacat.AccessionNumber; |
|
32 |
import edu.ucsb.nceas.metacat.AccessionNumberException; |
|
31 | 33 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
32 | 34 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
33 | 35 |
import edu.ucsb.nceas.metacat.client.MetacatAuthException; |
... | ... | |
66 | 68 |
try |
67 | 69 |
{ |
68 | 70 |
IdentifierManager im = IdentifierManager.getInstance(); |
69 |
Date d1 = new Date(); |
|
70 |
String guid1 = "guid:" + d1.getTime(); |
|
71 | 71 |
|
72 | 72 |
String docid = insertTestDocument(); |
73 |
im.createSystemMetadataMapping(guid1, docid); |
|
74 | 73 |
docid = docid.substring(0, docid.lastIndexOf(".")); |
75 | 74 |
|
76 | 75 |
String gotGuid = im.getGUID(docid, 1); |
77 |
assertTrue(gotGuid.equals(guid1));
|
|
76 |
assertNotNull(gotGuid);
|
|
78 | 77 |
} |
79 | 78 |
catch(Exception e) |
80 | 79 |
{ |
... | ... | |
114 | 113 |
public void testGetLocalId() { |
115 | 114 |
ph("testGetLocalId"); |
116 | 115 |
IdentifierManager im = IdentifierManager.getInstance(); |
117 |
String docid = insertTestDocument(); |
|
118 |
String goodGuid = "test:" + docid;
|
|
119 |
im.createMapping(goodGuid, docid);
|
|
116 |
String docidWithRev = insertTestDocument();
|
|
117 |
String docid = docidWithRev.substring(0, docidWithRev.lastIndexOf("."));
|
|
118 |
String guid;
|
|
120 | 119 |
String idReturned; |
121 | 120 |
try { |
122 |
idReturned = im.getLocalId(goodGuid); |
|
123 |
assertEquals(docid, idReturned); |
|
121 |
guid = im.getGUID(docid, 1); |
|
122 |
idReturned = im.getLocalId(guid); |
|
123 |
assertEquals(docidWithRev, idReturned); |
|
124 |
|
|
124 | 125 |
} catch (McdbDocNotFoundException e) { |
125 | 126 |
fail(e.getMessage()); |
126 | 127 |
} |
... | ... | |
146 | 147 |
*/ |
147 | 148 |
public void testIdentifierExists() { |
148 | 149 |
ph("testIdentifierExists"); |
149 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
150 |
String docid = insertTestDocument(); |
|
151 |
im.createMapping("test:"+docid, docid); |
|
152 |
String goodGuid = "test:" + docid; |
|
153 |
assertTrue(im.identifierExists(goodGuid)); |
|
154 |
assertFalse(im.identifierExists(badGuid)); |
|
150 |
|
|
151 |
String goodGuid = ""; |
|
152 |
String accString = ""; |
|
153 |
String docid = ""; |
|
154 |
int rev = 0; |
|
155 |
|
|
156 |
try { |
|
157 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
158 |
accString = insertTestDocument(); |
|
159 |
AccessionNumber accNumber = new AccessionNumber(accString, "NONE"); |
|
160 |
docid = accNumber.getDocid(); |
|
161 |
rev = new Integer(accNumber.getRev()); |
|
162 |
goodGuid = im.getGUID(docid, rev); |
|
163 |
assertTrue(im.identifierExists(goodGuid)); |
|
164 |
assertFalse(im.identifierExists(badGuid)); |
|
165 |
|
|
166 |
} catch ( McdbDocNotFoundException dnfe ) { |
|
167 |
fail("The document " + docid + "couldn't be found. The error was: " + |
|
168 |
dnfe.getMessage()); |
|
169 |
|
|
170 |
} catch ( AccessionNumberException ane ) { |
|
171 |
fail("The accession number could not be created for docid" + |
|
172 |
accString + ". The error was: " + ane.getMessage()); |
|
173 |
|
|
174 |
} catch ( NumberFormatException nfe ) { |
|
175 |
fail("The revision number could not be created for docid" + |
|
176 |
accString + ". The error was: " + nfe.getMessage()); |
|
177 |
|
|
178 |
} catch ( SQLException sqle ) { |
|
179 |
fail("The accession number could not be created for docid" + |
|
180 |
accString + ". The error was: " + sqle.getMessage()); |
|
181 |
|
|
182 |
} |
|
155 | 183 |
} |
156 | 184 |
|
157 | 185 |
/** |
... | ... | |
164 | 192 |
try |
165 | 193 |
{ |
166 | 194 |
IdentifierManager im = IdentifierManager.getInstance(); |
167 |
String docid = insertTestDocument();
|
|
168 |
String guid = "test:" + docid;
|
|
195 |
String docid = "test." + new Date().getTime() + ".1";
|
|
196 |
String guid = "guid:" + docid;
|
|
169 | 197 |
im.createMapping(guid, docid); |
170 | 198 |
String guiddocid = docid.substring(0, docid.length() - 2); |
171 | 199 |
System.out.println("guiddocid: " + guiddocid); |
... | ... | |
188 | 216 |
try |
189 | 217 |
{ |
190 | 218 |
IdentifierManager im = IdentifierManager.getInstance(); |
191 |
String docid = insertTestDocument();
|
|
192 |
String guid = "test:" + docid;
|
|
219 |
String docid = "test." + new Date().getTime() + ".1";
|
|
220 |
String guid = "guid:" + docid;
|
|
193 | 221 |
im.createSystemMetadataMapping(guid, docid); |
194 | 222 |
String docid2 = im.getSystemMetadataLocalId(guid); |
195 | 223 |
assertTrue(docid2.equals(docid)); |
... | ... | |
204 | 232 |
*/ |
205 | 233 |
public void testGenerateLocalId() { |
206 | 234 |
IdentifierManager im = IdentifierManager.getInstance(); |
207 |
String localid = im.generateLocalId("mynewid.1.3.3.2", 1);
|
|
235 |
String localid = im.generateLocalId("mynewid." + new Date().getTime(), 1);
|
|
208 | 236 |
System.out.println("localid: " + localid); |
209 | 237 |
assertTrue(localid != null); |
210 | 238 |
} |
Also available in: Unified diff
Now that MetacatHandler creates GUID identifier mappings and system metadata, many of the tests in IdentifierManagerTest were failing that were manually creating id mappings and system metadata.
Modified testCreateMapping() and testCreateSystemMetadataMapping() to use docids that haven't been inserted to just exercise the methods.
Modified testGetLocalId() and testIdentifierExists()to use the GUID that was generated via MetacatHandler to get the local id.
Modified testGenerateLocalId() to use a unique docid (from a datetime) since it was failing using the same fixed docid.