@Test(expected = ClassCastException.class) public void classCastException() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test(expected = ClassCastException.class) public void classCastException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test(expected = ClassCastException.class) public void classCastException() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); group.getList(commentId); }
@Test public void group_by_null() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void group_by_null() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void first_set_and_list() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void group_by_null() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(null); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test @ExcludeIn(DERBY) public void transform_groupBy_alias() { QCat kitten = new QCat("kitten"); SimplePath<Cat> k = Expressions.path(Cat.class, "k"); Map<Integer, Group> result = query().from(cat).innerJoin(cat.kittens, kitten) .transform(GroupBy.groupBy(cat.id) .as(cat.name, cat.id, GroupBy.list(Projections.constructor(Cat.class, kitten.name, kitten.id).as(k)))); for (Group entry : result.values()) { assertNotNull(entry.getOne(cat.id)); assertNotNull(entry.getOne(cat.name)); assertFalse(entry.getList(k).isEmpty()); } }