Revision 10023
Added by Jing Tao about 8 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
180 | 180 |
suite.addTest(new MNodeServiceTest("testCreateAndUpdateXMLWithUnmatchingEncoding")); |
181 | 181 |
suite.addTest(new MNodeServiceTest("testListViews")); |
182 | 182 |
suite.addTest(new MNodeServiceTest("testCreateNOAAObject")); |
183 |
|
|
184 |
suite.addTest(new MNodeServiceTest("testPermissionOfUpdateSystemmeta")); |
|
185 |
|
|
183 | 186 |
|
184 | 187 |
|
185 | 188 |
|
... | ... | |
2482 | 2485 |
assertTrue(pid.getValue().equals(guid.getValue())); |
2483 | 2486 |
} |
2484 | 2487 |
|
2488 |
|
|
2489 |
/** |
|
2490 |
* Test the permission control on the updateSystemMetadata method |
|
2491 |
* @throws Exception |
|
2492 |
*/ |
|
2493 |
public void testPermissionOfUpdateSystemmeta() throws Exception { |
|
2494 |
String str = "object1"; |
|
2495 |
|
|
2496 |
Date date = new Date(); |
|
2497 |
Thread.sleep(2000); |
|
2498 |
//insert a test document |
|
2499 |
Session session = getTestSession(); |
|
2500 |
Identifier guid = new Identifier(); |
|
2501 |
guid.setValue(generateDocumentId()); |
|
2502 |
InputStream object1 = new ByteArrayInputStream(str.getBytes("UTF-8")); |
|
2503 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object1); |
|
2504 |
MNodeService.getInstance(request).create(session, guid, object1, sysmeta); |
|
2505 |
//Test the generating object succeeded. |
|
2506 |
SystemMetadata metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
2507 |
|
|
2508 |
//Test cn session -success |
|
2509 |
Session cnSession= getCNSession(); |
|
2510 |
MNodeService.getInstance(request).updateSystemMetadata(cnSession, guid, metadata); |
|
2511 |
|
|
2512 |
//Test mn session - success |
|
2513 |
Session mnSession = getMNSession(); |
|
2514 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
2515 |
MNodeService.getInstance(request).updateSystemMetadata(mnSession, guid, metadata); |
|
2516 |
|
|
2517 |
//Test the owner session -success |
|
2518 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
2519 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata); |
|
2520 |
|
|
2521 |
//Test another session -failed |
|
2522 |
Session anotherSession = getAnotherSession(); |
|
2523 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
2524 |
try { |
|
2525 |
MNodeService.getInstance(request).updateSystemMetadata(anotherSession, guid, metadata); |
|
2526 |
fail("Another user can't update the system metadata"); |
|
2527 |
} catch (NotAuthorized e) { |
|
2528 |
|
|
2529 |
} |
|
2530 |
|
|
2531 |
} |
|
2485 | 2532 |
} |
Also available in: Unified diff
Add a test method to test different users if they can update system metadata.