Search in sources :

Example 1 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class CanPaginateVisitorTest method testNotOperationExpression.

@Test
public void testNotOperationExpression() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "NOT In Memory Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class CanPaginateVisitorTest method testSparseFields.

@Test
public void testSparseFields() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @ReadPermission(expression = "In Memory Check")
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "Filter Expression Check")
        private String title;

        @ReadPermission(expression = "Filter Expression Check")
        private Date publicationDate;

        private boolean outOfPrint;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    Set<String> sparseFields = new HashSet<>();
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
    sparseFields.add("title");
    sparseFields.add("publicationDate");
    assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
    sparseFields.add("outOfPrint");
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class CanPaginateVisitorTest method testFieldFilterPermissions.

@Test
public void testFieldFilterPermissions() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "Filter Expression Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class CanPaginateVisitorTest method testFalseUserOROperationExpression.

@Test
public void testFalseUserOROperationExpression() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "False User Check OR In Memory Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class CanPaginateVisitorTest method testComplexTrueExpression.

@Test
public void testComplexTrueExpression() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "(Filter Expression Check AND False User Check) OR (Filter Expression Check OR NOT False User Check)")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Include (com.yahoo.elide.annotation.Include)46 Test (org.junit.jupiter.api.Test)41 Entity (javax.persistence.Entity)37 RequestScope (com.yahoo.elide.core.RequestScope)26 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)19 HashSet (java.util.HashSet)17 PersistentResource (com.yahoo.elide.core.PersistentResource)16 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)12 ReadPermission (com.yahoo.elide.annotation.ReadPermission)11 Annotation (java.lang.annotation.Annotation)4 Date (java.util.Date)4 ApiVersion (com.yahoo.elide.annotation.ApiVersion)3 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)3 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Exclude (com.yahoo.elide.annotation.Exclude)2 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)2 Expression (com.yahoo.elide.core.security.permissions.expressions.Expression)2 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)2