Search in sources :

Example 96 with RequestScope

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

the class PermissionExecutorTest method testUpdateFieldAwareSuccessAll.

@Test
public void testUpdateFieldAwareSuccessAll() {
    SampleBean sampleBean = new SampleBean();
    sampleBean.id = 1L;
    PersistentResource resource = newResource(sampleBean, SampleBean.class, true);
    RequestScope requestScope = resource.getRequestScope();
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, new ChangeSpec(null, null, null, null), UpdatePermission.class, "allVisible"));
    requestScope.getPermissionExecutor().executeCommitChecks();
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) RequestScope(com.yahoo.elide.core.RequestScope) UpdatePermission(com.yahoo.elide.annotation.UpdatePermission) Test(org.junit.jupiter.api.Test)

Example 97 with RequestScope

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

the class PermissionExecutorTest method testReadCheckExpressionForNewlyCreatedObject.

@Test
public void testReadCheckExpressionForNewlyCreatedObject() {
    @Entity
    @Include(rootLevel = false)
    @ReadPermission(expression = "FailOp")
    class Model {
    }
    PersistentResource resource = newResource(new Model(), Model.class, true);
    RequestScope requestScope = resource.getRequestScope();
    requestScope.getDictionary().bindEntity(Model.class);
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 98 with RequestScope

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

the class PermissionExecutorTest method testSuccessfulCommitChecks.

@Test
public void testSuccessfulCommitChecks() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "sampleOperation")
    class Model implements SampleOperationModel {
    }
    PersistentResource resource = newResource(new Model(), Model.class, true);
    RequestScope requestScope = resource.getRequestScope();
    // Because the object is newly created, the check is DEFERRED.
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
    requestScope.getPermissionExecutor().executeCommitChecks();
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Include(com.yahoo.elide.annotation.Include) RequestScope(com.yahoo.elide.core.RequestScope) UpdatePermission(com.yahoo.elide.annotation.UpdatePermission) Test(org.junit.jupiter.api.Test)

Example 99 with RequestScope

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

the class PermissionExecutorTest method testSpecificFieldCommitCheckFailByOveriddenField.

@Test
public void testSpecificFieldCommitCheckFailByOveriddenField() {
    PersistentResource resource = newResource(CheckedEntity.class, true);
    RequestScope requestScope = resource.getRequestScope();
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, new ChangeSpec(null, null, null, null), UpdatePermission.class, "hello"));
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) RequestScope(com.yahoo.elide.core.RequestScope) UpdatePermission(com.yahoo.elide.annotation.UpdatePermission) Test(org.junit.jupiter.api.Test)

Example 100 with RequestScope

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

the class EntityProjectionMakerTest method testNestedEntityNoQueryParams.

@Test
public void testNestedEntityNoQueryParams() {
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    String path = "/author/1/books/3/publisher/1";
    RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
    EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
    EntityProjection expected = EntityProjection.builder().type(Author.class).relationship("books", EntityProjection.builder().type(Book.class).relationship("publisher", EntityProjection.builder().type(Publisher.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("updateHookInvoked").type(boolean.class).build()).relationship("books", EntityProjection.builder().type(Book.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).build()).build();
    EntityProjection actual = maker.parsePath(path);
    projectionEquals(expected, actual);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Publisher(example.Publisher) Editor(example.Editor) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

RequestScope (com.yahoo.elide.core.RequestScope)132 Test (org.junit.jupiter.api.Test)99 PersistentResource (com.yahoo.elide.core.PersistentResource)63 TestRequestScope (com.yahoo.elide.core.TestRequestScope)28 Include (com.yahoo.elide.annotation.Include)27 Entity (javax.persistence.Entity)27 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)26 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)23 ReadPermission (com.yahoo.elide.annotation.ReadPermission)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)22 Book (example.Book)19 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)17 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)15 HashSet (java.util.HashSet)15 Publisher (example.Publisher)14 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 Author (example.Author)10 Editor (example.Editor)10 Collection (java.util.Collection)10