use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithIncludedRelation.
@Test
public void testSubCollectionFetchWithIncludedRelation() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).relationship(Relationship.builder().name(PUBLISHER).projection(EntityProjection.builder().type(Publisher.class).build()).build()).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book LEFT JOIN FETCH example_Book.publisher " + "WHERE example_Author__fetch=:example_Author__fetch order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithIncludedToManyRelation.
@Test
public void testSubCollectionFetchWithIncludedToManyRelation() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).relationship(Relationship.builder().name(AUTHORS).projection(EntityProjection.builder().type(Author.class).build()).build()).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book " + "WHERE example_Author__fetch=:example_Author__fetch order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithSorting.
@Test
public void testSubCollectionFetchWithSorting() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
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();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book " + "WHERE example_Author__fetch=:example_Author__fetch order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AbstractHQLQueryBuilderTest method testSortClauseWithNestedComplexAttribute.
@Test
public void testSortClauseWithNestedComplexAttribute() {
Map<String, Sorting.SortOrder> sorting = new LinkedHashMap<>();
sorting.put("price.currency.isoCode", Sorting.SortOrder.asc);
String actual = getSortClause(new SortingImpl(sorting, Book.class, dictionary));
String expected = " order by example_Book.price.currency.isoCode asc";
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AbstractHQLQueryBuilderTest method testSortClauseWithoutPrefix.
@Test
public void testSortClauseWithoutPrefix() {
Map<String, Sorting.SortOrder> sorting = new LinkedHashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
sorting.put(GENRE, Sorting.SortOrder.desc);
String actual = getSortClause(new SortingImpl(sorting, Book.class, dictionary));
String expected = " order by example_Book.title asc,example_Book.genre desc";
assertEquals(expected, actual);
}
Aggregations