322 |
322 |
printTestHeader("testSetOwner");
|
323 |
323 |
|
324 |
324 |
try {
|
|
325 |
//v2 mn should fail
|
325 |
326 |
Session session = getCNSession();
|
|
327 |
Identifier guid = new Identifier();
|
|
328 |
guid.setValue("testSetOwner." + System.currentTimeMillis());
|
|
329 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
|
330 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
331 |
NodeReference nr = new NodeReference();
|
|
332 |
nr.setValue(MockCNode.V1MNNODEID);
|
|
333 |
sysmeta.setOriginMemberNode(nr);
|
|
334 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
335 |
long serialVersion = 1L;
|
|
336 |
// save it
|
|
337 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
|
338 |
assertEquals(guid.getValue(), retGuid.getValue());
|
|
339 |
Subject rightsHolder = new Subject();
|
|
340 |
rightsHolder.setValue("newUser");
|
|
341 |
// set it
|
|
342 |
Identifier retPid = CNodeService.getInstance(request).setRightsHolder(session, guid, rightsHolder, serialVersion);
|
|
343 |
assertEquals(guid, retPid);
|
|
344 |
// get it
|
|
345 |
sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
|
|
346 |
assertNotNull(sysmeta);
|
|
347 |
// check it
|
|
348 |
assertTrue(rightsHolder.equals(sysmeta.getRightsHolder()));
|
|
349 |
|
|
350 |
} catch(Exception e) {
|
|
351 |
e.printStackTrace();
|
|
352 |
fail("Unexpected error: " + e.getMessage());
|
|
353 |
}
|
|
354 |
try {
|
|
355 |
//v2 mn should fail
|
|
356 |
Session session = getCNSession();
|
326 |
357 |
Identifier guid = new Identifier();
|
327 |
358 |
guid.setValue("testSetOwner." + System.currentTimeMillis());
|
328 |
359 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
329 |
360 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
361 |
NodeReference nr = new NodeReference();
|
|
362 |
nr.setValue(MockCNode.V2MNNODEID);
|
|
363 |
sysmeta.setOriginMemberNode(nr);
|
|
364 |
sysmeta.setAuthoritativeMemberNode(nr);
|
330 |
365 |
long serialVersion = 1L;
|
331 |
366 |
// save it
|
332 |
367 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
... | ... | |
344 |
379 |
|
345 |
380 |
} catch(Exception e) {
|
346 |
381 |
e.printStackTrace();
|
347 |
|
if(e instanceof ServiceFailure) {
|
348 |
|
assertTrue(e.getMessage().contains("Couldn't determine the authoritative member node"));
|
|
382 |
if(e instanceof NotAuthorized) {
|
|
383 |
assertTrue(e.getMessage().contains("The Coordinating Node is not authorized to make systemMetadata changes"));
|
349 |
384 |
} else {
|
350 |
385 |
fail("Unexpected error: " + e.getMessage());
|
351 |
386 |
}
|
... | ... | |
354 |
389 |
|
355 |
390 |
public void testSetAccessPolicy() {
|
356 |
391 |
printTestHeader("testSetAccessPolicy");
|
|
392 |
|
|
393 |
|
|
394 |
try {
|
|
395 |
// trys to set access policy on an object whose authortiative memeber node is MNRead v2. It should fail.
|
|
396 |
Session session = getCNSession();
|
|
397 |
Identifier guid = new Identifier();
|
|
398 |
guid.setValue("testSetAccessPolicy." + System.currentTimeMillis());
|
|
399 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
|
400 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
401 |
NodeReference nr = new NodeReference();
|
|
402 |
nr.setValue(MockCNode.V1MNNODEID);
|
|
403 |
sysmeta.setOriginMemberNode(nr);
|
|
404 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
405 |
|
|
406 |
long serialVersion = 1L;
|
357 |
407 |
|
|
408 |
// save it
|
|
409 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
|
410 |
assertEquals(guid.getValue(), retGuid.getValue());
|
|
411 |
AccessPolicy accessPolicy = new AccessPolicy();
|
|
412 |
AccessRule accessRule = new AccessRule();
|
|
413 |
accessRule.addPermission(Permission.WRITE);
|
|
414 |
Subject publicSubject = new Subject();
|
|
415 |
publicSubject.setValue(Constants.SUBJECT_PUBLIC);
|
|
416 |
accessRule.addSubject(publicSubject);
|
|
417 |
accessPolicy.addAllow(accessRule);
|
|
418 |
// set it
|
|
419 |
boolean result = CNodeService.getInstance(request).setAccessPolicy(session, guid, accessPolicy, serialVersion );
|
|
420 |
assertTrue(result);
|
|
421 |
// check it
|
|
422 |
result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.WRITE);
|
|
423 |
assertTrue(result);
|
|
424 |
} catch(Exception e) {
|
|
425 |
|
|
426 |
fail("Unexpected error: " + e.getMessage());
|
|
427 |
|
|
428 |
}
|
|
429 |
|
358 |
430 |
try {
|
|
431 |
// trys to set access policy on an object whose authortiative memeber node is MNRead v2. It should fail.
|
359 |
432 |
Session session = getCNSession();
|
360 |
433 |
Identifier guid = new Identifier();
|
361 |
434 |
guid.setValue("testSetAccessPolicy." + System.currentTimeMillis());
|
362 |
435 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
363 |
436 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
364 |
|
long serialVersion = 1L;
|
|
437 |
NodeReference nr = new NodeReference();
|
|
438 |
nr.setValue(MockCNode.V2MNNODEID);
|
|
439 |
sysmeta.setOriginMemberNode(nr);
|
|
440 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
441 |
|
|
442 |
long serialVersion = 1L;
|
365 |
443 |
|
366 |
444 |
// save it
|
367 |
445 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
... | ... | |
381 |
459 |
assertTrue(result);
|
382 |
460 |
} catch(Exception e) {
|
383 |
461 |
e.printStackTrace();
|
384 |
|
if(e instanceof ServiceFailure) {
|
385 |
|
assertTrue(e.getMessage().contains("Couldn't determine the authoritative member node"));
|
|
462 |
if(e instanceof NotAuthorized) {
|
|
463 |
assertTrue(e.getMessage().contains("The Coordinating Node is not authorized to make systemMetadata changes"));
|
386 |
464 |
} else {
|
387 |
465 |
fail("Unexpected error: " + e.getMessage());
|
388 |
466 |
}
|
... | ... | |
426 |
504 |
printTestHeader("testReplicationPolicy");
|
427 |
505 |
|
428 |
506 |
try {
|
|
507 |
//v2 mn should fail
|
429 |
508 |
Session session = getCNSession();
|
|
509 |
Identifier guid = new Identifier();
|
|
510 |
guid.setValue("testReplicationPolicy." + System.currentTimeMillis());
|
|
511 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
|
512 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
513 |
NodeReference nr = new NodeReference();
|
|
514 |
nr.setValue(MockCNode.V1MNNODEID);
|
|
515 |
sysmeta.setOriginMemberNode(nr);
|
|
516 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
517 |
long serialVersion = 1L;
|
|
518 |
|
|
519 |
// save it
|
|
520 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
|
521 |
assertEquals(guid.getValue(), retGuid.getValue());
|
|
522 |
|
|
523 |
ReplicationPolicy policy = new ReplicationPolicy();
|
|
524 |
NodeReference node = new NodeReference();
|
|
525 |
node.setValue("testNode");
|
|
526 |
policy.addPreferredMemberNode(node );
|
|
527 |
// set it
|
|
528 |
boolean result = CNodeService.getInstance(request).setReplicationPolicy(session, guid, policy, serialVersion);
|
|
529 |
assertTrue(result);
|
|
530 |
// get it
|
|
531 |
sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
|
|
532 |
assertNotNull(sysmeta);
|
|
533 |
// check it
|
|
534 |
assertEquals(policy.getPreferredMemberNode(0).getValue(), sysmeta.getReplicationPolicy().getPreferredMemberNode(0).getValue());
|
|
535 |
|
|
536 |
} catch(Exception e) {
|
|
537 |
|
|
538 |
fail("Unexpected error: " + e.getMessage());
|
|
539 |
|
|
540 |
|
|
541 |
}
|
|
542 |
try {
|
|
543 |
//v2 mn should fail
|
|
544 |
Session session = getCNSession();
|
430 |
545 |
Identifier guid = new Identifier();
|
431 |
546 |
guid.setValue("testReplicationPolicy." + System.currentTimeMillis());
|
432 |
547 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
433 |
548 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
434 |
|
long serialVersion = 1L;
|
|
549 |
NodeReference nr = new NodeReference();
|
|
550 |
nr.setValue(MockCNode.V2MNNODEID);
|
|
551 |
sysmeta.setOriginMemberNode(nr);
|
|
552 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
553 |
long serialVersion = 1L;
|
435 |
554 |
|
436 |
555 |
// save it
|
437 |
556 |
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
... | ... | |
452 |
571 |
|
453 |
572 |
} catch(Exception e) {
|
454 |
573 |
e.printStackTrace();
|
455 |
|
if(e instanceof ServiceFailure) {
|
456 |
|
assertTrue(e.getMessage().contains("Couldn't determine the authoritative member node"));
|
|
574 |
if(e instanceof NotAuthorized) {
|
|
575 |
assertTrue(e.getMessage().contains("The Coordinating Node is not authorized to make systemMetadata changes"));
|
457 |
576 |
} else {
|
458 |
577 |
fail("Unexpected error: " + e.getMessage());
|
459 |
578 |
}
|
... | ... | |
1454 |
1573 |
}
|
1455 |
1574 |
|
1456 |
1575 |
public void testArchive() throws Exception {
|
1457 |
|
Session session = getCNSession();
|
1458 |
|
Identifier guid = new Identifier();
|
1459 |
|
guid.setValue("testArchive." + System.currentTimeMillis());
|
1460 |
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1461 |
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
1462 |
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1463 |
1576 |
try {
|
|
1577 |
Session session = getCNSession();
|
|
1578 |
Identifier guid = new Identifier();
|
|
1579 |
guid.setValue("testArchive." + System.currentTimeMillis());
|
|
1580 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
|
1581 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
1582 |
NodeReference nr = new NodeReference();
|
|
1583 |
nr.setValue(MockCNode.V1MNNODEID);
|
|
1584 |
sysmeta.setOriginMemberNode(nr);
|
|
1585 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
1586 |
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1464 |
1587 |
CNodeService.getInstance(request).archive(session, guid);
|
1465 |
1588 |
} catch (Exception e) {
|
1466 |
1589 |
e.printStackTrace();
|
1467 |
|
if(e instanceof ServiceFailure) {
|
1468 |
|
assertTrue(e.getMessage().contains("Couldn't determine the authoritative member node"));
|
1469 |
|
} else {
|
1470 |
|
fail("Unexpected error: " + e.getMessage());
|
1471 |
|
}
|
|
1590 |
fail("Unexpected error: " + e.getMessage());
|
1472 |
1591 |
}
|
|
1592 |
|
|
1593 |
try {
|
|
1594 |
//v2 mn should faile
|
|
1595 |
Session session = getCNSession();
|
|
1596 |
Identifier guid = new Identifier();
|
|
1597 |
guid.setValue("testArchive." + System.currentTimeMillis());
|
|
1598 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
|
1599 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
|
1600 |
NodeReference nr = new NodeReference();
|
|
1601 |
nr.setValue(MockCNode.V2MNNODEID);
|
|
1602 |
sysmeta.setOriginMemberNode(nr);
|
|
1603 |
sysmeta.setAuthoritativeMemberNode(nr);
|
|
1604 |
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
|
1605 |
CNodeService.getInstance(request).archive(session, guid);
|
|
1606 |
} catch (Exception e) {
|
|
1607 |
e.printStackTrace();
|
|
1608 |
if(e instanceof NotAuthorized) {
|
|
1609 |
assertTrue(e.getMessage().contains("The Coordinating Node is not authorized to make systemMetadata changes"));
|
|
1610 |
} else {
|
|
1611 |
fail("Unexpected error: " + e.getMessage());
|
|
1612 |
}
|
|
1613 |
}
|
1473 |
1614 |
}
|
1474 |
1615 |
|
1475 |
1616 |
|
Add code to testArchive, testSetAccessPolicy, testSetOwner and testSetReplicationPolicy on objects whose authoritative member node is v1 or v2 MNRead.