From 0ce99211490c62edf488c234c6386a6293678182 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 1 Apr 2015 10:13:52 +0200 Subject: [PATCH] OO-1483: fix the query in business group relation DAO that I broke --- .../manager/BusinessGroupRelationDAO.java | 2 +- .../test/BusinessGroupRelationDAOTest.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java index 524193da609..6940e1bd310 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java @@ -322,7 +322,7 @@ public class BusinessGroupRelationDAO { public List<Identity> getMembersOrderByDate(BusinessGroupRef group, String... roles) { StringBuilder sb = new StringBuilder(); - sb.append("select membership.identity.key from ").append(BusinessGroupImpl.class.getName()).append(" as bgroup ") + sb.append("select membership.identity from ").append(BusinessGroupImpl.class.getName()).append(" as bgroup ") .append(" inner join bgroup.baseGroup as baseGroup") .append(" inner join baseGroup.members as membership") .append(" where bgroup.key=:businessGroupKey and membership.role in (:roles) order by membership.creationDate"); diff --git a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java index fe5ba4e0337..0dd69600d7b 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java @@ -782,4 +782,47 @@ public class BusinessGroupRelationDAOTest extends OlatTestCase { Assert.assertEquals(1, duplicates.size()); Assert.assertEquals(id1.getKey(), duplicates.get(0).getKey()); } + + @Test + public void getMembersOrderByDate() { + Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + BusinessGroup group = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name()); + businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name()); + businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name()); + dbInstance.commitAndCloseSession(); + + //load the identities + List<Identity> ids = businessGroupRelationDao.getMembersOrderByDate(group, GroupRoles.participant.name()); + Assert.assertNotNull(ids); + Assert.assertEquals(3, ids.size()); + Assert.assertTrue(ids.contains(id1)); + Assert.assertTrue(ids.contains(id2)); + Assert.assertTrue(ids.contains(id3)); + } + + @Test + public void getMemberKeysOrderByDate() { + Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1"); + BusinessGroup group = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name()); + businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name()); + businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name()); + dbInstance.commitAndCloseSession(); + + //load the identities + List<Long> ids = businessGroupRelationDao.getMemberKeysOrderByDate(group, GroupRoles.participant.name()); + Assert.assertNotNull(ids); + Assert.assertEquals(3, ids.size()); + Assert.assertTrue(ids.contains(id1.getKey())); + Assert.assertTrue(ids.contains(id2.getKey())); + Assert.assertTrue(ids.contains(id3.getKey())); + } + + + } \ No newline at end of file -- GitLab