Revision 7163
Added by ben leinfelder over 12 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
116 | 116 |
suite.addTest(new MNodeServiceTest("testCreate")); |
117 | 117 |
suite.addTest(new MNodeServiceTest("testUpdate")); |
118 | 118 |
// this requires MN certificate |
119 |
//suite.addTest(new MNodeServiceTest("testDelete"));
|
|
119 |
suite.addTest(new MNodeServiceTest("testDelete")); |
|
120 | 120 |
|
121 | 121 |
// MNRead tests |
122 | 122 |
suite.addTest(new MNodeServiceTest("testGet")); |
... | ... | |
381 | 381 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
382 | 382 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
383 | 383 |
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
384 |
|
|
385 |
// use MN admin to delete |
|
386 |
session = getMNSession(); |
|
384 | 387 |
Identifier deletedPid = MNodeService.getInstance(request).delete(session, pid); |
385 | 388 |
assertEquals(pid.getValue(), deletedPid.getValue()); |
386 | 389 |
// check that we cannot get the object |
390 |
session = getTestSession(); |
|
387 | 391 |
InputStream deletedObject = null; |
388 | 392 |
try { |
389 |
deletedObject = MNodeService.getInstance(request).get(deletedPid); |
|
393 |
deletedObject = MNodeService.getInstance(request).get(session, deletedPid);
|
|
390 | 394 |
} catch (NotFound nf) { |
391 | 395 |
// this is expected |
392 | 396 |
} |
... | ... | |
770 | 774 |
Identifier retPid = MNodeService.getInstance(request).create(session, pid, object, sysmeta); |
771 | 775 |
assertEquals(retPid.getValue(), pid.getValue()); |
772 | 776 |
|
773 |
// pretend the sync failed |
|
777 |
// pretend the sync failed, act as CN
|
|
774 | 778 |
SynchronizationFailed syncFailed = |
775 | 779 |
new SynchronizationFailed("0000", "Testing Synch Failure"); |
776 | 780 |
syncFailed.setPid(pid.getValue()); |
781 |
session = getCNSession(); |
|
777 | 782 |
MNodeService.getInstance(request).synchronizationFailed(session, syncFailed ); |
778 | 783 |
} catch (Exception e) { |
779 | 784 |
e.printStackTrace(); |
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java | ||
---|---|---|
30 | 30 |
import java.io.Reader; |
31 | 31 |
import java.math.BigInteger; |
32 | 32 |
import java.util.Date; |
33 |
import java.util.List; |
|
33 | 34 |
|
34 | 35 |
import org.apache.wicket.protocol.http.MockHttpServletRequest; |
36 |
import org.dataone.client.CNode; |
|
37 |
import org.dataone.client.D1Client; |
|
35 | 38 |
import org.dataone.client.ObjectFormatCache; |
39 |
import org.dataone.service.exceptions.ServiceFailure; |
|
36 | 40 |
import org.dataone.service.types.v1.AccessPolicy; |
37 | 41 |
import org.dataone.service.types.v1.AccessRule; |
38 | 42 |
import org.dataone.service.types.v1.Checksum; |
39 | 43 |
import org.dataone.service.types.v1.Identifier; |
44 |
import org.dataone.service.types.v1.Node; |
|
40 | 45 |
import org.dataone.service.types.v1.NodeReference; |
46 |
import org.dataone.service.types.v1.NodeType; |
|
41 | 47 |
import org.dataone.service.types.v1.Permission; |
42 | 48 |
import org.dataone.service.types.v1.Session; |
43 | 49 |
import org.dataone.service.types.v1.Subject; |
... | ... | |
89 | 95 |
session.setSubject(subject); |
90 | 96 |
return session; |
91 | 97 |
} |
98 |
|
|
99 |
/** |
|
100 |
* constructs a "fake" session with the MN subject |
|
101 |
* @return |
|
102 |
*/ |
|
103 |
public Session getMNSession() throws Exception { |
|
104 |
Session session = new Session(); |
|
105 |
Subject subject = MNodeService.getInstance(request).getCapabilities().getSubject(0); |
|
106 |
session.setSubject(subject); |
|
107 |
return session; |
|
108 |
} |
|
92 | 109 |
|
110 |
public Session getCNSession() throws Exception { |
|
111 |
Session session = new Session(); |
|
112 |
Subject subject = null; |
|
113 |
CNode cn = D1Client.getCN(); |
|
114 |
List<Node> nodes = cn.listNodes().getNodeList(); |
|
115 |
|
|
116 |
// find the first CN in the node list |
|
117 |
for (Node node : nodes) { |
|
118 |
if (node.getType() == NodeType.CN) { |
|
119 |
subject = node.getSubject(0); |
|
120 |
break; |
|
121 |
} |
|
122 |
} |
|
123 |
session.setSubject(subject); |
|
124 |
return session; |
|
125 |
|
|
126 |
} |
|
127 |
|
|
93 | 128 |
/** |
94 | 129 |
* Run an initial test that always passes to check that the test harness is |
95 | 130 |
* working. |
Also available in: Unified diff
use MN (self) as the Session.subject so that the MN.delete() call is successful.