Search in sources :

Example 36 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionInheritedForAttributeFailureCase.

@Test
public void createPermissionInheritedForAttributeFailureCase() {
    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);
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userThreeScope, Optional.of("5"));
    assertThrows(ForbiddenAccessException.class, () -> created.updateAttribute("name", ""));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 37 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionInheritedForAttributeSuccessCase.

// ----------------------------------------- ** Update Attribute On Create ** --------------------------------------
// Expression for field inherited from class level expression
@Test
public void createPermissionInheritedForAttributeSuccessCase() {
    com.yahoo.elide.core.RequestScope userOneScope = new TestRequestScope(tx, userOne, dictionary);
    UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
    when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userOneScope)).thenReturn(updateAndCreateNewObject);
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userOneScope, Optional.of("4"));
    created.updateAttribute("name", "");
    created.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 38 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method updatePermissionOverwrittenForAttributeFailureCase.

@Test
public void updatePermissionOverwrittenForAttributeFailureCase() {
    com.yahoo.elide.core.RequestScope userThreeScope = new TestRequestScope(tx, userThree, dictionary);
    UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
    when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userThreeScope);
    assertThrows(ForbiddenAccessException.class, () -> loaded.updateAttribute("alias", ""));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) 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 39 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionOverwrittenForRelationFailureCase.

@Test
public void createPermissionOverwrittenForRelationFailureCase() {
    com.yahoo.elide.core.RequestScope userOneScope = new TestRequestScope(tx, userOne, dictionary);
    UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
    when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userOneScope)).thenReturn(updateAndCreateNewObject);
    when(tx.loadObject(any(), eq(2L), any(RequestScope.class))).thenReturn(new Author());
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userOneScope, Optional.of("11"));
    com.yahoo.elide.core.PersistentResource<Author> loadedAuthor = PersistentResource.loadRecord(EntityProjection.builder().type(Author.class).build(), "2", userOneScope);
    assertThrows(ForbiddenAccessException.class, () -> created.addRelation("author", loadedAuthor));
}
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 40 with TestRequestScope

use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.

the class UpdateOnCreateTest method updatePermissionInheritedForAttributeFailureCase.

@Test
public void updatePermissionInheritedForAttributeFailureCase() {
    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);
    com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userOneScope);
    assertThrows(ForbiddenAccessException.class, () -> loaded.updateAttribute("name", ""));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) 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