use of example.Right in project elide by yahoo.
the class PersistentResourceTest method testDeleteBidirectionalRelation.
@Test
public void testDeleteBidirectionalRelation() {
Left left = new Left();
Right right = new Right();
left.setOne2one(right);
right.setOne2one(left);
RequestScope scope = new TestRequestScope(tx, goodUser, dictionary);
PersistentResource<Left> leftResource = new PersistentResource<>(left, "3", scope);
leftResource.deleteInverseRelation("one2one", right);
assertNull(right.getOne2one(), "The one-2-one inverse relationship should have been unset");
assertEquals(right, left.getOne2one(), "The owning relationship should NOT have been unset");
Child child = new Child();
Parent parent = new Parent();
child.setParents(Sets.newHashSet(parent));
parent.setChildren(Sets.newHashSet(child));
parent.setSpouses(Sets.newHashSet());
scope = new TestRequestScope(tx, goodUser, dictionary);
PersistentResource<Child> childResource = new PersistentResource<>(child, "4", scope);
childResource.deleteInverseRelation("parents", parent);
assertEquals(parent.getChildren().size(), 0, "The many-2-many inverse collection should have been cleared.");
assertTrue(child.getParents().contains(parent), "The owning relationship should NOT have been touched");
}
use of example.Right in project elide by yahoo.
the class PersistentResourceTest method testClearRelationInvalidToOneUpdatePermission.
@Test
public void testClearRelationInvalidToOneUpdatePermission() {
Left left = new Left();
left.setId(1);
Right right = new Right();
right.setId(1);
left.setNoUpdateOne2One(right);
right.setNoUpdateOne2One(left);
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(EntityProjection.builder().type(Left.class).relationship("noUpdateOne2One", EntityProjection.builder().type(Right.class).build()).build());
PersistentResource<Left> leftResource = new PersistentResource<>(left, "1", goodScope);
assertThrows(ForbiddenAccessException.class, () -> leftResource.clearRelation("noUpdateOne2One"));
// Modifications have a deferred check component:
leftResource.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of example.Right in project elide by yahoo.
the class PersistentResourceTest method testDeletePermissionCheckedOnInverseRelationship.
@Test
public void testDeletePermissionCheckedOnInverseRelationship() {
Left left = new Left();
left.setId(1);
Right right = new Right();
right.setId(2);
Set<Right> rights = Sets.newHashSet(right);
left.setFieldLevelDelete(Sets.newHashSet(right));
right.setAllowDeleteAtFieldLevel(Sets.newHashSet(left));
// Bad User triggers the delete permission failure
when(tx.getToManyRelation(any(), eq(left), any(), any())).thenReturn(new DataStoreIterableBuilder(rights).build());
RequestScope badScope = buildRequestScope(tx, badUser);
PersistentResource<Left> leftResource = new PersistentResource<>(left, badScope.getUUIDFor(left), badScope);
assertTrue(leftResource.clearRelation("fieldLevelDelete"));
assertEquals(0, leftResource.getObject().getFieldLevelDelete().size());
}
use of example.Right in project elide by yahoo.
the class PersistentResourceTest method testSuccessfulOneToOneRelationshipAdd.
@Test
public void testSuccessfulOneToOneRelationshipAdd() throws Exception {
Left left = new Left();
Right right = new Right();
left.setId(2);
right.setId(3);
RequestScope goodScope = buildRequestScope(tx, goodUser);
PersistentResource<Left> leftResource = new PersistentResource<>(left, "2", goodScope);
Relationship ids = new Relationship(null, new Data<>(new ResourceIdentifier("right", "3").castToResource()));
when(tx.loadObject(any(), eq(3L), any())).thenReturn(right);
boolean updated = leftResource.updateRelation("one2one", ids.toPersistentResources(goodScope));
goodScope.saveOrCreateObjects();
verify(tx, times(1)).save(left, goodScope);
verify(tx, times(1)).save(right, goodScope);
verify(tx, times(1)).getToOneRelation(tx, left, getRelationship(ClassType.of(Right.class), "one2one"), goodScope);
assertTrue(updated, "The one-2-one relationship should be added.");
assertEquals(3, left.getOne2one().getId(), "The correct object was set in the one-2-one relationship");
}
use of example.Right in project elide by yahoo.
the class PersistentResourceTest method testUpdatePermissionCheckedOnInverseRelationship.
@Test
public void testUpdatePermissionCheckedOnInverseRelationship() {
Left left = new Left();
left.setId(1);
Right right = new Right();
Set<Right> rights = Sets.newHashSet(right);
left.setNoInverseUpdate(rights);
right.setNoUpdate(Sets.newHashSet(left));
List<Resource> empty = new ArrayList<>();
Relationship ids = new Relationship(null, new Data<>(empty));
when(tx.getToManyRelation(any(), eq(left), any(), any())).thenReturn(new DataStoreIterableBuilder(rights).build());
RequestScope goodScope = buildRequestScope(tx, goodUser);
PersistentResource<Left> leftResource = new PersistentResource<>(left, goodScope.getUUIDFor(left), goodScope);
assertThrows(ForbiddenAccessException.class, () -> leftResource.updateRelation("noInverseUpdate", ids.toPersistentResources(goodScope)));
// Modifications have a deferred check component:
leftResource.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
Aggregations