Revision 8906
Added by Jing Tao over 10 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
26 | 26 |
package edu.ucsb.nceas.metacat.dataone; |
27 | 27 |
|
28 | 28 |
|
29 |
import MNodeServiceTest; |
|
29 | 30 |
import gov.loc.repository.bagit.Bag; |
30 | 31 |
import gov.loc.repository.bagit.BagFactory; |
31 | 32 |
import gov.loc.repository.bagit.BagFile; |
... | ... | |
154 | 155 |
// MN packaging tests |
155 | 156 |
suite.addTest(new MNodeServiceTest("testGetPackage")); |
156 | 157 |
suite.addTest(new MNodeServiceTest("testGetOREPackage")); |
158 |
suite.addTest(new MNodeServiceTest("testReadDeletedObject")); |
|
157 | 159 |
|
158 |
|
|
159 | 160 |
return suite; |
160 | 161 |
|
161 | 162 |
} |
... | ... | |
1258 | 1259 |
} |
1259 | 1260 |
} |
1260 | 1261 |
|
1262 |
/** |
|
1263 |
* Test the extra "delete information" was added to the NotFoundException |
|
1264 |
* if the object was delete in the following methods: |
|
1265 |
* MN.get |
|
1266 |
* MN.getSystemmetadata |
|
1267 |
* MN.describe |
|
1268 |
* MN.getChecksum |
|
1269 |
* MN.getRelica |
|
1270 |
*/ |
|
1271 |
public void testReadDeletedObject() { |
|
1272 |
printTestHeader("testDelete"); |
|
1273 |
|
|
1274 |
try { |
|
1275 |
Session session = getTestSession(); |
|
1276 |
Identifier guid = new Identifier(); |
|
1277 |
guid.setValue("testDelete." + System.currentTimeMillis()); |
|
1278 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
1279 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
1280 |
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
1281 |
Thread.sleep(3000); |
|
1282 |
// use MN admin to delete |
|
1283 |
session = getMNSession(); |
|
1284 |
Identifier deletedPid = MNodeService.getInstance(request).delete(session, pid); |
|
1285 |
System.out.println("after deleting"); |
|
1286 |
assertEquals(pid.getValue(), deletedPid.getValue()); |
|
1287 |
// check that we cannot get the object |
|
1288 |
session = getTestSession(); |
|
1289 |
InputStream deletedObject = null; |
|
1290 |
try { |
|
1291 |
//System.out.println("before read ==============="); |
|
1292 |
deletedObject = MNodeService.getInstance(request).get(session, deletedPid); |
|
1293 |
//System.out.println("after read ==============="); |
|
1294 |
} catch (NotFound nf) { |
|
1295 |
assertTrue(nf.getMessage().contains("deleted")); |
|
1296 |
} |
|
1297 |
try { |
|
1298 |
//System.out.println("before read ==============="); |
|
1299 |
SystemMetadata sysmeta2 = MNodeService.getInstance(request).getSystemMetadata(session, deletedPid); |
|
1300 |
//System.out.println("after read ==============="); |
|
1301 |
} catch (NotFound nf) { |
|
1302 |
//System.out.println("the exception is "+nf.getMessage()); |
|
1303 |
assertTrue(nf.getMessage().contains("deleted")); |
|
1304 |
} |
|
1305 |
|
|
1306 |
try { |
|
1307 |
//System.out.println("before read ==============="); |
|
1308 |
DescribeResponse describeResponse = MNodeService.getInstance(request).describe(session, pid); |
|
1309 |
//System.out.println("after read ==============="); |
|
1310 |
} catch (NotFound nf) { |
|
1311 |
//System.out.println("the exception is "+nf.getMessage()); |
|
1312 |
assertTrue(nf.getMessage().contains("deleted")); |
|
1313 |
} |
|
1314 |
|
|
1315 |
try { |
|
1316 |
//System.out.println("before read ==============="); |
|
1317 |
Checksum checksum = MNodeService.getInstance(request).getChecksum(session, pid, "MD5"); |
|
1318 |
//System.out.println("after read ==============="); |
|
1319 |
} catch (NotFound nf) { |
|
1320 |
//System.out.println("the exception 3 is "+nf.getMessage()); |
|
1321 |
assertTrue(nf.getMessage().contains("deleted")); |
|
1322 |
} |
|
1323 |
|
|
1324 |
try { |
|
1325 |
//System.out.println("before read ==============="); |
|
1326 |
boolean isAuthorized = |
|
1327 |
MNodeService.getInstance(request).isAuthorized(session, pid, Permission.READ); |
|
1328 |
//System.out.println("after read ==============="); |
|
1329 |
} catch (NotFound nf) { |
|
1330 |
System.out.println("the exception 4 is "+nf.getMessage()); |
|
1331 |
assertTrue(nf.getMessage().contains("deleted")); |
|
1332 |
} |
|
1333 |
|
|
1334 |
assertNull(deletedObject); |
|
1335 |
|
|
1336 |
} catch (UnsupportedEncodingException e) { |
|
1337 |
e.printStackTrace(); |
|
1338 |
|
|
1339 |
} catch (Exception e) { |
|
1340 |
e.printStackTrace(); |
|
1341 |
fail("Unexpected error: " + e.getMessage()); |
|
1342 |
|
|
1343 |
} |
|
1344 |
} |
|
1261 | 1345 |
|
1262 | 1346 |
} |
Also available in: Unified diff
Added the junit tests to test the NotFoundException having the deleted information.