Revision 5654
Added by berkley about 14 years ago
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java | ||
---|---|---|
93 | 93 |
public static Test suite() |
94 | 94 |
{ |
95 | 95 |
TestSuite suite = new TestSuite(); |
96 |
suite.addTest(new CrudServiceTest("initialize")); |
|
96 |
/*suite.addTest(new CrudServiceTest("initialize"));
|
|
97 | 97 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
98 | 98 |
suite.addTest(new CrudServiceTest("testCreateAndGet")); |
99 | 99 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata")); |
... | ... | |
106 | 106 |
suite.addTest(new CrudServiceTest("testPublicAccess")); |
107 | 107 |
suite.addTest(new CrudServiceTest("testFailedCreate")); |
108 | 108 |
suite.addTest(new CrudServiceTest("testChecksum")); |
109 |
suite.addTest(new CrudServiceTest("testDescribe")); |
|
109 |
suite.addTest(new CrudServiceTest("testDescribe"));*/ |
|
110 |
suite.addTest(new CrudServiceTest("testDelete")); |
|
110 | 111 |
return suite; |
111 | 112 |
} |
112 | 113 |
|
113 | 114 |
/** |
115 |
* test the delete function |
|
116 |
*/ |
|
117 |
public void testDelete() |
|
118 |
{ |
|
119 |
try |
|
120 |
{ |
|
121 |
CrudService cs = CrudService.getInstance(); |
|
122 |
AuthToken token = getToken(); |
|
123 |
String doc = getTestDoc(); |
|
124 |
Identifier id = createDoc(token, doc); |
|
125 |
System.out.println("ID: " + id.getValue()); |
|
126 |
makeDocPublic(token, id, true); |
|
127 |
cs.get(token, id); |
|
128 |
cs.delete(token, id); |
|
129 |
//there should be a try/catch around the next statement |
|
130 |
//to make sure that the document is no longer readable, |
|
131 |
//but because the data is output in a 2nd thread, the |
|
132 |
//exception does not get caught here. See |
|
133 |
//https://redmine.dataone.org/issues/1079 |
|
134 |
cs.get(token, id); |
|
135 |
} |
|
136 |
catch(Exception e) |
|
137 |
{ |
|
138 |
fail("Unexpected error in testDescribe: " + e.getMessage()); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
114 | 143 |
* test the describe crud function |
115 | 144 |
*/ |
116 | 145 |
public void testDescribe() |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
886 | 886 |
} |
887 | 887 |
|
888 | 888 |
/** |
889 |
* Delete a document. NOT IMPLEMENTED
|
|
889 |
* Delete a document. |
|
890 | 890 |
*/ |
891 | 891 |
public Identifier delete(AuthToken token, Identifier guid) |
892 | 892 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
893 |
NotImplemented { |
|
893 |
NotImplemented, InvalidRequest {
|
|
894 | 894 |
logCrud.info("delete"); |
895 |
throw new NotImplemented("1321", "This method not yet implemented."); |
|
895 |
|
|
896 |
if(token == null || token.getToken().equals("publid")) |
|
897 |
{ |
|
898 |
throw new NotAuthorized("1320", "You must be logged in to delete records."); |
|
899 |
} |
|
900 |
|
|
901 |
if(guid == null || guid.getValue().trim().equals("")) |
|
902 |
{ |
|
903 |
throw new InvalidRequest("1322", "No GUID specified in CrudService.delete()"); |
|
904 |
} |
|
905 |
final SessionData sessionData = getSessionData(token); |
|
906 |
IdentifierManager manager = IdentifierManager.getInstance(); |
|
907 |
|
|
908 |
String docid; |
|
909 |
try |
|
910 |
{ |
|
911 |
docid = manager.getLocalId(guid.getValue()); |
|
912 |
} |
|
913 |
catch(McdbDocNotFoundException mnfe) |
|
914 |
{ |
|
915 |
throw new InvalidRequest("1322", "GUID " + guid + " not found."); |
|
916 |
} |
|
917 |
|
|
918 |
try |
|
919 |
{ |
|
920 |
DocumentImpl.delete(docid, sessionData.getUserName(), sessionData.getGroupNames(), null); |
|
921 |
} |
|
922 |
catch(Exception e) |
|
923 |
{ |
|
924 |
throw new ServiceFailure("1350", "Could not delete document: " + e.getMessage()); |
|
925 |
} |
|
926 |
|
|
927 |
return guid; |
|
896 | 928 |
} |
897 | 929 |
|
898 | 930 |
/** |
Also available in: Unified diff
implemented crud.delete