Revision 9112
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java | ||
---|---|---|
39 | 39 |
import org.apache.commons.io.IOUtils; |
40 | 40 |
import org.dataone.client.v2.itk.D1Client; |
41 | 41 |
import org.dataone.service.exceptions.BaseException; |
42 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
|
42 | 43 |
import org.dataone.service.exceptions.NotAuthorized; |
43 | 44 |
import org.dataone.service.exceptions.NotFound; |
44 | 45 |
import org.dataone.service.exceptions.NotImplemented; |
... | ... | |
67 | 68 |
import org.dataone.service.types.v2.SystemMetadata; |
68 | 69 |
import org.dataone.service.util.Constants; |
69 | 70 |
|
71 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
|
72 |
|
|
70 | 73 |
/** |
71 | 74 |
* A JUnit test for testing the dataone CNCore implementation |
72 | 75 |
*/ |
... | ... | |
106 | 109 |
suite.addTest(new CNodeServiceTest("testSetAccessPolicy")); |
107 | 110 |
suite.addTest(new CNodeServiceTest("testSetOwner")); |
108 | 111 |
suite.addTest(new CNodeServiceTest("readDeletedObject")); |
112 |
suite.addTest(new CNodeServiceTest("testGetSID")); |
|
109 | 113 |
|
110 | 114 |
return suite; |
111 | 115 |
} |
... | ... | |
207 | 211 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
208 | 212 |
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta); |
209 | 213 |
assertEquals(guid.getValue(), pid.getValue()); |
214 |
System.out.println("the pid is+++++++++++++++++++++++++"+guid.getValue()); |
|
210 | 215 |
// get it |
211 | 216 |
InputStream retObject = CNodeService.getInstance(request).get(session, pid); |
212 | 217 |
// check it |
... | ... | |
658 | 663 |
fail("Unexpected error: " + e.getMessage()); |
659 | 664 |
} |
660 | 665 |
} |
666 |
|
|
667 |
/** |
|
668 |
* Test the method - get api for a speicified SID |
|
669 |
*/ |
|
670 |
public void testGetSID() { |
|
671 |
String str1 = "object1"; |
|
672 |
String str2 = "object2"; |
|
673 |
String str3 = "object3"; |
|
674 |
try { |
|
675 |
//insert test documents with a series id |
|
676 |
Session session = getTestSession(); |
|
677 |
Identifier guid = new Identifier(); |
|
678 |
guid.setValue(generateDocumentId()); |
|
679 |
InputStream object1 = new ByteArrayInputStream(str1.getBytes("UTF-8")); |
|
680 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object1); |
|
681 |
String sid1= "sid."+System.nanoTime(); |
|
682 |
Identifier seriesId = new Identifier(); |
|
683 |
seriesId.setValue(sid1); |
|
684 |
System.out.println("the first sid is "+seriesId.getValue()); |
|
685 |
sysmeta.setSeriesId(seriesId); |
|
686 |
CNodeService.getInstance(request).create(session, guid, object1, sysmeta); |
|
687 |
System.out.println("the first pid is "+guid.getValue()); |
|
688 |
//test the get(pid) for v2 |
|
689 |
InputStream result = CNodeService.getInstance(request).get(session, guid); |
|
690 |
// go back to beginning of original stream |
|
691 |
object1.reset(); |
|
692 |
// check |
|
693 |
assertTrue(object1.available() > 0); |
|
694 |
assertTrue(result.available() > 0); |
|
695 |
assertTrue(IOUtils.contentEquals(result, object1)); |
|
696 |
// test the get(id) for v2 |
|
697 |
InputStream result1 = CNodeService.getInstance(request).get(session, seriesId); |
|
698 |
object1.reset(); |
|
699 |
// check |
|
700 |
assertTrue(object1.available() > 0); |
|
701 |
assertTrue(result1.available() > 0); |
|
702 |
assertTrue(IOUtils.contentEquals(result1, object1)); |
|
703 |
//test the get(pid) for v1 |
|
704 |
InputStream result2 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, guid); |
|
705 |
object1.reset(); |
|
706 |
// check |
|
707 |
assertTrue(object1.available() > 0); |
|
708 |
assertTrue(result2.available() > 0); |
|
709 |
assertTrue(IOUtils.contentEquals(result2, object1)); |
|
710 |
//test the get(sid) for v1 |
|
711 |
try { |
|
712 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, seriesId); |
|
713 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
714 |
} catch (NotFound ee) { |
|
715 |
|
|
716 |
} |
|
717 |
SystemMetadata metadata = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
718 |
assertTrue(metadata.getIdentifier().getValue().equals(guid.getValue())); |
|
719 |
assertTrue(metadata.getSeriesId().getValue().equals(seriesId.getValue())); |
|
720 |
DescribeResponse describeResponse = CNodeService.getInstance(request).describe(session, seriesId); |
|
721 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata.getChecksum().getValue()); |
|
722 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata.getFormatId().getValue()); |
|
723 |
|
|
724 |
metadata = CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
725 |
assertTrue(metadata.getIdentifier().getValue().equals(guid.getValue())); |
|
726 |
assertTrue(metadata.getSeriesId().getValue().equals(seriesId.getValue())); |
|
727 |
describeResponse = CNodeService.getInstance(request).describe(session, guid); |
|
728 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata.getChecksum().getValue()); |
|
729 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata.getFormatId().getValue()); |
|
730 |
|
|
731 |
org.dataone.service.types.v1.SystemMetadata sys1=edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
732 |
assertTrue(metadata.getIdentifier().getValue().equals(guid.getValue())); |
|
733 |
|
|
734 |
try { |
|
735 |
org.dataone.service.types.v1.SystemMetadata sys2=edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
736 |
fail("the getSystemMetadata(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
737 |
} catch(NotFound nf2) { |
|
738 |
|
|
739 |
} |
|
740 |
|
|
741 |
describeResponse = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).describe(session, guid); |
|
742 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), sys1.getChecksum().getValue()); |
|
743 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), sys1.getFormatId().getValue()); |
|
744 |
try { |
|
745 |
describeResponse = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).describe(session, seriesId); |
|
746 |
fail("the describe(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
747 |
} catch(NotFound nf2) { |
|
748 |
|
|
749 |
} |
|
750 |
|
|
751 |
Checksum sum = CNodeService.getInstance(request).getChecksum(session, guid); |
|
752 |
assertTrue(sum.getValue().equals("5b78f9689b9aab1ebc0f3c1df916dd97")); |
|
753 |
|
|
754 |
try { |
|
755 |
sum = CNodeService.getInstance(request).getChecksum(session, seriesId); |
|
756 |
fail("the getCheckSum shouldn't work for sid"); |
|
757 |
} catch(NotFound nf3) { |
|
758 |
|
|
759 |
} |
|
760 |
|
|
761 |
sum = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).getChecksum(session, guid); |
|
762 |
assertTrue(sum.getValue().equals("5b78f9689b9aab1ebc0f3c1df916dd97")); |
|
763 |
|
|
764 |
try { |
|
765 |
sum = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).getChecksum(session, seriesId); |
|
766 |
fail("the getCheckSum shouldn't work for sid"); |
|
767 |
} catch(NotFound nf3) { |
|
768 |
|
|
769 |
} |
|
770 |
|
|
771 |
boolean isAuthorized = |
|
772 |
CNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ); |
|
773 |
assertEquals(isAuthorized, true); |
|
774 |
|
|
775 |
isAuthorized = |
|
776 |
CNodeService.getInstance(request).isAuthorized(session, seriesId, Permission.READ); |
|
777 |
assertEquals(isAuthorized, true); |
|
778 |
|
|
779 |
isAuthorized = |
|
780 |
edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ); |
|
781 |
assertEquals(isAuthorized, true); |
|
782 |
|
|
783 |
try { |
|
784 |
isAuthorized = |
|
785 |
edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).isAuthorized(session, seriesId, Permission.READ); |
|
786 |
fail("we can't reach here since the v1 isAuthorized method doesn't suppport series id"); |
|
787 |
} catch (NotFound e) { |
|
788 |
|
|
789 |
} |
|
790 |
|
|
791 |
//do a update with the same series id |
|
792 |
Thread.sleep(1000); |
|
793 |
Identifier newPid = new Identifier(); |
|
794 |
newPid.setValue(generateDocumentId()+"1"); |
|
795 |
System.out.println("the second pid is "+newPid.getValue()); |
|
796 |
InputStream object2 = new ByteArrayInputStream(str2.getBytes("UTF-8")); |
|
797 |
SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object2); |
|
798 |
newSysMeta.setObsoletes(guid); |
|
799 |
newSysMeta.setSeriesId(seriesId); |
|
800 |
//CNodeService.getInstance(request).update(session, guid, object2, newPid, newSysMeta); |
|
801 |
CNodeService.getInstance(request).create(session, newPid, object2, newSysMeta); |
|
802 |
//update the system metadata of previous version. |
|
803 |
sysmeta.setObsoletedBy(newPid); |
|
804 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta); |
|
805 |
InputStream result4 = CNodeService.getInstance(request).get(session, guid); |
|
806 |
// go back to beginning of original stream |
|
807 |
object1.reset(); |
|
808 |
// check |
|
809 |
assertTrue(object1.available() > 0); |
|
810 |
assertTrue(result4.available() > 0); |
|
811 |
assertTrue(IOUtils.contentEquals(result4, object1)); |
|
812 |
|
|
813 |
InputStream result5 = CNodeService.getInstance(request).get(session, newPid); |
|
814 |
// go back to beginning of original stream |
|
815 |
object2.reset(); |
|
816 |
// check |
|
817 |
assertTrue(object2.available() > 0); |
|
818 |
assertTrue(result5.available() > 0); |
|
819 |
assertTrue(IOUtils.contentEquals(result5, object2)); |
|
820 |
|
|
821 |
|
|
822 |
InputStream result6 = CNodeService.getInstance(request).get(session, seriesId); |
|
823 |
object2.reset(); |
|
824 |
// check |
|
825 |
assertTrue(object2.available() > 0); |
|
826 |
assertTrue(result6.available() > 0); |
|
827 |
assertTrue(IOUtils.contentEquals(result6, object2)); |
|
828 |
//test the get(pid) for v1 |
|
829 |
InputStream result7 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, guid); |
|
830 |
//System.out.println("+++++++++++++++++++++"+IOUtils.toString(result7)); |
|
831 |
object1.reset(); |
|
832 |
// check |
|
833 |
assertTrue(object1.available() > 0); |
|
834 |
assertTrue(result7.available() > 0); |
|
835 |
assertTrue(IOUtils.contentEquals(result7, object1)); |
|
836 |
|
|
837 |
InputStream result8 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, newPid); |
|
838 |
object2.reset(); |
|
839 |
// check |
|
840 |
assertTrue(object2.available() > 0); |
|
841 |
assertTrue(result8.available() > 0); |
|
842 |
assertTrue(IOUtils.contentEquals(result8, object2)); |
|
843 |
//test the get(sid) for v1 |
|
844 |
try { |
|
845 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, seriesId); |
|
846 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
847 |
} catch (NotFound ee) { |
|
848 |
|
|
849 |
} |
|
850 |
|
|
851 |
SystemMetadata metadata1 = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
852 |
assertTrue(metadata1.getIdentifier().getValue().equals(newPid.getValue())); |
|
853 |
assertTrue(metadata1.getSeriesId().getValue().equals(seriesId.getValue())); |
|
854 |
describeResponse = CNodeService.getInstance(request).describe(session, seriesId); |
|
855 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata1.getChecksum().getValue()); |
|
856 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata1.getFormatId().getValue()); |
|
857 |
|
|
858 |
SystemMetadata metadata2 = CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
859 |
assertTrue(metadata2.getIdentifier().getValue().equals(guid.getValue())); |
|
860 |
assertTrue(metadata2.getSeriesId().getValue().equals(seriesId.getValue())); |
|
861 |
describeResponse = CNodeService.getInstance(request).describe(session, guid); |
|
862 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata2.getChecksum().getValue()); |
|
863 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata2.getFormatId().getValue()); |
|
864 |
|
|
865 |
SystemMetadata metadata3 = CNodeService.getInstance(request).getSystemMetadata(session, newPid); |
|
866 |
assertTrue(metadata3.getIdentifier().getValue().equals(newPid.getValue())); |
|
867 |
assertTrue(metadata3.getSeriesId().getValue().equals(seriesId.getValue())); |
|
868 |
describeResponse = CNodeService.getInstance(request).describe(session, newPid); |
|
869 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata3.getChecksum().getValue()); |
|
870 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata3.getFormatId().getValue()); |
|
871 |
|
|
872 |
//do another update with different series id |
|
873 |
Thread.sleep(1000); |
|
874 |
String sid2 = "sid."+System.nanoTime(); |
|
875 |
Identifier seriesId2= new Identifier(); |
|
876 |
seriesId2.setValue(sid2); |
|
877 |
System.out.println("the second sid is "+seriesId2.getValue()); |
|
878 |
Identifier newPid2 = new Identifier(); |
|
879 |
newPid2.setValue(generateDocumentId()+"2"); |
|
880 |
System.out.println("the third pid is "+newPid2.getValue()); |
|
881 |
InputStream object3 = new ByteArrayInputStream(str3.getBytes("UTF-8")); |
|
882 |
SystemMetadata sysmeta3 = createSystemMetadata(newPid2, session.getSubject(), object3); |
|
883 |
sysmeta3.setObsoletes(newPid); |
|
884 |
sysmeta3.setSeriesId(seriesId2); |
|
885 |
//CNodeService.getInstance(request).update(session, newPid, object3, newPid2, sysmeta3); |
|
886 |
CNodeService.getInstance(request).create(session, newPid2, object3, sysmeta3); |
|
887 |
//update the system metadata of the previous version |
|
888 |
newSysMeta.setObsoletedBy(newPid2); |
|
889 |
CNodeService.getInstance(request).updateSystemMetadata(session, newPid, newSysMeta); |
|
890 |
|
|
891 |
InputStream result9 = CNodeService.getInstance(request).get(session, guid); |
|
892 |
// go back to beginning of original stream |
|
893 |
object1.reset(); |
|
894 |
// check |
|
895 |
assertTrue(object1.available() > 0); |
|
896 |
assertTrue(result9.available() > 0); |
|
897 |
assertTrue(IOUtils.contentEquals(result9, object1)); |
|
898 |
|
|
899 |
InputStream result10 = CNodeService.getInstance(request).get(session, newPid); |
|
900 |
// go back to beginning of original stream |
|
901 |
object2.reset(); |
|
902 |
// check |
|
903 |
assertTrue(object2.available() > 0); |
|
904 |
assertTrue(result10.available() > 0); |
|
905 |
assertTrue(IOUtils.contentEquals(result10, object2)); |
|
906 |
|
|
907 |
|
|
908 |
InputStream result11 = CNodeService.getInstance(request).get(session, newPid2); |
|
909 |
// go back to beginning of original stream |
|
910 |
object3.reset(); |
|
911 |
// check |
|
912 |
assertTrue(object3.available() > 0); |
|
913 |
assertTrue(result11.available() > 0); |
|
914 |
assertTrue(IOUtils.contentEquals(result11, object3)); |
|
915 |
|
|
916 |
InputStream result12 = CNodeService.getInstance(request).get(session, seriesId2); |
|
917 |
object3.reset(); |
|
918 |
// check |
|
919 |
assertTrue(object3.available() > 0); |
|
920 |
assertTrue(result12.available() > 0); |
|
921 |
assertTrue(IOUtils.contentEquals(result12, object3)); |
|
922 |
|
|
923 |
InputStream result16 = CNodeService.getInstance(request).get(session, seriesId); |
|
924 |
object2.reset(); |
|
925 |
// check |
|
926 |
assertTrue(object2.available() > 0); |
|
927 |
assertTrue(result16.available() > 0); |
|
928 |
assertTrue(IOUtils.contentEquals(result16, object2)); |
|
929 |
|
|
930 |
//test the get(pid) for v1 |
|
931 |
InputStream result13 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, guid); |
|
932 |
object1.reset(); |
|
933 |
// check |
|
934 |
assertTrue(object1.available() > 0); |
|
935 |
assertTrue(result13.available() > 0); |
|
936 |
assertTrue(IOUtils.contentEquals(result13, object1)); |
|
937 |
|
|
938 |
InputStream result14 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, newPid); |
|
939 |
object2.reset(); |
|
940 |
// check |
|
941 |
assertTrue(object2.available() > 0); |
|
942 |
assertTrue(result14.available() > 0); |
|
943 |
assertTrue(IOUtils.contentEquals(result14, object2)); |
|
944 |
|
|
945 |
InputStream result15 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, newPid2); |
|
946 |
object3.reset(); |
|
947 |
// check |
|
948 |
assertTrue(object3.available() > 0); |
|
949 |
assertTrue(result15.available() > 0); |
|
950 |
assertTrue(IOUtils.contentEquals(result15, object3)); |
|
951 |
|
|
952 |
SystemMetadata metadata4 = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
953 |
assertTrue(metadata4.getIdentifier().getValue().equals(newPid.getValue())); |
|
954 |
assertTrue(metadata4.getSeriesId().getValue().equals(seriesId.getValue())); |
|
955 |
describeResponse = CNodeService.getInstance(request).describe(session, seriesId); |
|
956 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata4.getChecksum().getValue()); |
|
957 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata4.getFormatId().getValue()); |
|
958 |
|
|
959 |
SystemMetadata metadata5 = CNodeService.getInstance(request).getSystemMetadata(session, seriesId2); |
|
960 |
assertTrue(metadata5.getIdentifier().getValue().equals(newPid2.getValue())); |
|
961 |
assertTrue(metadata5.getSeriesId().getValue().equals(seriesId2.getValue())); |
|
962 |
describeResponse = CNodeService.getInstance(request).describe(session, seriesId2); |
|
963 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata5.getChecksum().getValue()); |
|
964 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata5.getFormatId().getValue()); |
|
965 |
|
|
966 |
SystemMetadata metadata6 = CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
967 |
assertTrue(metadata6.getIdentifier().getValue().equals(guid.getValue())); |
|
968 |
assertTrue(metadata6.getSeriesId().getValue().equals(seriesId.getValue())); |
|
969 |
describeResponse = CNodeService.getInstance(request).describe(session, guid); |
|
970 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata6.getChecksum().getValue()); |
|
971 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata6.getFormatId().getValue()); |
|
972 |
|
|
973 |
SystemMetadata metadata7 = CNodeService.getInstance(request).getSystemMetadata(session, newPid); |
|
974 |
assertTrue(metadata7.getIdentifier().getValue().equals(newPid.getValue())); |
|
975 |
assertTrue(metadata7.getSeriesId().getValue().equals(seriesId.getValue())); |
|
976 |
describeResponse = CNodeService.getInstance(request).describe(session, newPid); |
|
977 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata7.getChecksum().getValue()); |
|
978 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata7.getFormatId().getValue()); |
|
979 |
|
|
980 |
SystemMetadata metadata8 = CNodeService.getInstance(request).getSystemMetadata(session, newPid2); |
|
981 |
assertTrue(metadata8.getIdentifier().getValue().equals(newPid2.getValue())); |
|
982 |
assertTrue(metadata8.getSeriesId().getValue().equals(seriesId2.getValue())); |
|
983 |
describeResponse = CNodeService.getInstance(request).describe(session, newPid2); |
|
984 |
assertEquals(describeResponse.getDataONE_Checksum().getValue(), metadata8.getChecksum().getValue()); |
|
985 |
assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier().getValue(), metadata8.getFormatId().getValue()); |
|
986 |
|
|
987 |
|
|
988 |
|
|
989 |
System.out.println("here==========================="); |
|
990 |
//test the get(sid) for v1 |
|
991 |
try { |
|
992 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, seriesId); |
|
993 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
994 |
} catch (NotFound ee) { |
|
995 |
|
|
996 |
} |
|
997 |
|
|
998 |
//test the get(sid) for v1 |
|
999 |
try { |
|
1000 |
InputStream result3 = edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, seriesId2); |
|
1001 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1002 |
} catch (NotFound ee) { |
|
1003 |
|
|
1004 |
} |
|
1005 |
|
|
1006 |
//test to get non-existing id for v2 |
|
1007 |
try { |
|
1008 |
// the pid should be null when we try to get a no-exist sid |
|
1009 |
Identifier non_exist_sid = new Identifier(); |
|
1010 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
|
1011 |
InputStream result3 = CNodeService.getInstance(request).get(session, non_exist_sid); |
|
1012 |
fail("the get(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1013 |
} catch (NotFound ee) { |
|
1014 |
|
|
1015 |
} |
|
1016 |
|
|
1017 |
try { |
|
1018 |
// the pid should be null when we try to get a no-exist sid |
|
1019 |
Identifier non_exist_sid = new Identifier(); |
|
1020 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
|
1021 |
SystemMetadata result3 = CNodeService.getInstance(request).getSystemMetadata(session, non_exist_sid); |
|
1022 |
fail("the getSystemMetadata(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1023 |
} catch (NotFound ee) { |
|
1024 |
|
|
1025 |
} |
|
1026 |
|
|
1027 |
try { |
|
1028 |
// the pid should be null when we try to get a no-exist sid |
|
1029 |
Identifier non_exist_sid = new Identifier(); |
|
1030 |
non_exist_sid.setValue("no-sid-exist-123qwe"); |
|
1031 |
CNodeService.getInstance(request).describe(session, non_exist_sid); |
|
1032 |
fail("the describe(sid) methoud should throw a not found exception for the sid "+seriesId.getValue()); |
|
1033 |
} catch (NotFound ee) { |
|
1034 |
|
|
1035 |
} |
|
1036 |
|
|
1037 |
|
|
1038 |
//do another update with invalid series ids |
|
1039 |
Thread.sleep(1000); |
|
1040 |
Identifier newPid3 = new Identifier(); |
|
1041 |
newPid3.setValue(generateDocumentId()+"3"); |
|
1042 |
System.out.println("the third pid is "+newPid3.getValue()); |
|
1043 |
InputStream object4 = new ByteArrayInputStream(str3.getBytes("UTF-8")); |
|
1044 |
SystemMetadata sysmeta4 = createSystemMetadata(newPid3, session.getSubject(), object4); |
|
1045 |
sysmeta4.setObsoletes(newPid2); |
|
1046 |
sysmeta4.setSeriesId(seriesId); |
|
1047 |
try { |
|
1048 |
CNodeService.getInstance(request).create(session, newPid3, object4, sysmeta4); |
|
1049 |
fail("we can't reach here since the sid is using an old one "); |
|
1050 |
} catch (InvalidSystemMetadata eee) { |
|
1051 |
|
|
1052 |
} |
|
1053 |
|
|
1054 |
sysmeta4.setSeriesId(newPid3); |
|
1055 |
try { |
|
1056 |
CNodeService.getInstance(request).create(session, newPid3, object4, sysmeta4); |
|
1057 |
fail("we can't reach here since the sid is using the pid "); |
|
1058 |
} catch (InvalidSystemMetadata eee) { |
|
1059 |
|
|
1060 |
} |
|
1061 |
|
|
1062 |
//test archive a series id by v1 |
|
1063 |
try { |
|
1064 |
edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).archive(session, seriesId2); |
|
1065 |
fail("we can't reach here since the v1 archive method doesn't support the sid "); |
|
1066 |
} catch (NotFound nf2) { |
|
1067 |
|
|
1068 |
} |
|
1069 |
|
|
1070 |
// test delete a series id by v1 |
|
1071 |
Session mnSession = getMNSession(); |
|
1072 |
try { |
|
1073 |
edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).delete(mnSession, seriesId2); |
|
1074 |
fail("we can't reach here since the v1 delete method doesn't support the sid "); |
|
1075 |
} catch (NotFound nf2) { |
|
1076 |
|
|
1077 |
} |
|
1078 |
|
|
1079 |
// test archive a series id by v2 |
|
1080 |
CNodeService.getInstance(request).archive(session, seriesId2); |
|
1081 |
SystemMetadata archived = CNodeService.getInstance(request).getSystemMetadata(session, seriesId2); |
|
1082 |
assertTrue(archived.getArchived()); |
|
1083 |
archived = CNodeService.getInstance(request).getSystemMetadata(session, newPid2); |
|
1084 |
assertTrue(archived.getArchived()); |
|
1085 |
|
|
1086 |
// test delete a series id by v2 |
|
1087 |
CNodeService.getInstance(request).delete(mnSession, seriesId2); |
|
1088 |
try { |
|
1089 |
CNodeService.getInstance(request).get(session, seriesId2); |
|
1090 |
fail("we can't reach here since the series id was deleted "); |
|
1091 |
} catch (NotFound nf3) { |
|
1092 |
System.out.println("the message is ============="+nf3.getMessage()); |
|
1093 |
//assertTrue(nf3.getMessage().indexOf("delete") >0); |
|
1094 |
} |
|
1095 |
|
|
1096 |
try { |
|
1097 |
CNodeService.getInstance(request).get(session, newPid2); |
|
1098 |
fail("we can't reach here since the series id was deleted "); |
|
1099 |
} catch (NotFound nf3) { |
|
1100 |
//System.out.println("the message is ============="+nf3.getMessage()); |
|
1101 |
assertTrue(nf3.getMessage().indexOf("delete") >0); |
|
1102 |
} |
|
1103 |
|
|
1104 |
try { |
|
1105 |
edu.ucsb.nceas.metacat.dataone.v1.CNodeService.getInstance(request).get(session, newPid2); |
|
1106 |
fail("we can't reach here since the series id was deleted "); |
|
1107 |
} catch (NotFound nf3) { |
|
1108 |
System.out.println("the message is ============="+nf3.getMessage()); |
|
1109 |
assertTrue(nf3.getMessage().indexOf("delete") >0); |
|
1110 |
} |
|
1111 |
|
|
1112 |
//archive seriesId |
|
1113 |
CNodeService.getInstance(request).archive(mnSession, seriesId); |
|
1114 |
archived = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
1115 |
assertTrue(archived.getArchived()); |
|
1116 |
archived = CNodeService.getInstance(request).getSystemMetadata(session, newPid); |
|
1117 |
assertTrue(archived.getArchived()); |
|
1118 |
|
|
1119 |
|
|
1120 |
//delete seriesId |
|
1121 |
CNodeService.getInstance(request).delete(mnSession, seriesId); |
|
1122 |
try { |
|
1123 |
CNodeService.getInstance(request).get(session, newPid); |
|
1124 |
fail("we can't reach here since the series id was deleted "); |
|
1125 |
} catch (NotFound nf3) { |
|
1126 |
//System.out.println("the message is ============="+nf3.getMessage()); |
|
1127 |
assertTrue(nf3.getMessage().indexOf("delete") >0); |
|
1128 |
} |
|
1129 |
SystemMetadata meta = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
1130 |
assertTrue(meta.getIdentifier().getValue().equals(guid.getValue())); |
|
1131 |
|
|
1132 |
} catch (Exception e) { |
|
1133 |
e.printStackTrace(); |
|
1134 |
fail(e.getMessage()); |
|
1135 |
} |
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
} |
|
661 | 1141 |
|
662 | 1142 |
} |
Also available in: Unified diff
Add a test case for testing sid chains.