Revision 8905
Added by Jing Tao about 10 years ago
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
package edu.ucsb.nceas.metacat.dataone; |
27 | 27 |
|
28 |
import CNodeServiceTest; |
|
29 |
|
|
28 | 30 |
import java.io.ByteArrayInputStream; |
29 | 31 |
import java.io.InputStream; |
30 | 32 |
import java.text.SimpleDateFormat; |
... | ... | |
45 | 47 |
import org.dataone.service.types.v1.AccessPolicy; |
46 | 48 |
import org.dataone.service.types.v1.AccessRule; |
47 | 49 |
import org.dataone.service.types.v1.Checksum; |
50 |
import org.dataone.service.types.v1.DescribeResponse; |
|
48 | 51 |
import org.dataone.service.types.v1.Event; |
49 | 52 |
import org.dataone.service.types.v1.Identifier; |
50 | 53 |
import org.dataone.service.types.v1.NodeReference; |
... | ... | |
103 | 106 |
suite.addTest(new CNodeServiceTest("testSearch")); |
104 | 107 |
suite.addTest(new CNodeServiceTest("testSetAccessPolicy")); |
105 | 108 |
suite.addTest(new CNodeServiceTest("testSetOwner")); |
109 |
suite.addTest(new CNodeServiceTest("readDeletedObject")); |
|
106 | 110 |
|
107 | 111 |
return suite; |
108 | 112 |
} |
... | ... | |
575 | 579 |
} |
576 | 580 |
|
577 | 581 |
} |
582 |
|
|
583 |
public void readDeletedObject() { |
|
584 |
printTestHeader("testCreate"); |
|
585 |
|
|
586 |
try { |
|
587 |
Session session = getTestSession(); |
|
588 |
Identifier guid = new Identifier(); |
|
589 |
guid.setValue("testCreate." + System.currentTimeMillis()); |
|
590 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
591 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
592 |
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
593 |
assertEquals(guid, pid); |
|
594 |
|
|
595 |
Thread.sleep(3000); |
|
596 |
// use MN admin to delete |
|
597 |
session = getMNSession(); |
|
598 |
Identifier deletedPid = CNodeService.getInstance(request).delete(session, pid); |
|
599 |
System.out.println("after deleting"); |
|
600 |
assertEquals(pid.getValue(), deletedPid.getValue()); |
|
601 |
// check that we cannot get the object |
|
602 |
session = getTestSession(); |
|
603 |
InputStream deletedObject = null; |
|
604 |
try { |
|
605 |
//System.out.println("before read ==============="); |
|
606 |
deletedObject = CNodeService.getInstance(request).get(session, deletedPid); |
|
607 |
//System.out.println("after read ==============="); |
|
608 |
} catch (NotFound nf) { |
|
609 |
//System.out.println("the exception is1 "+nf.getMessage()); |
|
610 |
//nf.printStackTrace(); |
|
611 |
assertTrue(nf.getMessage().contains("deleted")); |
|
612 |
} |
|
613 |
try { |
|
614 |
//System.out.println("before read ==============="); |
|
615 |
SystemMetadata sysmeta2 = CNodeService.getInstance(request).getSystemMetadata(session, deletedPid); |
|
616 |
//System.out.println("after read ==============="); |
|
617 |
} catch (NotFound nf) { |
|
618 |
//System.out.println("the exception is "+nf.getMessage()); |
|
619 |
//nf.printStackTrace(); |
|
620 |
assertTrue(nf.getMessage().contains("deleted")); |
|
621 |
} |
|
622 |
|
|
623 |
try { |
|
624 |
//System.out.println("before read ==============="); |
|
625 |
DescribeResponse describeResponse = CNodeService.getInstance(request).describe(session, pid); |
|
626 |
//System.out.println("after read ==============="); |
|
627 |
} catch (NotFound nf) { |
|
628 |
//System.out.println("the exception is "+nf.getMessage()); |
|
629 |
//nf.printStackTrace(); |
|
630 |
assertTrue(nf.getMessage().contains("deleted")); |
|
631 |
} |
|
632 |
|
|
633 |
try { |
|
634 |
//System.out.println("before read ==============="); |
|
635 |
Checksum checksum = CNodeService.getInstance(request).getChecksum(session, pid); |
|
636 |
//System.out.println("after read ==============="); |
|
637 |
} catch (NotFound nf) { |
|
638 |
//System.out.println("the exception 3 is "+nf.getMessage()); |
|
639 |
//nf.printStackTrace(); |
|
640 |
assertTrue(nf.getMessage().contains("deleted")); |
|
641 |
} |
|
642 |
|
|
643 |
try { |
|
644 |
//System.out.println("before read ==============="); |
|
645 |
boolean isAuthorized = |
|
646 |
CNodeService.getInstance(request).isAuthorized(session, pid, Permission.READ); |
|
647 |
//System.out.println("after read ==============="); |
|
648 |
} catch (NotFound nf) { |
|
649 |
//System.out.println("the exception 4 is "+nf.getMessage()); |
|
650 |
//nf.printStackTrace(); |
|
651 |
assertTrue(nf.getMessage().contains("deleted")); |
|
652 |
} |
|
653 |
|
|
654 |
|
|
655 |
|
|
656 |
assertNull(deletedObject); |
|
657 |
} catch(Exception e) { |
|
658 |
e.printStackTrace(); |
|
659 |
fail("Unexpected error: " + e.getMessage()); |
|
660 |
} |
|
661 |
} |
|
578 | 662 |
|
579 | 663 |
} |
Also available in: Unified diff
Added the junit tests to test the NotFoundException having the deleted information.