use of com.yahoo.elide.core.filter.predicates.InPredicate in project elide by yahoo.
the class EntityProjectionMakerTest method testRelationshipsAndIncludeWithFilterAndSort.
@Test
public void testRelationshipsAndIncludeWithFilterAndSort() {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("include", "authors");
queryParams.add("filter[author]", "name=='Foo'");
queryParams.add("filter[publisher]", "name=='Foo'");
queryParams.add("sort", "name");
String path = "/book/1/relationships/publisher";
Sorting sorting = SortingImpl.parseSortRule("name", ClassType.of(Publisher.class), dictionary);
RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
EntityProjection expected = EntityProjection.builder().type(Book.class).relationship("publisher", EntityProjection.builder().type(Publisher.class).filterExpression(new InPredicate(new Path(Publisher.class, dictionary, "name"), "Foo")).sorting(sorting).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Publisher.class))).build()).relationship("authors", EntityProjection.builder().attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("type").type(Author.AuthorType.class).build()).attribute(Attribute.builder().name("homeAddress").type(Address.class).build()).attribute(Attribute.builder().name("vacationHomes").type(Set.class).build()).attribute(Attribute.builder().name("stuff").type(Map.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).filterExpression(new InPredicate(new Path(Author.class, dictionary, "name"), "Foo")).relationship("books", EntityProjection.builder().type(Book.class).build()).type(Author.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build();
EntityProjection actual = maker.parsePath(path);
projectionEquals(expected, actual);
}
use of com.yahoo.elide.core.filter.predicates.InPredicate in project elide by yahoo.
the class EntityProjectionMakerTest method testRootCollectionWithGlobalFilter.
@Test
public void testRootCollectionWithGlobalFilter() {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("filter", "genre=='Science Fiction'");
String path = "/book";
RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Science Fiction");
EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
EntityProjection expected = EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).filterExpression(expression).relationship("publisher", EntityProjection.builder().type(Publisher.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).relationship("authors", EntityProjection.builder().type(Author.class).build()).pagination(PaginationImpl.getDefaultPagination(ClassType.of(Book.class))).build();
EntityProjection actual = maker.parsePath(path);
projectionEquals(expected, actual);
}
use of com.yahoo.elide.core.filter.predicates.InPredicate in project elide by yahoo.
the class InMemoryStoreTransactionTest method testFilteringRequiresInMemoryPagination.
@Test
public void testFilteringRequiresInMemoryPagination() {
FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 2, 10, 10, true, false);
EntityProjection projection = EntityProjection.builder().type(Book.class).filterExpression(expression).pagination(pagination).build();
DataStoreIterable filterInMemory = new DataStoreIterableBuilder(books).filterInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(filterInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(2, loaded.size());
assertTrue(loaded.contains(book1));
assertTrue(loaded.contains(book3));
assertEquals(2, pagination.getPageTotals());
}
use of com.yahoo.elide.core.filter.predicates.InPredicate in project elide by yahoo.
the class InMemoryFilterExecutorTest method andExpressionTest.
@Test
public void andExpressionTest() throws Exception {
author = new Author();
author.setId(1L);
author.setName("AuthorForTest");
expression = new AndFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "AuthorForTest"));
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new AndFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "AuthorForTest"));
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new AndFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "Fail"));
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new AndFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "Fail"));
fn = expression.accept(visitor);
assertFalse(fn.test(author));
}
use of com.yahoo.elide.core.filter.predicates.InPredicate in project elide by yahoo.
the class InMemoryFilterExecutorTest method orExpressionTest.
@Test
public void orExpressionTest() throws Exception {
author = new Author();
author.setId(1L);
author.setName("AuthorForTest");
expression = new OrFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "AuthorForTest"));
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new OrFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "AuthorForTest"));
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new OrFilterExpression(new InPredicate(authorIdElement, 1L), new InPredicate(authorNameElement, "Fail"));
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new OrFilterExpression(new InPredicate(authorIdElement, 0L), new InPredicate(authorNameElement, "Fail"));
fn = expression.accept(visitor);
assertFalse(fn.test(author));
}
Aggregations