use of example.Left 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.Left 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.Left 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.Left 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.Left in project elide by yahoo.
the class PersistentResourceTest method testClearRelationInvalidToOneDeletePermission.
@Test
public void testClearRelationInvalidToOneDeletePermission() {
Left left = new Left();
left.setId(1);
NoDeleteEntity noDelete = new NoDeleteEntity();
noDelete.setId(1);
left.setNoDeleteOne2One(noDelete);
when(tx.getToOneRelation(any(), eq(left), any(), any())).thenReturn(noDelete);
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(EntityProjection.builder().type(Left.class).relationship("noDeleteOne2One", EntityProjection.builder().type(NoDeleteEntity.class).build()).build());
PersistentResource<Left> leftResource = new PersistentResource<>(left, "1", goodScope);
assertTrue(leftResource.clearRelation("noDeleteOne2One"));
assertNull(leftResource.getObject().getNoDeleteOne2One());
}
Aggregations