@Test public void testSubCollectionFetch() { Author author = new Author(); author.setId(1L); Book book = new Book(); book.setId(2); RelationshipImpl relationship = new RelationshipImpl( Author.class, Book.class, BOOKS, author, Arrays.asList(book)); SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper()); TestQueryWrapper query = (TestQueryWrapper) builder.build(); Assert.assertNull(query); }
@Transient @ComputedRelationship @OneToOne @FilterExpressionPath("publisher.editor") @ReadPermission(expression = "Field path editor check") public Editor getEditor() { return getPublisher().getEditor(); } }
@Test public void testSubCollectionFetchWithSorting() { Author author = new Author(); author.setId(1L); Book book = new Book(); book.setId(2); RelationshipImpl relationship = new RelationshipImpl( Author.class, Book.class, BOOKS, author, Arrays.asList(book)); SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper()); Map<String, Sorting.SortOrder> sorting = new HashMap<>(); sorting.put(TITLE, Sorting.SortOrder.asc); TestQueryWrapper query = (TestQueryWrapper) builder .withPossibleSorting(Optional.of(new Sorting(sorting))) .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(); Assert.assertEquals(actual, expected); }
@Test public void testSubCollectionPageTotals() { Author author = new Author(); author.setId(1L); Book book = new Book(); book.setId(2); RelationshipImpl relationship = new RelationshipImpl( Author.class, Book.class, BOOKS, author, Arrays.asList(book) ); SubCollectionPageTotalsQueryBuilder builder = new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper()); TestQueryWrapper query = (TestQueryWrapper) builder .build(); String actual = query.getQueryText(); actual = actual.replaceFirst(":id_\\w+", ":id_XXX"); 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)"; Assert.assertEquals(actual, expected); }