Search in sources :

Example 1 with RootCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetch.

@Test
public void testRootFetch() {
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).build();
    RootCollectionPageTotalsQueryBuilder builder = new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.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);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) Book(example.Book) Test(org.junit.jupiter.api.Test)

Example 2 with RootCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithSorting.

@Test
public void testRootFetchWithSorting() {
    Sorting sorting = mock(Sorting.class);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(sorting).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);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) Sorting(com.yahoo.elide.core.request.Sorting) Test(org.junit.jupiter.api.Test)

Example 3 with RootCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder 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);
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Chapter(example.Chapter) Publisher(example.Publisher) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Book(example.Book) Author(example.Author) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 4 with RootCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder 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);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

EntityProjection (com.yahoo.elide.core.request.EntityProjection)4 RootCollectionPageTotalsQueryBuilder (com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder)4 Test (org.junit.jupiter.api.Test)4 Book (example.Book)2 Path (com.yahoo.elide.core.Path)1 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)1 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)1 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)1 PaginationImpl (com.yahoo.elide.core.pagination.PaginationImpl)1 Sorting (com.yahoo.elide.core.request.Sorting)1 Author (example.Author)1 Chapter (example.Chapter)1 Publisher (example.Publisher)1