use of com.yahoo.elide.core.filter.predicates.NotEmptyPredicate in project elide by yahoo.
the class InMemoryFilterExecutorTest method isemptyAndNotemptyPredicateTest.
@Test
public void isemptyAndNotemptyPredicateTest() throws Exception {
author = new Author();
author.setId(1L);
// When name is empty and books are empty
author.setBooks(new HashSet<>());
author.setAwards(new HashSet<>());
expression = new IsEmptyPredicate(authorAwardsElement);
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new IsEmptyPredicate(authorBooksElement);
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new NotEmptyPredicate(authorAwardsElement);
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new NotEmptyPredicate(authorBooksElement);
fn = expression.accept(visitor);
assertFalse(fn.test(author));
// When name and books are not empty
author.setAwards(Arrays.asList("Bookery prize"));
author.getBooks().add(new Book());
expression = new IsEmptyPredicate(authorAwardsElement);
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new IsEmptyPredicate(authorBooksElement);
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new NotEmptyPredicate(authorAwardsElement);
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new NotEmptyPredicate(authorBooksElement);
fn = expression.accept(visitor);
assertTrue(fn.test(author));
}
use of com.yahoo.elide.core.filter.predicates.NotEmptyPredicate in project elide by yahoo.
the class FilterTranslatorTest method testHQLQueryVisitor.
@Test
public void testHQLQueryVisitor() throws Exception {
List<Path.PathElement> p0Path = Arrays.asList(new Path.PathElement(Book.class, Author.class, "authors"));
FilterPredicate p0 = new NotEmptyPredicate(new Path(p0Path));
List<Path.PathElement> p1Path = Arrays.asList(new Path.PathElement(Book.class, Author.class, "authors"), new Path.PathElement(Author.class, String.class, "name"));
FilterPredicate p1 = new InPredicate(new Path(p1Path), "foo", "bar");
List<Path.PathElement> p2Path = Arrays.asList(new Path.PathElement(Book.class, String.class, "name"));
FilterPredicate p2 = new InPredicate(new Path(p2Path), "blah");
List<Path.PathElement> p3Path = Arrays.asList(new Path.PathElement(Book.class, String.class, "genre"));
FilterPredicate p3 = new InPredicate(new Path(p3Path), "scifi");
OrFilterExpression or = new OrFilterExpression(p2, p3);
AndFilterExpression and1 = new AndFilterExpression(p0, p1);
AndFilterExpression and2 = new AndFilterExpression(or, and1);
NotFilterExpression not = new NotFilterExpression(and2);
FilterTranslator filterOp = new FilterTranslator(dictionary);
String query = filterOp.apply(not, false);
query = query.trim().replaceAll(" +", " ");
String p1Params = p1.getParameters().stream().map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", "));
String p2Params = p2.getParameters().stream().map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", "));
String p3Params = p3.getParameters().stream().map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", "));
String expected = "NOT (((name IN (" + p2Params + ") OR genre IN (" + p3Params + ")) " + "AND (authors IS NOT EMPTY AND authors.name IN (" + p1Params + "))))";
assertEquals(expected, query);
}
Aggregations