Revision 9120
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java | ||
---|---|---|
29 | 29 |
import java.sql.SQLException; |
30 | 30 |
import java.util.*; |
31 | 31 |
|
32 |
import org.dataone.client.v2.itk.D1Client; |
|
32 | 33 |
import org.dataone.service.types.v1.Identifier; |
34 |
import org.dataone.service.types.v1.NodeType; |
|
33 | 35 |
import org.dataone.service.types.v1.Session; |
36 |
import org.dataone.service.types.v1.Subject; |
|
37 |
import org.dataone.service.types.v2.Node; |
|
38 |
import org.dataone.service.types.v2.NodeList; |
|
34 | 39 |
import org.dataone.service.types.v2.SystemMetadata; |
35 | 40 |
|
36 | 41 |
import edu.ucsb.nceas.MCTestCase; |
... | ... | |
41 | 46 |
import edu.ucsb.nceas.metacat.client.MetacatAuthException; |
42 | 47 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
43 | 48 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
49 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
|
44 | 50 |
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest; |
45 | 51 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
46 | 52 |
|
53 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
|
54 |
import org.dataone.service.exceptions.ServiceFailure; |
|
55 |
|
|
47 | 56 |
public class IdentifierManagerTest extends D1NodeServiceTest { |
48 | 57 |
private String badGuid = "test:testIdThatDoesNotExist"; |
49 | 58 |
|
... | ... | |
305 | 314 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
306 | 315 |
assertTrue(IdentifierManager.getInstance().getHeadPID(non_exist_sid) == null); |
307 | 316 |
|
317 |
//case-2 |
|
318 |
object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
319 |
Identifier pid1_case2 = new Identifier(); |
|
320 |
pid1_case2.setValue(generateDocumentId()); |
|
321 |
String sid_case2_str= "sid."+System.nanoTime(); |
|
322 |
Identifier sid_case2 = new Identifier(); |
|
323 |
sid_case2.setValue(sid_case2_str); |
|
324 |
SystemMetadata sysmeta_case2 = createSystemMetadata(pid1_case2, session.getSubject(), object); |
|
325 |
sysmeta_case2.setSeriesId(sid_case2); |
|
326 |
CNodeService.getInstance(request).create(session, pid1_case2, object, sysmeta_case2); |
|
327 |
|
|
328 |
Thread.sleep(1000); |
|
329 |
Identifier pid2_case2 = new Identifier(); |
|
330 |
pid2_case2.setValue(generateDocumentId()); |
|
331 |
sysmeta = createSystemMetadata(pid2_case2, session.getSubject(), object); |
|
332 |
sysmeta.setSeriesId(sid_case2); |
|
333 |
try { |
|
334 |
CNodeService.getInstance(request).create(session, pid2_case2, object, sysmeta); |
|
335 |
fail("we shouldn't get here and an InvalidSystemMetacat exception should be thrown."); |
|
336 |
} catch (InvalidSystemMetadata e) { |
|
337 |
System.out.println("case 2======= Invalid system metadata"); |
|
338 |
} |
|
339 |
|
|
308 | 340 |
} catch (Exception e) { |
309 | 341 |
fail(e.getMessage()); |
310 | 342 |
} |
... | ... | |
338 | 370 |
{ |
339 | 371 |
System.out.println("*********************** " + s + " ****************************"); |
340 | 372 |
} |
373 |
|
|
374 |
/** |
|
375 |
* We want to act as the CN itself |
|
376 |
* @throws ServiceFailure |
|
377 |
* @throws Exception |
|
378 |
*/ |
|
379 |
@Override |
|
380 |
public Session getTestSession() throws Exception { |
|
381 |
Session session = super.getTestSession(); |
|
382 |
|
|
383 |
// use the first CN we find in the nodelist |
|
384 |
NodeList nodeList = D1Client.getCN().listNodes(); |
|
385 |
for (Node node : nodeList.getNodeList()) { |
|
386 |
if ( node.getType().equals(NodeType.CN) ) { |
|
387 |
|
|
388 |
List<Subject> subjects = node.getSubjectList(); |
|
389 |
for (Subject subject : subjects) { |
|
390 |
session.setSubject(subject); |
|
391 |
// we are done here |
|
392 |
return session; |
|
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
// in case we didn't find it |
|
397 |
return session; |
|
398 |
} |
|
399 |
|
|
341 | 400 |
} |
Also available in: Unified diff
Add test cases for the method getHeadPID.