use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class VerifyFieldAccessFilterExpressionVisitorTest method testShortCircuitPass.
@Test
public void testShortCircuitPass() throws Exception {
RSQLFilterDialect dialect = RSQLFilterDialect.builder().dictionary(scope.getDictionary()).build();
FilterExpression expression = dialect.parseFilterExpression("authors.name==foo", ClassType.of(Book.class), true);
Book book = new Book();
PersistentResource<Book> resource = new PersistentResource<>(book, "", scope);
PermissionExecutor permissionExecutor = scope.getPermissionExecutor();
DataStoreTransaction tx = scope.getTransaction();
when(permissionExecutor.checkUserPermissions(ClassType.of(Book.class), ReadPermission.class, AUTHORS)).thenReturn(ExpressionResult.PASS);
when(permissionExecutor.checkUserPermissions(ClassType.of(Author.class), ReadPermission.class, NAME)).thenReturn(ExpressionResult.PASS);
VerifyFieldAccessFilterExpressionVisitor visitor = new VerifyFieldAccessFilterExpressionVisitor(resource);
// restricted HOME field
assertTrue(expression.accept(visitor));
verify(permissionExecutor, times(1)).evaluateFilterJoinUserChecks(any(), any());
verify(permissionExecutor, times(1)).checkUserPermissions(ClassType.of(Book.class), ReadPermission.class, AUTHORS);
verify(permissionExecutor, times(1)).checkUserPermissions(ClassType.of(Author.class), ReadPermission.class, NAME);
verify(permissionExecutor, never()).checkSpecificFieldPermissions(resource, null, ReadPermission.class, GENRE);
verify(permissionExecutor, times(2)).checkUserPermissions(any(), any(), isA(String.class));
verify(permissionExecutor, never()).handleFilterJoinReject(any(), any(), any());
verify(tx, never()).getToManyRelation(any(), any(), any(), any());
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class DefaultFilterDialectTest method testGlobalExpressionParsingWithComplexAttribute.
@Test
public void testGlobalExpressionParsingWithComplexAttribute() throws Exception {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("filter[author.homeAddress.street1][infix]", "State");
FilterExpression expression = dialect.parseGlobalExpression("/author", queryParams, NO_VERSION);
assertEquals("author.homeAddress.street1 INFIX [State]", expression.toString());
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class RSQLFilterDialectTest method testIsemptyOperatorBool.
// TODO: add test for =isempty= case
@Test
public void testIsemptyOperatorBool() throws Exception {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("filter", "title=isempty=true");
FilterExpression expression = dialect.parseGlobalExpression("/book", queryParams, NO_VERSION);
assertEquals("book.title ISEMPTY []", expression.toString());
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class RSQLFilterDialectTest method testMemberOfOperatorInt.
@Test
public void testMemberOfOperatorInt() throws Exception {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("filter", "awards=hasmember=title1");
FilterExpression expression = dialect.parseGlobalExpression("/book", queryParams, NO_VERSION);
assertEquals("book.awards HASMEMBER [title1]", expression.toString());
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class RSQLFilterDialectTest method testIsnullOperatorInt.
@Test
public void testIsnullOperatorInt() throws Exception {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("filter", "title=isnull=1");
FilterExpression expression = dialect.parseGlobalExpression("/book", queryParams, NO_VERSION);
assertEquals("book.title ISNULL []", expression.toString());
}
Aggregations