Project

General

Profile

« Previous | Next » 

Revision 9126

Added by Jing Tao almost 10 years ago

Add more test cases for the method getHeadVersion.

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
280 280
            newSysMeta.setObsoletes(guid);
281 281
            newSysMeta.setSeriesId(seriesId);
282 282
            MNodeService.getInstance(request).update(session, guid, object, newPid, newSysMeta);
283
            System.out.println("case 1: =======");
283 284
            // the pid should be the newPid when we try to get the sid1
284 285
            head = IdentifierManager.getInstance().getHeadPID(seriesId);
285
            System.out.println("the head 2 is "+head.getValue());
286 286
            assertTrue(head.getValue().equals(newPid.getValue()));
287 287
            
288
            //do another update with different series id
289
            Thread.sleep(1000);
290
            String sid2 = "sid."+System.nanoTime();
291
            Identifier seriesId2= new Identifier();
292
            seriesId2.setValue(sid2);
293
            System.out.println("the second sid is "+seriesId2.getValue());
294
            Identifier newPid2 = new Identifier();
295
            newPid2.setValue(generateDocumentId()+"2");
296
            System.out.println("the third pid is "+newPid2.getValue());
297
            SystemMetadata sysmeta3 = createSystemMetadata(newPid2, session.getSubject(), object);
298
            sysmeta3.setObsoletes(newPid);
299
            sysmeta3.setSeriesId(seriesId2);
300
            MNodeService.getInstance(request).update(session, newPid, object, newPid2, sysmeta3);
301 288
            
302
            // the pid should be the newPid when we try to get the sid1
303
            head =IdentifierManager.getInstance().getHeadPID(seriesId);
304
            System.out.println("the head 3 is "+head.getValue());
305
            assertTrue(head.getValue().equals(newPid.getValue()));
306
            
307
            // the pid should be the newPid2 when we try to get the sid2
308
            head = IdentifierManager.getInstance().getHeadPID(seriesId2);
309
            System.out.println("the head 4 is "+head.getValue());
310
            assertTrue(head.getValue().equals(newPid2.getValue()));
311
            
312 289
            // the pid should be null when we try to get a no-exist sid
313 290
            Identifier non_exist_sid = new Identifier();
314 291
            non_exist_sid.setValue("no-sid-exist-123qwe");
315 292
            assertTrue(IdentifierManager.getInstance().getHeadPID(non_exist_sid) == null);
316 293
            
317 294
            //case-2
295
            // http://jenkins-1.dataone.org/documentation/unstable/API-Documentation-development/design/ContentMutability.html
318 296
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
319 297
            Identifier pid1_case2 = new Identifier();
320 298
            pid1_case2.setValue(generateDocumentId());
......
337 315
                System.out.println("case 2======= Invalid system metadata");
338 316
            }
339 317
            
318
            
319
            //case-3
320
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
321
            Identifier pid1_case3 = new Identifier();
322
            pid1_case3.setValue(generateDocumentId());
323
            String sid_case3_str= "sid."+System.nanoTime();
324
            Identifier sid_case3 = new Identifier();
325
            sid_case3.setValue(sid_case3_str);
326
            SystemMetadata sysmeta_case3 = createSystemMetadata(pid1_case3, session.getSubject(), object);
327
            sysmeta_case3.setSeriesId(sid_case3);
328
            CNodeService.getInstance(request).create(session, pid1_case3, object, sysmeta_case3);
329
            
330
            Thread.sleep(1000);
331
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
332
            Identifier pid2_case3 = new Identifier();
333
            pid2_case3.setValue(generateDocumentId());
334
            SystemMetadata sysmeta2_case3 = createSystemMetadata(pid2_case3, session.getSubject(), object);
335
            sysmeta2_case3.setSeriesId(sid_case3);
336
            sysmeta2_case3.setObsoletes(pid1_case3);
337
            CNodeService.getInstance(request).create(session, pid2_case3, object, sysmeta2_case3);
338
            System.out.println("case 3: =======");
339
            head = IdentifierManager.getInstance().getHeadPID(sid_case3);
340
            assertTrue(head.equals(pid2_case3));
341
            
342
            //case-4
343
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
344
            Identifier pid1_case4 = new Identifier();
345
            pid1_case4.setValue(generateDocumentId());
346
            Identifier sid_case4 = new Identifier();
347
            sid_case4.setValue("sid."+System.nanoTime());
348
            SystemMetadata sysmeta_case4 = createSystemMetadata(pid1_case4, session.getSubject(), object);
349
            sysmeta_case4.setSeriesId(sid_case4);
350
            CNodeService.getInstance(request).create(session, pid1_case4, object, sysmeta_case4);
351
            
352
            Thread.sleep(1000);
353
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
354
            Identifier pid2_case4 = new Identifier();
355
            pid2_case4.setValue(generateDocumentId());
356
            SystemMetadata sysmeta2_case4 = createSystemMetadata(pid2_case4, session.getSubject(), object);
357
            sysmeta2_case4.setSeriesId(sid_case4);
358
            sysmeta2_case4.setObsoletes(pid1_case4);
359
            CNodeService.getInstance(request).create(session, pid2_case4, object, sysmeta2_case4);
360
            
361
            sysmeta_case4.setObsoletedBy(pid2_case4);
362
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case4, sysmeta_case4);
363
            
364
            Thread.sleep(1000);
365
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
366
            Identifier pid3_case4 = new Identifier();
367
            pid3_case4.setValue(generateDocumentId());
368
            Identifier sid2_case4 = new Identifier();
369
            sid2_case4.setValue("sid."+System.nanoTime());
370
            SystemMetadata sysmeta3_case4 = createSystemMetadata(pid3_case4, session.getSubject(), object);
371
            sysmeta3_case4.setSeriesId(sid2_case4);
372
            sysmeta3_case4.setObsoletes(pid2_case4);
373
            CNodeService.getInstance(request).create(session, pid3_case4, object, sysmeta3_case4);
374
            
375
            sysmeta2_case4.setObsoletedBy(pid3_case4);
376
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case4, sysmeta2_case4);
377
            
378
            
379
            System.out.println("case 4: =======");
380
            head = IdentifierManager.getInstance().getHeadPID(sid_case4);
381
            assertTrue(head.equals(pid2_case4));
382
            head = IdentifierManager.getInstance().getHeadPID(sid2_case4);
383
            assertTrue(head.equals(pid3_case4));
384
            
385
            
386
            //case-5
387
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
388
            Identifier pid1_case5 = new Identifier();
389
            pid1_case5.setValue(generateDocumentId());
390
            Identifier sid_case5 = new Identifier();
391
            sid_case5.setValue("sid."+System.nanoTime());
392
            SystemMetadata sysmeta1_case5 = createSystemMetadata(pid1_case5, session.getSubject(), object);
393
            sysmeta1_case5.setSeriesId(sid_case5);
394
            CNodeService.getInstance(request).create(session, pid1_case5, object, sysmeta1_case5);
395
            
396
            Thread.sleep(1000);
397
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
398
            Identifier pid2_case5 = new Identifier();
399
            pid2_case5.setValue(generateDocumentId());
400
            SystemMetadata sysmeta2_case5 = createSystemMetadata(pid2_case5, session.getSubject(), object);
401
            sysmeta2_case5.setSeriesId(sid_case5);
402
            sysmeta2_case5.setObsoletes(pid1_case5);
403
            CNodeService.getInstance(request).create(session, pid2_case5, object, sysmeta2_case5);
404
            
405
            Thread.sleep(1000);
406
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
407
            Identifier pid3_case5 = new Identifier();
408
            pid3_case5.setValue(generateDocumentId());
409
            Identifier sid2_case5 = new Identifier();
410
            sid2_case5.setValue("sid."+System.nanoTime());
411
            SystemMetadata sysmeta3_case5 = createSystemMetadata(pid3_case5, session.getSubject(), object);
412
            sysmeta3_case5.setSeriesId(sid2_case5);
413
            sysmeta3_case5.setObsoletes(pid2_case5);
414
            CNodeService.getInstance(request).create(session, pid3_case5, object, sysmeta3_case5);
415
            
416
            System.out.println("case 5: =======");
417
            head = IdentifierManager.getInstance().getHeadPID(sid_case5);
418
            assertTrue(head.equals(pid2_case5));
419
            head = IdentifierManager.getInstance().getHeadPID(sid2_case5);
420
            assertTrue(head.equals(pid3_case5));
421
            
422
            
423
            //case-6
424
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
425
            Identifier pid1_case6 = new Identifier();
426
            pid1_case6.setValue(generateDocumentId());
427
            Identifier sid_case6 = new Identifier();
428
            sid_case6.setValue("sid."+System.nanoTime());
429
            SystemMetadata sysmeta_case6 = createSystemMetadata(pid1_case6, session.getSubject(), object);
430
            sysmeta_case6.setSeriesId(sid_case6);
431
            CNodeService.getInstance(request).create(session, pid1_case6, object, sysmeta_case6);
432
            
433
            Thread.sleep(1000);
434
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
435
            Identifier pid2_case6 = new Identifier();
436
            pid2_case6.setValue(generateDocumentId());
437
            SystemMetadata sysmeta2_case6 = createSystemMetadata(pid2_case6, session.getSubject(), object);
438
            sysmeta2_case6.setSeriesId(sid_case6);
439
            sysmeta2_case6.setObsoletes(pid1_case6);
440
            CNodeService.getInstance(request).create(session, pid2_case6, object, sysmeta2_case6);
441
            
442
            sysmeta_case6.setObsoletedBy(pid2_case6);
443
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case6, sysmeta_case6);
444
            
445
            Thread.sleep(1000);
446
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
447
            Identifier pid3_case6 = new Identifier();
448
            pid3_case6.setValue(generateDocumentId());
449
            SystemMetadata sysmeta3_case6 = createSystemMetadata(pid3_case6, session.getSubject(), object);
450
            sysmeta3_case6.setObsoletes(pid2_case6);
451
            CNodeService.getInstance(request).create(session, pid3_case6, object, sysmeta3_case6);
452
            
453
            sysmeta2_case6.setObsoletedBy(pid3_case6);
454
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case6, sysmeta2_case6);
455
            
456
            System.out.println("case 6: =======");
457
            head = IdentifierManager.getInstance().getHeadPID(sid_case6);
458
            assertTrue(head.equals(pid2_case6));
459
            
460
            
461
            //case-7
462
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
463
            Identifier pid1_case7 = new Identifier();
464
            pid1_case7.setValue(generateDocumentId());
465
            Identifier sid_case7 = new Identifier();
466
            sid_case7.setValue("sid."+System.nanoTime());
467
            SystemMetadata sysmeta_case7 = createSystemMetadata(pid1_case7, session.getSubject(), object);
468
            sysmeta_case7.setSeriesId(sid_case7);
469
            CNodeService.getInstance(request).create(session, pid1_case7, object, sysmeta_case7);
470
            
471
            Thread.sleep(1000);
472
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
473
            Identifier pid2_case7 = new Identifier();
474
            pid2_case7.setValue(generateDocumentId());
475
            SystemMetadata sysmeta2_case7 = createSystemMetadata(pid2_case7, session.getSubject(), object);
476
            sysmeta2_case7.setSeriesId(sid_case7);
477
            sysmeta2_case7.setObsoletes(pid1_case7);
478
            CNodeService.getInstance(request).create(session, pid2_case7, object, sysmeta2_case7);
479
            
480
            sysmeta_case7.setObsoletedBy(pid2_case7);
481
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case7, sysmeta_case7);
482
            
483
            Thread.sleep(1000);
484
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
485
            Identifier pid3_case7 = new Identifier();
486
            pid3_case7.setValue(generateDocumentId());
487
            SystemMetadata sysmeta3_case7 = createSystemMetadata(pid3_case7, session.getSubject(), object);
488
            sysmeta3_case7.setObsoletes(pid2_case7);
489
            CNodeService.getInstance(request).create(session, pid3_case7, object, sysmeta3_case7);
490
            
491
            sysmeta2_case7.setObsoletedBy(pid3_case7);
492
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case7, sysmeta2_case7);
493
            
494
            Thread.sleep(1000);
495
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
496
            Identifier pid4_case7 = new Identifier();
497
            pid4_case7.setValue(generateDocumentId());
498
            Identifier sid2_case7 = new Identifier();
499
            sid2_case7.setValue("sid."+System.nanoTime());
500
            SystemMetadata sysmeta4_case7 = createSystemMetadata(pid4_case7, session.getSubject(), object);
501
            sysmeta4_case7.setObsoletes(pid3_case7);
502
            sysmeta4_case7.setSeriesId(sid2_case7);
503
            CNodeService.getInstance(request).create(session, pid4_case7, object, sysmeta4_case7);
504
            
505
            sysmeta3_case7.setObsoletedBy(pid4_case7);
506
            CNodeService.getInstance(request).updateSystemMetadata(session, pid3_case7, sysmeta3_case7);
507
            
508
            System.out.println("case 7: =======");
509
            head = IdentifierManager.getInstance().getHeadPID(sid_case7);
510
            assertTrue(head.equals(pid2_case7));
511
            head = IdentifierManager.getInstance().getHeadPID(sid2_case7);
512
            assertTrue(head.equals(pid4_case7));
513
         
340 514
        } catch (Exception e) {
515
            e.printStackTrace();
341 516
            fail(e.getMessage());
342 517
        }
343 518
        

Also available in: Unified diff