use of com.yahoo.elide.core.pagination.PaginationImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortingRequiresInMemoryPagination.
@Test
public void testSortingRequiresInMemoryPagination() {
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 3, 10, 10, true, false);
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).pagination(pagination).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(books).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(3, loaded.size());
List<String> bookTitles = loaded.stream().map((o) -> ((Book) o).getTitle()).collect(Collectors.toList());
assertEquals(Lists.newArrayList("Book 3", "Book 2", "Book 1"), bookTitles);
assertEquals(3, pagination.getPageTotals());
}
use of com.yahoo.elide.core.pagination.PaginationImpl 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.pagination.PaginationImpl in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testFetchJoinExcludesParent.
@Test
public void testFetchJoinExcludesParent() {
Publisher publisher = new Publisher();
publisher.setId(1);
Book book = new Book();
book.setId(2);
Pagination pagination = new PaginationImpl(Book.class, 0, 10, 10, 10, false, false);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Publisher.class), publisher, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Publisher example_Publisher__fetch " + "JOIN example_Publisher__fetch.books example_Book " + "WHERE example_Publisher__fetch=:example_Publisher__fetch";
String actual = query.getQueryText();
actual = actual.replaceFirst(":publisher_name_\\w+", ":publisher_name_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.pagination.PaginationImpl in project elide by yahoo.
the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithPagination.
@Test
public void testSubCollectionPageTotalsWithPagination() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
PaginationImpl pagination = mock(PaginationImpl.class);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
TestQueryWrapper query = (TestQueryWrapper) new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper()).build();
String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "JOIN example_Author.books example_Author_books " + "WHERE example_Author.id IN (:id_XXX)";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.pagination.PaginationImpl in project elide by yahoo.
the class DataStoreLoadTest method testPaginationPageTwo.
@Test
public void testPaginationPageTwo() throws Exception {
DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
Map<String, Sorting.SortOrder> sortRules = new HashMap<>();
sortRules.put("name", Sorting.SortOrder.desc);
sortRules.put("modifiedDate", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortRules, Item.class, dictionary);
PaginationImpl pagination = new PaginationImpl(Item.class, 1, 1, PaginationImpl.DEFAULT_PAGE_LIMIT, PaginationImpl.MAX_PAGE_LIMIT, true, false);
FilterExpression filter = filterParser.parseFilterExpression("name==cymbal*", ClassType.of(Item.class), false);
Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).sorting(sorting).pagination(pagination).build(), mockScope);
assertListMatches(loaded, Lists.newArrayList(5L));
assertEquals(pagination.getPageTotals(), 3);
verify(wrappedTransaction, never()).loadObjects(any(), any());
}
Aggregations