use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testDistinctRootFetchWithToManyJoinFilterAndPagination.
@Test
public void testDistinctRootFetchWithToManyJoinFilterAndPagination() throws ParseException {
final Pagination pagination = new PaginationImpl(Book.class, 0, 10, 10, 10, false, false);
final FilterExpression titlePredicate = filterParser.parseFilterExpression("books.chapters.title=in=('ABC','DEF')", ClassType.of(Author.class), true);
final FilterExpression publisherNamePredicate = filterParser.parseFilterExpression("books.publisher.name=in='Pub1'", ClassType.of(Author.class), true);
OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
EntityProjection entityProjection = EntityProjection.builder().type(Author.class).pagination(pagination).filterExpression(expression).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT DISTINCT example_Author FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_chapters.title IN (:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX))";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithJoinFilter.
@Test
public void testRootFetchWithJoinFilter() throws ParseException {
final FilterExpression titlePredicate = filterParser.parseFilterExpression("books.chapters.title=in=('ABC','DEF')", ClassType.of(Author.class), true);
final FilterExpression publisherNamePredicate = filterParser.parseFilterExpression("books.publisher.name=in='Pub1'", ClassType.of(Author.class), true);
OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
EntityProjection entityProjection = EntityProjection.builder().type(Author.class).filterExpression(expression).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Author FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_chapters.title IN (:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX)) ";
String actual = query.getQueryText();
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithRelationshipSortingAndFilters.
@Test
public void testRootFetchWithRelationshipSortingAndFilters() {
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(PUBLISHER + PERIOD + EDITOR + PERIOD + FIRSTNAME, Sorting.SortOrder.desc);
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" + " LEFT JOIN example_Book.publisher example_Book_publisher" + " LEFT JOIN example_Book_publisher.editor example_Book_publisher_editor" + " WHERE example_Book.id IN (:id_XXX)" + " order by example_Book_publisher_editor.firstName desc";
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 RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithJoinFilter.
@Test
public void testRootFetchWithJoinFilter() {
List<Path.PathElement> chapterTitlePath = Arrays.asList(new Path.PathElement(Author.class, Book.class, BOOKS), new Path.PathElement(Book.class, Chapter.class, "chapters"), new Path.PathElement(Chapter.class, String.class, TITLE));
FilterPredicate titlePredicate = new InPredicate(new Path(chapterTitlePath), "ABC", "DEF");
List<Path.PathElement> publisherNamePath = Arrays.asList(new Path.PathElement(Author.class, Book.class, BOOKS), new Path.PathElement(Book.class, Publisher.class, PUBLISHER), new Path.PathElement(Publisher.class, String.class, "name"));
FilterPredicate publisherNamePredicate = new InPredicate(new Path(publisherNamePath), "Pub1");
OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
EntityProjection entityProjection = EntityProjection.builder().type(Author.class).filterExpression(expression).build();
RootCollectionPageTotalsQueryBuilder builder = new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT COUNT(DISTINCT example_Author) FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_chapters.title IN " + "(:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX))";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithPagination.
@Test
public void testRootFetchWithPagination() {
PaginationImpl pagination = mock(PaginationImpl.class);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
TestQueryWrapper query = (TestQueryWrapper) new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper()).build();
String expected = "SELECT COUNT(DISTINCT example_Book) FROM example.Book AS example_Book";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
Aggregations