Search in sources :

Example 31 with TestRequestScope

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));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 32 with TestRequestScope

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));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 33 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Author(example.Author) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 34 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 35 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Author(example.Author) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

TestRequestScope (com.yahoo.elide.core.TestRequestScope)48 RequestScope (com.yahoo.elide.core.RequestScope)47 Test (org.junit.jupiter.api.Test)47 Book (example.Book)20 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)20 UpdateAndCreate (example.UpdateAndCreate)19 EntityProjection (com.yahoo.elide.core.request.EntityProjection)18 Publisher (example.Publisher)13 Author (example.Author)11 Editor (example.Editor)9 Collection (java.util.Collection)8 Parent (example.Parent)7 PersistentResource (com.yahoo.elide.core.PersistentResource)6 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)6 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)5 Resource (com.yahoo.elide.jsonapi.models.Resource)5 Child (example.Child)5 Price (example.Price)5 Path (com.yahoo.elide.core.Path)4 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)4