use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method updatePermissionInheritedForRelationFailureCase.
@Test
public void updatePermissionInheritedForRelationFailureCase() {
com.yahoo.elide.core.RequestScope userOneScope = new TestRequestScope(tx, userOne, dictionary);
UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Book());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userOneScope);
com.yahoo.elide.core.PersistentResource<Book> loadedBook = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Book.class).build(), "2", userOneScope);
assertThrows(ForbiddenAccessException.class, () -> loaded.addRelation("books", loadedBook));
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method createPermissionInheritedForRelationFailureCase.
@Test
public void createPermissionInheritedForRelationFailureCase() {
com.yahoo.elide.core.RequestScope userThreeScope = new TestRequestScope(tx, userThree, dictionary);
UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userThreeScope)).thenReturn(updateAndCreateNewObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Book());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userThreeScope, Optional.of("9"));
com.yahoo.elide.core.PersistentResource<Book> loadedBook = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Book.class).build(), "2", userThreeScope);
assertThrows(ForbiddenAccessException.class, () -> created.addRelation("books", loadedBook));
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method updatePermissionOverwrittenForRelationSuccessCase.
// Class level expression overwritten by field level expression
@Test
public void updatePermissionOverwrittenForRelationSuccessCase() {
com.yahoo.elide.core.RequestScope userThreeScope = new TestRequestScope(tx, new TestUser("3"), dictionary);
UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
updateAndCreateExistingObject.setId(1L);
when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Author());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userThreeScope);
com.yahoo.elide.core.PersistentResource<Author> loadedAuthor = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Author.class).build(), "2", userThreeScope);
loaded.addRelation("author", loadedAuthor);
loaded.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method updatePermissionInheritedForRelationSuccessCase.
// ----------------------------------------- ** Update Relation ** -----------------------------------------------
// Expression for relation inherited from class level expression
@Test
public void updatePermissionInheritedForRelationSuccessCase() {
com.yahoo.elide.core.RequestScope userTwoScope = new TestRequestScope(tx, userTwo, dictionary);
UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Book());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userTwoScope);
com.yahoo.elide.core.PersistentResource<Book> loadedBook = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Book.class).build(), "2", userTwoScope);
loaded.addRelation("books", loadedBook);
loaded.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method createPermissionOverwrittenForRelationSuccessCase.
// Class level expression overwritten by field level expression
@Test
public void createPermissionOverwrittenForRelationSuccessCase() {
com.yahoo.elide.core.RequestScope userTwoScope = new TestRequestScope(tx, userTwo, dictionary);
UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userTwoScope)).thenReturn(updateAndCreateNewObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Author());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userTwoScope, Optional.of("10"));
com.yahoo.elide.core.PersistentResource<Author> loadedAuthor = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Author.class).build(), "2", userTwoScope);
created.addRelation("author", loadedAuthor);
created.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
Aggregations