use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithSortingAndFilters.
@Test
public void testRootFetchWithSortingAndFilters() {
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
Path.PathElement idPath = new Path.PathElement(Book.class, Chapter.class, "id");
FilterPredicate idPredicate = new InPredicate(idPath, 1);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).filterExpression(idPredicate).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Book AS example_Book" + " WHERE example_Book.id IN (:id_XXX) order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithToOneRelationIncluded.
@Test
public void testRootFetchWithToOneRelationIncluded() {
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).relationship(Relationship.builder().name(PUBLISHER).projection(EntityProjection.builder().type(Publisher.class).build()).build()).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Book AS example_Book LEFT JOIN FETCH example_Book.publisher";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testSortingWithJoin.
@Test
public void testSortingWithJoin() {
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(PUBLISHER + PERIOD + NAME, Sorting.SortOrder.asc);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Book AS example_Book " + "LEFT JOIN example_Book.publisher example_Book_publisher " + "order by example_Book_publisher.name asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithSorting.
@Test
public void testRootFetchWithSorting() {
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Book AS example_Book " + "order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class DataStoreSupportsFilteringTest method testNgramJustRight.
@Test
public void testNgramJustRight() throws Exception {
DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==*ruabc*", ClassType.of(Item.class), false);
EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
assertFalse(loaded.needsInMemoryFilter());
assertFalse(loaded.needsInMemoryPagination());
assertFalse(loaded.needsInMemorySort());
verify(wrappedTransaction, times(0)).loadObjects(any(), any());
}
Aggregations