Revision 9035
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
1438 | 1438 |
} |
1439 | 1439 |
|
1440 | 1440 |
//do a update with the same series id |
1441 |
/*Thread.sleep(1000);
|
|
1441 |
Thread.sleep(1000); |
|
1442 | 1442 |
Identifier newPid = new Identifier(); |
1443 | 1443 |
newPid.setValue(generateDocumentId()+"1"); |
1444 | 1444 |
System.out.println("the second pid is "+newPid.getValue()); |
1445 |
SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object); |
|
1445 |
InputStream object2 = new ByteArrayInputStream(str2.getBytes("UTF-8")); |
|
1446 |
SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object2); |
|
1446 | 1447 |
newSysMeta.setObsoletes(guid); |
1447 | 1448 |
newSysMeta.setSeriesId(seriesId); |
1448 |
MNodeService.getInstance(request).update(session, guid, object, newPid, newSysMeta); |
|
1449 |
// the pid should be the newPid when we try to get the sid1 |
|
1450 |
head = IdentifierManager.getInstance().getHeadPID(seriesId); |
|
1451 |
System.out.println("the head 2 is "+head.getValue()); |
|
1452 |
assertTrue(head.getValue().equals(newPid.getValue())); |
|
1449 |
MNodeService.getInstance(request).update(session, guid, object2, newPid, newSysMeta); |
|
1450 |
|
|
1451 |
InputStream result4 = MNodeService.getInstance(request).get(session, guid); |
|
1452 |
// go back to beginning of original stream |
|
1453 |
object1.reset(); |
|
1454 |
// check |
|
1455 |
assertTrue(object1.available() > 0); |
|
1456 |
assertTrue(result4.available() > 0); |
|
1457 |
assertTrue(IOUtils.contentEquals(result4, object1)); |
|
1453 | 1458 |
|
1459 |
InputStream result5 = MNodeService.getInstance(request).get(session, newPid); |
|
1460 |
// go back to beginning of original stream |
|
1461 |
object2.reset(); |
|
1462 |
// check |
|
1463 |
assertTrue(object2.available() > 0); |
|
1464 |
assertTrue(result5.available() > 0); |
|
1465 |
assertTrue(IOUtils.contentEquals(result5, object2)); |
|
1466 |
|
|
1467 |
|
|
1468 |
InputStream result6 = MNodeService.getInstance(request).get(session, seriesId); |
|
1469 |
object2.reset(); |
|
1470 |
// check |
|
1471 |
assertTrue(object2.available() > 0); |
|
1472 |
assertTrue(result6.available() > 0); |
|
1473 |
assertTrue(IOUtils.contentEquals(result6, object2)); |
|
1474 |
//test the get(pid) for v1 |
|
1475 |
InputStream result7 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, guid); |
|
1476 |
object1.reset(); |
|
1477 |
// check |
|
1478 |
assertTrue(object1.available() > 0); |
|
1479 |
assertTrue(result7.available() > 0); |
|
1480 |
assertTrue(IOUtils.contentEquals(result7, object1)); |
|
1481 |
|
|
1482 |
InputStream result8 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, newPid); |
|
1483 |
object2.reset(); |
|
1484 |
// check |
|
1485 |
assertTrue(object2.available() > 0); |
|
1486 |
assertTrue(result8.available() > 0); |
|
1487 |
assertTrue(IOUtils.contentEquals(result8, object2)); |
|
1488 |
//test the get(sid) for v1 |
|
1489 |
try { |
|
1490 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, seriesId); |
|
1491 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1492 |
} catch (NotFound ee) { |
|
1493 |
|
|
1494 |
} |
|
1495 |
|
|
1496 |
|
|
1454 | 1497 |
//do another update with different series id |
1455 | 1498 |
Thread.sleep(1000); |
1456 | 1499 |
String sid2 = "sid."+System.nanoTime(); |
... | ... | |
1460 | 1503 |
Identifier newPid2 = new Identifier(); |
1461 | 1504 |
newPid2.setValue(generateDocumentId()+"2"); |
1462 | 1505 |
System.out.println("the third pid is "+newPid2.getValue()); |
1463 |
SystemMetadata sysmeta3 = createSystemMetadata(newPid2, session.getSubject(), object); |
|
1506 |
InputStream object3 = new ByteArrayInputStream(str3.getBytes("UTF-8")); |
|
1507 |
SystemMetadata sysmeta3 = createSystemMetadata(newPid2, session.getSubject(), object3); |
|
1464 | 1508 |
sysmeta3.setObsoletes(newPid); |
1465 | 1509 |
sysmeta3.setSeriesId(seriesId2); |
1466 |
MNodeService.getInstance(request).update(session, newPid, object, newPid2, sysmeta3); |
|
1510 |
MNodeService.getInstance(request).update(session, newPid, object3, newPid2, sysmeta3);
|
|
1467 | 1511 |
|
1468 |
// the pid should be the newPid when we try to get the sid1 |
|
1469 |
head =IdentifierManager.getInstance().getHeadPID(seriesId); |
|
1470 |
System.out.println("the head 3 is "+head.getValue()); |
|
1471 |
assertTrue(head.getValue().equals(newPid.getValue())); |
|
1512 |
InputStream result9 = MNodeService.getInstance(request).get(session, guid); |
|
1513 |
// go back to beginning of original stream |
|
1514 |
object1.reset(); |
|
1515 |
// check |
|
1516 |
assertTrue(object1.available() > 0); |
|
1517 |
assertTrue(result9.available() > 0); |
|
1518 |
assertTrue(IOUtils.contentEquals(result9, object1)); |
|
1472 | 1519 |
|
1473 |
// the pid should be the newPid2 when we try to get the sid2 |
|
1474 |
head = IdentifierManager.getInstance().getHeadPID(seriesId2); |
|
1475 |
System.out.println("the head 4 is "+head.getValue()); |
|
1476 |
assertTrue(head.getValue().equals(newPid2.getValue())); |
|
1520 |
InputStream result10 = MNodeService.getInstance(request).get(session, newPid); |
|
1521 |
// go back to beginning of original stream |
|
1522 |
object2.reset(); |
|
1523 |
// check |
|
1524 |
assertTrue(object2.available() > 0); |
|
1525 |
assertTrue(result10.available() > 0); |
|
1526 |
assertTrue(IOUtils.contentEquals(result10, object2)); |
|
1477 | 1527 |
|
1478 |
// the pid should be null when we try to get a no-exist sid |
|
1479 |
Identifier non_exist_sid = new Identifier(); |
|
1480 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
|
1481 |
assertTrue(IdentifierManager.getInstance().getHeadPID(non_exist_sid) == null);*/ |
|
1482 | 1528 |
|
1529 |
InputStream result11 = MNodeService.getInstance(request).get(session, newPid2); |
|
1530 |
// go back to beginning of original stream |
|
1531 |
object3.reset(); |
|
1532 |
// check |
|
1533 |
assertTrue(object3.available() > 0); |
|
1534 |
assertTrue(result11.available() > 0); |
|
1535 |
assertTrue(IOUtils.contentEquals(result11, object3)); |
|
1536 |
|
|
1537 |
InputStream result12 = MNodeService.getInstance(request).get(session, seriesId2); |
|
1538 |
object3.reset(); |
|
1539 |
// check |
|
1540 |
assertTrue(object3.available() > 0); |
|
1541 |
assertTrue(result12.available() > 0); |
|
1542 |
assertTrue(IOUtils.contentEquals(result12, object3)); |
|
1543 |
|
|
1544 |
InputStream result16 = MNodeService.getInstance(request).get(session, seriesId); |
|
1545 |
object2.reset(); |
|
1546 |
// check |
|
1547 |
assertTrue(object2.available() > 0); |
|
1548 |
assertTrue(result16.available() > 0); |
|
1549 |
assertTrue(IOUtils.contentEquals(result16, object2)); |
|
1550 |
|
|
1551 |
//test the get(pid) for v1 |
|
1552 |
InputStream result13 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, guid); |
|
1553 |
object1.reset(); |
|
1554 |
// check |
|
1555 |
assertTrue(object1.available() > 0); |
|
1556 |
assertTrue(result13.available() > 0); |
|
1557 |
assertTrue(IOUtils.contentEquals(result13, object1)); |
|
1558 |
|
|
1559 |
InputStream result14 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, newPid); |
|
1560 |
object2.reset(); |
|
1561 |
// check |
|
1562 |
assertTrue(object2.available() > 0); |
|
1563 |
assertTrue(result14.available() > 0); |
|
1564 |
assertTrue(IOUtils.contentEquals(result14, object2)); |
|
1565 |
|
|
1566 |
InputStream result15 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, newPid2); |
|
1567 |
object3.reset(); |
|
1568 |
// check |
|
1569 |
assertTrue(object3.available() > 0); |
|
1570 |
assertTrue(result15.available() > 0); |
|
1571 |
assertTrue(IOUtils.contentEquals(result15, object3)); |
|
1572 |
|
|
1573 |
|
|
1574 |
//test the get(sid) for v1 |
|
1575 |
try { |
|
1576 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, seriesId); |
|
1577 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1578 |
} catch (NotFound ee) { |
|
1579 |
|
|
1580 |
} |
|
1581 |
|
|
1582 |
//test the get(sid) for v1 |
|
1583 |
try { |
|
1584 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, seriesId2); |
|
1585 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1586 |
} catch (NotFound ee) { |
|
1587 |
|
|
1588 |
} |
|
1589 |
|
|
1590 |
//test to get non-existing id for v2 |
|
1591 |
try { |
|
1592 |
// the pid should be null when we try to get a no-exist sid |
|
1593 |
Identifier non_exist_sid = new Identifier(); |
|
1594 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
|
1595 |
InputStream result3 = MNodeService.getInstance(request).get(session, non_exist_sid); |
|
1596 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1597 |
} catch (NotFound ee) { |
|
1598 |
|
|
1599 |
} |
|
1600 |
|
|
1601 |
|
|
1483 | 1602 |
} catch (Exception e) { |
1484 | 1603 |
fail(e.getMessage()); |
1485 | 1604 |
} |
Also available in: Unified diff
Add two updates on the testGetSID method.