Revision 9377
Added by Jing Tao about 9 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
177 | 177 |
suite.addTest(new MNodeServiceTest("testUpdateSystemMetadata")); |
178 | 178 |
suite.addTest(new MNodeServiceTest("testUpdateObsoletesAndObsoletedBy")); |
179 | 179 |
suite.addTest(new MNodeServiceTest("testArchive")); |
180 |
suite.addTest(new MNodeServiceTest("testUpdateSciMetadata")); |
|
180 | 181 |
|
182 |
|
|
181 | 183 |
return suite; |
182 | 184 |
|
183 | 185 |
} |
... | ... | |
477 | 479 |
MNodeService.getInstance(request).archive(session, guid); |
478 | 480 |
SystemMetadata result = MNodeService.getInstance(request).getSystemMetadata(session, guid); |
479 | 481 |
assertTrue(result.getArchived()); |
482 |
System.out.println("the identifier is ==================="+pid.getValue()); |
|
480 | 483 |
} |
481 | 484 |
|
482 | 485 |
/** |
... | ... | |
591 | 594 |
|
592 | 595 |
} |
593 | 596 |
} |
597 |
|
|
598 |
|
|
599 |
/** |
|
600 |
* Test object updating |
|
601 |
*/ |
|
602 |
public void testUpdateSciMetadata() { |
|
603 |
printTestHeader("testUpdate"); |
|
604 |
|
|
605 |
try { |
|
606 |
String st1="<eml:eml xmlns:eml=\"eml://ecoinformatics.org/eml-2.1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" packageId=\"tao.13397.1\" system=\"knb\" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.1.1 eml.xsd\">" |
|
607 |
+"<access authSystem=\"knb\" order=\"allowFirst\">" |
|
608 |
+"<allow><principal>public</principal><permission>read</permission></allow></access>" |
|
609 |
+"<dataset><title>test</title><creator id=\"1445543475577\"><individualName><surName>test</surName></individualName></creator>" |
|
610 |
+"<contact id=\"1445543479900\"><individualName><surName>test</surName></individualName></contact></dataset></eml:eml>"; |
|
611 |
Session session = getTestSession(); |
|
612 |
Identifier guid = new Identifier(); |
|
613 |
guid.setValue("testUpdate." + System.currentTimeMillis()); |
|
614 |
InputStream object = new ByteArrayInputStream(st1.getBytes("UTF-8")); |
|
615 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
616 |
sysmeta.setFormatId(ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1").getFormatId()); |
|
617 |
MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
618 |
|
|
619 |
String st2="<eml:eml xmlns:eml=\"eml://ecoinformatics.org/eml-2.1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" packageId=\"tao.13397.1\" system=\"knb\" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.1.1 eml.xsd\">" |
|
620 |
+"<access authSystem=\"knb\" order=\"allowFirst\">" |
|
621 |
+"<allow><principal>public</principal><permission>read</permission></allow></access>" |
|
622 |
+"<dataset><title>test2</title><creator id=\"1445543475577\"><individualName><surName>test</surName></individualName></creator>" |
|
623 |
+"<contact id=\"1445543479900\"><individualName><surName>test</surName></individualName></contact></dataset></eml:eml>"; |
|
624 |
Identifier newPid = new Identifier(); |
|
625 |
newPid.setValue("testUpdate." + (System.currentTimeMillis() + 1)); // ensure it is different from original |
|
626 |
System.out.println("=================the pid is "+newPid.getValue()); |
|
627 |
object = new ByteArrayInputStream(st2.getBytes("UTF-8")); |
|
628 |
SystemMetadata sysmeta2 = createSystemMetadata(newPid, session.getSubject(), object); |
|
629 |
sysmeta2.setFormatId(ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1").getFormatId()); |
|
630 |
//sysmeta2.setObsoletes(guid); |
|
631 |
Checksum sum1= sysmeta2.getChecksum(); |
|
632 |
System.out.println("the checksum before sending is "+sum1.getValue()); |
|
633 |
object = new ByteArrayInputStream(st2.getBytes("UTF-8")); |
|
634 |
MNodeService.getInstance(request).update(session, guid, object, newPid, sysmeta2); |
|
635 |
SystemMetadata meta = MNodeService.getInstance(request).getSystemMetadata(session, newPid); |
|
636 |
System.out.println("the checksum getting from the server is "+meta.getChecksum().getValue()); |
|
637 |
assertTrue(meta.getChecksum().getValue().equals(sum1.getValue())); |
|
638 |
} catch (UnsupportedEncodingException e) { |
|
639 |
e.printStackTrace(); |
|
640 |
fail("Unexpected error: " + e.getMessage()); |
|
594 | 641 |
|
642 |
} catch (InvalidToken e) { |
|
643 |
e.printStackTrace(); |
|
644 |
fail("Unexpected error: " + e.getMessage()); |
|
645 |
|
|
646 |
} catch (ServiceFailure e) { |
|
647 |
e.printStackTrace(); |
|
648 |
fail("Unexpected error: " + e.getMessage()); |
|
649 |
|
|
650 |
} catch (NotAuthorized e) { |
|
651 |
e.printStackTrace(); |
|
652 |
fail("Unexpected error: " + e.getMessage()); |
|
653 |
|
|
654 |
} catch (IdentifierNotUnique e) { |
|
655 |
e.printStackTrace(); |
|
656 |
fail("Unexpected error: " + e.getMessage()); |
|
657 |
|
|
658 |
} catch (UnsupportedType e) { |
|
659 |
e.printStackTrace(); |
|
660 |
fail("Unexpected error: " + e.getMessage()); |
|
661 |
|
|
662 |
} catch (InsufficientResources e) { |
|
663 |
e.printStackTrace(); |
|
664 |
fail("Unexpected error: " + e.getMessage()); |
|
665 |
|
|
666 |
} catch (InvalidSystemMetadata e) { |
|
667 |
e.printStackTrace(); |
|
668 |
fail("Unexpected error: " + e.getMessage()); |
|
669 |
|
|
670 |
} catch (NotImplemented e) { |
|
671 |
e.printStackTrace(); |
|
672 |
fail("Unexpected error: " + e.getMessage()); |
|
673 |
|
|
674 |
} catch (InvalidRequest e) { |
|
675 |
e.printStackTrace(); |
|
676 |
fail("Unexpected error: " + e.getMessage()); |
|
677 |
|
|
678 |
} catch (Exception e) { |
|
679 |
e.printStackTrace(); |
|
680 |
fail("Unexpected error: " + e.getMessage()); |
|
681 |
|
|
682 |
} |
|
683 |
} |
|
684 |
|
|
595 | 685 |
/** |
596 | 686 |
* We currently expect this unit test to fail because it should rely on a different member node |
597 | 687 |
* to retrieve the object from. Currently it gets the object from itself and throws |
... | ... | |
2095 | 2185 |
//serialVersion = serialVersion.add(BigInteger.ONE); |
2096 | 2186 |
//System.out.println("the new version is "+serialVersion.toString()); |
2097 | 2187 |
//sysmeta.setSerialVersion(serialVersion); |
2188 |
System.out.println("the identifier is ----------------------- "+guid.getValue()); |
|
2098 | 2189 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta); |
2099 | 2190 |
SystemMetadata metadata2 = MNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
2100 | 2191 |
assertTrue(metadata2.getIdentifier().equals(guid)); |
Also available in: Unified diff
Add a new test to test the checksum matching for mn.update.