38 |
38 |
import junit.framework.TestSuite;
|
39 |
39 |
|
40 |
40 |
import org.apache.commons.io.IOUtils;
|
|
41 |
import org.dataone.client.v2.CNode;
|
41 |
42 |
import org.dataone.client.v2.itk.D1Client;
|
42 |
43 |
import org.dataone.service.exceptions.BaseException;
|
43 |
44 |
import org.dataone.service.exceptions.InvalidRequest;
|
... | ... | |
456 |
457 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
457 |
458 |
assertEquals(guid.getValue(), retGuid.getValue());
|
458 |
459 |
// set it
|
459 |
|
ReplicationStatus status = ReplicationStatus.COMPLETED;
|
|
460 |
ReplicationStatus status = ReplicationStatus.QUEUED;
|
460 |
461 |
BaseException failure = new NotAuthorized("000", "Mock exception for " + this.getClass().getName());
|
461 |
462 |
//Test the failure of setReplicationStatus by a non-cn subject
|
462 |
463 |
Session testSession = getTestSession();
|
... | ... | |
475 |
476 |
// check it
|
476 |
477 |
assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
|
477 |
478 |
|
|
479 |
//Test the success of setReplicationStatus by a register mn subject
|
|
480 |
Session mnSession = getMNSessionFromCN();
|
|
481 |
status = ReplicationStatus.COMPLETED;
|
|
482 |
result = CNodeService.getInstance(request).setReplicationStatus(mnSession, guid, replicaMemberNode, status, failure);
|
|
483 |
sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
|
|
484 |
assertNotNull(sysmeta);
|
|
485 |
// check it
|
|
486 |
assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
|
|
487 |
|
478 |
488 |
} catch(Exception e) {
|
479 |
489 |
fail("Unexpected error: " + e.getMessage());
|
480 |
490 |
}
|
... | ... | |
1262 |
1272 |
assertTrue(e instanceof InvalidRequest);
|
1263 |
1273 |
}
|
1264 |
1274 |
}
|
|
1275 |
|
|
1276 |
public Session getMNSessionFromCN() throws NotImplemented, ServiceFailure {
|
|
1277 |
Session session = new Session();
|
|
1278 |
Subject subject = null;
|
|
1279 |
CNode cn = D1Client.getCN();
|
|
1280 |
System.out.println("the cn is "+cn.getNodeBaseServiceUrl());
|
|
1281 |
List<Node> nodes = cn.listNodes().getNodeList();
|
|
1282 |
System.out.println("the size of the list is "+nodes.size());
|
|
1283 |
// find the first CN in the node list
|
|
1284 |
for (Node node : nodes) {
|
|
1285 |
if (node.getType().equals(NodeType.MN)) {
|
|
1286 |
subject = node.getSubject(0);
|
|
1287 |
break;
|
|
1288 |
}
|
|
1289 |
}
|
|
1290 |
session.setSubject(subject);
|
|
1291 |
return session;
|
|
1292 |
}
|
|
1293 |
|
1265 |
1294 |
}
|
Add the code to test a MN to call setReplicationStatus successfully.