diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index 18d7ca391fc7165d47f7f579dc18d8fec3b2764a..0ec3a280482573c69b0ad1e52bbef60d1c1fc026 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -51,9 +51,7 @@ public interface BusinessGroupService { public void registerDeletableGroupDataListener(DeletableGroupData listener); public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); - - - + public BusinessGroup createBusinessGroup(Identity creator, String name, String description, int minParticipants, int maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource); diff --git a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java index 9be46ce94c1a0450394770d80e0452e64bb91e0a..4dc4e1ef1db58f142a170623d8301e040c4a9c2d 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java @@ -168,14 +168,15 @@ public class BusinessGroupRelationDAO { } public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, BusinessGroup group) { + if(names == null || names.isEmpty()) return false; + StringBuilder sb = new StringBuilder(); - sb.append("select bgs.key from ").append(BGResourceRelation.class.getName()).append(" as rel ") + sb.append("select rel.resource.key from ").append(BGResourceRelation.class.getName()).append(" as rel ") .append(" inner join rel.group bgs ") .append(" where bgs.key=:groupKey"); List<Long> resourceKeys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class) .setParameter("groupKey", group.getKey()) - .setParameter("names", names) .getResultList(); return checkIfOneOrMoreNameExistsInContext(names, resourceKeys); @@ -183,6 +184,7 @@ public class BusinessGroupRelationDAO { public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, List<Long> resourceKeys) { if(resourceKeys == null || resourceKeys.isEmpty()) return false; + if(names == null || names.isEmpty()) return false; StringBuilder sb = new StringBuilder(); sb.append("select count(bgs) from ").append(BGResourceRelation.class.getName()).append(" as rel ") @@ -213,7 +215,7 @@ public class BusinessGroupRelationDAO { } StringBuilder sb = new StringBuilder(); - sb.append("select bgcr.resource from ").append(BGResourceRelation.class.getName()).append(" bgcr where bgcr.group.key in (:groupKeys)"); + sb.append("select distinct bgcr.resource from ").append(BGResourceRelation.class.getName()).append(" bgcr where bgcr.group.key in (:groupKeys)"); TypedQuery<OLATResource> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), OLATResource.class); query.setFirstResult(firstResult); diff --git a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java index 0f5c4707716f21bb2e157098a7df6b6f6d46e843..9ff2af87af5f9194240f828a130677112b0dedf3 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java @@ -1,3 +1,22 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ package org.olat.group.test; import java.util.ArrayList; diff --git a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java index c02fff351c089c5d68272909dca86797e47ecce4..fead4822a7ea3092c37d3f9ca5a85cc37b4f1031 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java @@ -1,33 +1,643 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ package org.olat.group.test; -public class BusinessGroupRelationDAOTest { +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import junit.framework.Assert; + +import org.junit.Test; +import org.olat.basesecurity.BaseSecurity; +import org.olat.core.commons.persistence.DB; +import org.olat.core.id.Identity; +import org.olat.group.BusinessGroup; +import org.olat.group.manager.BusinessGroupDAO; +import org.olat.group.manager.BusinessGroupRelationDAO; +import org.olat.group.model.SearchBusinessGroupParams; +import org.olat.resource.OLATResource; +import org.olat.test.JunitTestHelper; +import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupRelationDAOTest extends OlatTestCase { - /* - // - public boolean isIdentityInBusinessGroup(Identity identity, String name, OLATResource resource) + @Autowired + private DB dbInstance; + @Autowired + private BusinessGroupDAO businessGroupDao; + @Autowired + private BusinessGroupRelationDAO businessGroupRelationDao; + @Autowired + private BaseSecurity securityManager; - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, OLATResource resource) + @Test + public void should_service_present() { + Assert.assertNotNull(businessGroupDao); + Assert.assertNotNull(businessGroupRelationDao); + } - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, List<Long> resourceKeys) + @Test + public void addRelation() { + //create a relation + OLATResource resource = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group, resource); + + dbInstance.commitAndCloseSession(); + + //check + List<OLATResource> resources = businessGroupRelationDao.findResources(Collections.singletonList(group), 0, -1); + Assert.assertNotNull(resources); + Assert.assertEquals(1, resources.size()); + Assert.assertTrue(resources.contains(resource)); + } - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, BusinessGroup group) + @Test + public void addRelations() { + //create a relation + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group, resource1); + businessGroupRelationDao.addRelationToResource(group, resource2); + businessGroupRelationDao.addRelationToResource(group, resource3); + businessGroupRelationDao.addRelationToResource(group, resource3); + + dbInstance.commitAndCloseSession(); + + //check + List<OLATResource> resources = businessGroupRelationDao.findResources(Collections.singletonList(group), 0, -1); + Assert.assertNotNull(resources); + Assert.assertEquals(3, resources.size()); + Assert.assertTrue(resources.contains(resource1)); + Assert.assertTrue(resources.contains(resource2)); + Assert.assertTrue(resources.contains(resource3)); + } + @Test + public void addGroupsAndRelations() { + //create a relation + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-2", "rel-bg-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource2); + businessGroupRelationDao.addRelationToResource(group2, resource3); + + + dbInstance.commitAndCloseSession(); + + //check group1 + List<OLATResource> resources1 = businessGroupRelationDao.findResources(Collections.singletonList(group1), 0, -1); + Assert.assertNotNull(resources1); + Assert.assertEquals(2, resources1.size()); + Assert.assertTrue(resources1.contains(resource1)); + Assert.assertTrue(resources1.contains(resource2)); + Assert.assertFalse(resources1.contains(resource3)); + + //check group2 + List<OLATResource> resources2 = businessGroupRelationDao.findResources(Collections.singletonList(group2), 0, -1); + Assert.assertNotNull(resources2); + Assert.assertEquals(2, resources2.size()); + Assert.assertFalse(resources2.contains(resource1)); + Assert.assertTrue(resources2.contains(resource2)); + Assert.assertTrue(resources2.contains(resource3)); + } + + @Test + public void deleteRelation() { + //create relations + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-2", "rel-bg-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource2); + businessGroupRelationDao.addRelationToResource(group2, resource3); + dbInstance.commitAndCloseSession(); + + //delete relation + businessGroupRelationDao.deleteRelation(group1, resource1); + dbInstance.commitAndCloseSession(); + + //check group1 + List<OLATResource> resources1 = businessGroupRelationDao.findResources(Collections.singletonList(group1), 0, -1); + Assert.assertNotNull(resources1); + Assert.assertEquals(1, resources1.size()); + Assert.assertFalse(resources1.contains(resource1)); + Assert.assertTrue(resources1.contains(resource2)); + Assert.assertFalse(resources1.contains(resource3)); + + //check group2 + List<OLATResource> resources2 = businessGroupRelationDao.findResources(Collections.singletonList(group2), 0, -1); + Assert.assertNotNull(resources2); + Assert.assertEquals(2, resources2.size()); + Assert.assertFalse(resources2.contains(resource1)); + Assert.assertTrue(resources2.contains(resource2)); + Assert.assertTrue(resources2.contains(resource3)); + } - check with resources - //findBusinessGroupsWithWaitingListAttendedBy - * public int countBusinessGroups(SearchBusinessGroupParams params, Identity identity, - boolean ownedById, boolean attendedById, OLATResource resource) + @Test + public void deleteRelations() { + //create relations + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-2", "rel-bg-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource2); + businessGroupRelationDao.addRelationToResource(group2, resource3); + dbInstance.commitAndCloseSession(); + + //delete relation + businessGroupRelationDao.deleteRelations(group1); + dbInstance.commitAndCloseSession(); + + //check group1 + List<OLATResource> resources1 = businessGroupRelationDao.findResources(Collections.singletonList(group1), 0, -1); + Assert.assertNotNull(resources1); + Assert.assertEquals(0, resources1.size()); + + //check group2 + List<OLATResource> resources2 = businessGroupRelationDao.findResources(Collections.singletonList(group2), 0, -1); + Assert.assertNotNull(resources2); + Assert.assertEquals(2, resources2.size()); + Assert.assertFalse(resources2.contains(resource1)); + Assert.assertTrue(resources2.contains(resource2)); + Assert.assertTrue(resources2.contains(resource3)); + } - public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, Identity identity, - boolean ownedById, boolean attendedById, OLATResource resource, int firstResult, int maxResults) + @Test + public void isIdentityInBusinessGroupNameOwner() { + //create relations + Identity id = JunitTestHelper.createAndPersistIdentityAsUser(UUID.randomUUID().toString()); + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bgis-1", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + securityManager.addIdentityToSecurityGroup(id, group1.getOwnerGroup()); + dbInstance.commitAndCloseSession(); + + //check + boolean test1 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bgis-1", resource1); + Assert.assertTrue(test1); + //name doesn't exist + boolean test2 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bgis-2", resource1); + Assert.assertFalse(test2); + //case insensitive + boolean test3 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bgis-1".toUpperCase(), resource1); + Assert.assertTrue(test3); + //wrong resource + boolean test4 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bgis-1", resource3); + Assert.assertFalse(test4); + } + + @Test + public void isIdentityInBusinessGroupNameParticipant() { + //create relations + Identity id = JunitTestHelper.createAndPersistIdentityAsUser(UUID.randomUUID().toString()); + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-1", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + securityManager.addIdentityToSecurityGroup(id, group1.getPartipiciantGroup()); + + dbInstance.commitAndCloseSession(); + + //check + boolean test1 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bg-part-1", resource1); + Assert.assertTrue(test1); + //name doesn't exist + boolean test2 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bg-part-2", resource1); + Assert.assertFalse(test2); + //case insensitive + boolean test3 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bg-part-1".toUpperCase(), resource1); + Assert.assertTrue(test3); + //wrong resource + boolean test4 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bg-part-1", resource3); + Assert.assertFalse(test4); + } + + @Test + public void checkIfOneOrMoreNameExistsInContextByResource() { + //prepare 2 resources and 3 groups + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + + BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); -public int countMembersOf(OLATResource resource, boolean owner, boolean attendee) + dbInstance.commitAndCloseSession(); - public List<Identity> getMembersOf(OLATResource resource, boolean owner, boolean attendee) + //check with empty set (must return without exception) + boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), resource1); + Assert.assertFalse(test0); + + //check if name of group 1 is in resource 1 + Set<String> name1 = Collections.singleton("rel-bg-part-one"); + boolean test1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, resource1); + Assert.assertTrue(test1); + + //check if name of group 1 and 2 is in resource 1 + Set<String> name1_2 = new HashSet<String>(); + name1_2.add("rel-bg-part-one"); + name1_2.add("rel-bg-part-two"); + boolean test2_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_2, resource1); + Assert.assertTrue(test2_1); + //check if name of group 1 and 2 is in resource 1 + boolean test2_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_2, resource2); + Assert.assertTrue(test2_2); + + //check if name of group 1 and 2 is in resource 1 + Set<String> name3 = Collections.singleton("rel-bg-part-three"); + boolean test3_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name3, resource1); + Assert.assertFalse(test3_1); + //check if name of group 1 and 2 is in resource 2 + boolean test3_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name3, resource2); + Assert.assertTrue(test3_2); + + //check if name of group 1 and something else is in resource 1 + Set<String> name2_4 = new HashSet<String>(); + name2_4.add("rel-bg-part-two"); + name2_4.add("rel-bg-part-four"); + boolean test4_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resource1); + Assert.assertTrue(test4_1); + boolean test4_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resource2); + Assert.assertFalse(test4_2); + } + @Test + public void checkIfOneOrMoreNameExistsInContextByResourceKeys() { + //prepare 2 resources and 3 groups + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + + BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); + + dbInstance.commitAndCloseSession(); + + //check with empty set (must return without exception) + boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), resource1); + Assert.assertFalse(test0); + + List<Long> resourceKey1 = Collections.singletonList(resource1.getKey()); + List<Long> resourceKey2 = Collections.singletonList(resource2.getKey()); + List<Long> resourceKey1_2 = new ArrayList<Long>(); + resourceKey1_2.add(resource1.getKey()); + resourceKey1_2.add(resource2.getKey()); + + //check empty lists + Set<String> emptyName = Collections.<String>emptySet(); + boolean test0_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(emptyName, resourceKey1); + Assert.assertFalse(test0_1); + //empty keys + Set<String> name1 = Collections.singleton("rel-bg-part-one"); + List<Long> emptyKey = Collections.<Long>emptyList(); + boolean test0_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, emptyKey); + Assert.assertFalse(test0_2); + //all empty + boolean test0_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(emptyName, emptyKey); + Assert.assertFalse(test0_3); + + //check if name of group 1 is in resource 1 + boolean test1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, resourceKey1); + Assert.assertTrue(test1); + + //check if name of group 2 and something else is in resource 1 + Set<String> name2_4 = new HashSet<String>(); + name2_4.add("rel-bg-part-two"); + name2_4.add("rel-bg-part-four"); + boolean test4_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resourceKey1); + Assert.assertTrue(test4_1); + boolean test4_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resourceKey2); + Assert.assertFalse(test4_2); + + //check if name of group 1 and 3 is in resource 1 + Set<String> name1_3 = new HashSet<String>(); + name1_3.add("rel-bg-part-one"); + name1_3.add("rel-bg-part-three"); + boolean test5_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_3, resourceKey1); + Assert.assertTrue(test5_1); + boolean test5_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_3, resourceKey2); + Assert.assertTrue(test5_2); + + //check if a lot of keys and names make problems + Set<String> nameBig = new HashSet<String>(); + for(int i=0; i<10000; i++) { + nameBig.add("rel-bg-part-" + 1); + } + List<Long> keyBig = new ArrayList<Long>(); + for(int i=0; i<10000; i++) { + keyBig.add(new Long(800000 + i)); + } + boolean test6_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); + Assert.assertFalse(test6_1); + //check with the same log of + something real + nameBig.add("rel-bg-part-two"); + keyBig.add(resource2.getKey()); + boolean test7_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); + Assert.assertFalse(test7_1); + //add resource 2 + keyBig.add(resource1.getKey()); + boolean test8_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); + Assert.assertTrue(test8_1); + } + @Test + public void checkIfOneOrMoreNameExistsInContextByGroup() { + //prepare 2 resources and 3 groups + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + OLATResource resource3 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + + BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); + + BusinessGroup group4 = businessGroupDao.createAndPersist(null, "rel-bg-part-four", "rel-bgis-4-desc", -1, -1, false, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group4, resource3); + + dbInstance.commitAndCloseSession(); + + //check with empty set (must return without exception) + boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), group1); + Assert.assertFalse(test0); + + //check name 1 + Set<String> name1 = Collections.singleton("rel-bg-part-one"); + boolean test1_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group1); + Assert.assertTrue(test1_1); + boolean test1_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group2); + Assert.assertTrue(test1_2); + boolean test1_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group3); + Assert.assertTrue(test1_3); + boolean test1_4 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group4); + Assert.assertFalse(test1_4); + + //check name 2 + Set<String> name2 = Collections.singleton("rel-bg-part-one"); + boolean test2_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group1); + Assert.assertTrue(test2_1); + boolean test2_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group2); + Assert.assertTrue(test2_2); + boolean test2_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group3); + Assert.assertTrue(test2_3); + boolean test2_4 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group4); + Assert.assertFalse(test2_4); + } + + @Test + public void findBusinessGroupsWithWaitingListAttendedBy() { + //prepare 2 resources + 3 groups and 4 ids + Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString()); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString()); + Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString()); + Identity id4 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString()); + + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + securityManager.addIdentityToSecurityGroup(id1, group1.getWaitingGroup()); + securityManager.addIdentityToSecurityGroup(id4, group1.getWaitingGroup()); + + BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + securityManager.addIdentityToSecurityGroup(id2, group2.getWaitingGroup()); + securityManager.addIdentityToSecurityGroup(id4, group2.getWaitingGroup()); + + BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); + securityManager.addIdentityToSecurityGroup(id3, group3.getWaitingGroup()); + + dbInstance.commitAndCloseSession(); + + //check id 1 is in resource 1 + List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id1, resource1); + Assert.assertNotNull(groups1_1); + Assert.assertEquals(1, groups1_1.size()); + Assert.assertTrue(groups1_1.contains(group1)); + //check if id 1 is in resource 2 + List<BusinessGroup> groups1_2 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id1, resource2); + Assert.assertNotNull(groups1_2); + Assert.assertEquals(1, groups1_2.size()); + Assert.assertTrue(groups1_2.contains(group1)); + + //check id 2 is in resource 1 + List<BusinessGroup> groups2_1 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id2, resource1); + Assert.assertNotNull(groups2_1); + Assert.assertEquals(1, groups2_1.size()); + Assert.assertTrue(groups2_1.contains(group2)); + //check if id 2 is in resource 2 + List<BusinessGroup> groups2_2 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id2, resource2); + Assert.assertNotNull(groups2_2); + Assert.assertEquals(0, groups2_2.size()); + + //check id 4 is in resource 1 + List<BusinessGroup> groups4_1 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id4, resource1); + Assert.assertNotNull(groups4_1); + Assert.assertEquals(2, groups4_1.size()); + Assert.assertTrue(groups4_1.contains(group1)); + Assert.assertTrue(groups4_1.contains(group2)); + //check if id 2 is in resource 2 + List<BusinessGroup> groups4_2 = businessGroupDao.findBusinessGroupsWithWaitingListAttendedBy(id4, resource2); + Assert.assertNotNull(groups4_2); + Assert.assertEquals(1, groups4_2.size()); + Assert.assertTrue(groups4_2.contains(group1)); + } + + @Test + public void findAndCountBusinessGroups() { + //prepare 2 resources + 3 groups with 3 owners + Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString()); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString()); + Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString()); + + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + businessGroupRelationDao.addRelationToResource(group1, resource2); + + BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + + BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); + + dbInstance.commitAndCloseSession(); + + SearchBusinessGroupParams params = new SearchBusinessGroupParams(); + //check resource 1 + int count1_1 = businessGroupDao.countBusinessGroups(params, null, false, false, resource1); + Assert.assertEquals(2, count1_1); + List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, null, false, false, resource1, 0, -1); + Assert.assertNotNull(groups1_1); + Assert.assertEquals(2, groups1_1.size()); + Assert.assertTrue(groups1_1.contains(group1)); + Assert.assertTrue(groups1_1.contains(group2)); + + //check owner 1 + resource 1 + int count3_1 = businessGroupDao.countBusinessGroups(params, id1, true, true, resource1); + Assert.assertEquals(1, count3_1); + List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(params, id1, true, true, resource1, 0, -1); + Assert.assertNotNull(groups3_1); + Assert.assertEquals(1, groups3_1.size()); + Assert.assertEquals(group1, groups3_1.get(0)); + } - */ + @Test + public void countAndFindMembers() { + //prepare 2 resources + 3 groups with 3 owners + Identity owner1 = JunitTestHelper.createAndPersistIdentityAsUser("own-1-" + UUID.randomUUID().toString()); + Identity owner2 = JunitTestHelper.createAndPersistIdentityAsUser("own-2-" + UUID.randomUUID().toString()); + Identity owner3 = JunitTestHelper.createAndPersistIdentityAsUser("own-3-" + UUID.randomUUID().toString()); + + Identity part1 = JunitTestHelper.createAndPersistIdentityAsUser("part-1-" + UUID.randomUUID().toString()); + Identity part2 = JunitTestHelper.createAndPersistIdentityAsUser("part-2-" + UUID.randomUUID().toString()); + Identity part3 = JunitTestHelper.createAndPersistIdentityAsUser("part-3-" + UUID.randomUUID().toString()); + Identity part4 = JunitTestHelper.createAndPersistIdentityAsUser("part-4-" + UUID.randomUUID().toString()); + + OLATResource resource1 = JunitTestHelper.createRandomResource(); + OLATResource resource2 = JunitTestHelper.createRandomResource(); + + BusinessGroup group1 = businessGroupDao.createAndPersist(owner1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group1, resource1); + securityManager.addIdentityToSecurityGroup(part1, group1.getPartipiciantGroup()); + securityManager.addIdentityToSecurityGroup(part2, group1.getPartipiciantGroup()); + + BusinessGroup group2 = businessGroupDao.createAndPersist(owner2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group2, resource1); + securityManager.addIdentityToSecurityGroup(owner1, group2.getPartipiciantGroup()); + securityManager.addIdentityToSecurityGroup(part3, group2.getPartipiciantGroup()); + + BusinessGroup group3 = businessGroupDao.createAndPersist(owner3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false); + businessGroupRelationDao.addRelationToResource(group3, resource2); + securityManager.addIdentityToSecurityGroup(part4, group3.getPartipiciantGroup()); + + dbInstance.commitAndCloseSession(); + + //resource 1 owners and participants + int count1_1 = businessGroupRelationDao.countMembersOf(resource1, true, true); + Assert.assertEquals(5, count1_1); + List<Identity> partAndOwners1 = businessGroupRelationDao.getMembersOf(resource1, true, true); + Assert.assertNotNull(partAndOwners1); + Assert.assertEquals(5, partAndOwners1.size()); + Assert.assertTrue(partAndOwners1.contains(owner1)); + Assert.assertTrue(partAndOwners1.contains(owner2)); + Assert.assertTrue(partAndOwners1.contains(part1)); + Assert.assertTrue(partAndOwners1.contains(part2)); + Assert.assertTrue(partAndOwners1.contains(part3)); + + //resource 1 owners + int count2_1 = businessGroupRelationDao.countMembersOf(resource1, true, false); + Assert.assertEquals(2, count2_1); + List<Identity> owners2 = businessGroupRelationDao.getMembersOf(resource1, true, false); + Assert.assertNotNull(owners2); + Assert.assertEquals(2, owners2.size()); + Assert.assertTrue(owners2.contains(owner1)); + Assert.assertTrue(owners2.contains(owner2)); + + //resource 1 participants + int count3_1 = businessGroupRelationDao.countMembersOf(resource1, false, true); + Assert.assertEquals(4, count3_1); + List<Identity> participant3 = businessGroupRelationDao.getMembersOf(resource1, false, true); + Assert.assertNotNull(participant3); + Assert.assertEquals(4, participant3.size()); + Assert.assertTrue(participant3.contains(owner1)); + Assert.assertTrue(participant3.contains(part1)); + Assert.assertTrue(participant3.contains(part2)); + Assert.assertTrue(participant3.contains(part3)); + + //resource 2 owners and participants + int count4_1 = businessGroupRelationDao.countMembersOf(resource2, true, true); + Assert.assertEquals(2, count4_1); + List<Identity> partAndOwners4 = businessGroupRelationDao.getMembersOf(resource2, true, true); + Assert.assertNotNull(partAndOwners4); + Assert.assertEquals(2, partAndOwners4.size()); + Assert.assertTrue(partAndOwners4.contains(owner3)); + Assert.assertTrue(partAndOwners4.contains(part4)); + //resource 1 owners + int count5_1 = businessGroupRelationDao.countMembersOf(resource2, true, false); + Assert.assertEquals(1, count5_1); + List<Identity> owners5 = businessGroupRelationDao.getMembersOf(resource2, true, false); + Assert.assertNotNull(owners5); + Assert.assertEquals(1, owners5.size()); + Assert.assertTrue(owners5.contains(owner3)); + + //resource 1 participants + int count6_1 = businessGroupRelationDao.countMembersOf(resource2, false, true); + Assert.assertEquals(1, count6_1); + List<Identity> participant6 = businessGroupRelationDao.getMembersOf(resource2, false, true); + Assert.assertNotNull(participant6); + Assert.assertEquals(1, participant6.size()); + Assert.assertTrue(participant6.contains(part4)); + } } diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java index 4a8498bff15120540efb1c0e1a8a0dfe77b64071..53efbf2e268a35a9961808b56007692b6c768334 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java @@ -39,6 +39,7 @@ import java.util.UUID; import org.apache.log4j.Logger; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.olat.basesecurity.BaseSecurityManager; @@ -125,10 +126,10 @@ public class BusinessGroupServiceImplTest extends OlatTestCase { if(initialize) return; // Identities - id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1"); - id2 = JunitTestHelper.createAndPersistIdentityAsUser("id2"); - id3 = JunitTestHelper.createAndPersistIdentityAsUser("id3"); - id4 = JunitTestHelper.createAndPersistIdentityAsUser("id4"); + id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1-bgs-" + UUID.randomUUID().toString()); + id2 = JunitTestHelper.createAndPersistIdentityAsUser("id2-bgs-" + UUID.randomUUID().toString()); + id3 = JunitTestHelper.createAndPersistIdentityAsUser("id3-bgs-" + UUID.randomUUID().toString()); + id4 = JunitTestHelper.createAndPersistIdentityAsUser("id4-bgs-" + UUID.randomUUID().toString()); // buddyGroups without waiting-list: groupcontext is null List<BusinessGroup> l = businessGroupService.findBusinessGroupsOwnedBy(id1, null); if (l.size() == 0) { @@ -205,6 +206,8 @@ public class BusinessGroupServiceImplTest extends OlatTestCase { @Test public void testCheckIfNamesExistsInContext() throws Exception { suiteIsAborted = true; + + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("id5-check-" + UUID.randomUUID().toString()); OLATResource ctxA = JunitTestHelper.createRandomResource(); OLATResource ctxB = JunitTestHelper.createRandomResource(); @@ -215,11 +218,11 @@ public class BusinessGroupServiceImplTest extends OlatTestCase { BusinessGroup[] ctxBgroups = new BusinessGroup[namesInCtxB.length]; for (int i = 0; i < namesInCtxA.length; i++) { - ctxAgroups[i] = businessGroupService.createBusinessGroup(id1, namesInCtxA[i], null, 0, 0, false, + ctxAgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxA[i], null, 0, 0, false, false, ctxA); } for (int i = 0; i < namesInCtxB.length; i++) { - ctxBgroups[i] = businessGroupService.createBusinessGroup(id1, namesInCtxB[i], null, 0, 0, false, + ctxBgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxB[i], null, 0, 0, false, false, ctxB); } // first click created two context and each of them containg groups @@ -299,71 +302,43 @@ public class BusinessGroupServiceImplTest extends OlatTestCase { @Test public void testCreateAndPersistBuddyGroup() throws Exception { suiteIsAborted = true; - /* - * - */ - List<BusinessGroup> sqlRes; - BusinessGroup found; - /* - * id1 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id1, null); - assertTrue("2 BuddyGroups owned by id1", sqlRes.size() == 2); - for (int i = 0; i < sqlRes.size(); i++) { - assertTrue("It's a BuddyGroup Object", sqlRes.get(i) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(i); - // equality by comparing PersistenObject.getKey()!!! - boolean ok = one.getKey().longValue() == found.getKey().longValue() || three.getKey().longValue() == found.getKey().longValue(); - assertTrue("It's the correct BuddyGroup", ok); - } - sqlRes = businessGroupService.findBusinessGroupsAttendedBy(id1, null); - assertTrue("0 BuddyGroup where id1 is partipicating", sqlRes.size() == 0); + // id1 + List<BusinessGroup> groupOwnedId1 = businessGroupService.findBusinessGroupsOwnedBy(id1, null); + Assert.assertEquals("2 BuddyGroups owned by id1", 3, groupOwnedId1.size()); + Assert.assertTrue(groupOwnedId1.contains(one)); + Assert.assertTrue(groupOwnedId1.contains(three)); + Assert.assertTrue(groupOwnedId1.contains(bgWithWaitingList)); - /* - * id2 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1); - assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(0); - // equality by comparing PersistenObject.getKey()!!! - assertTrue("It's the correct BuddyGroup", two.getKey().longValue() == found.getKey().longValue()); - sqlRes = businessGroupService.findBusinessGroupsAttendedBy(id2, null); - assertTrue("1 BuddyGroup where id2 is partipicating", sqlRes.size() == 1); - assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(0); - assertTrue("It's the correct BuddyGroup", three.getKey().longValue() == found.getKey().longValue()); + List<BusinessGroup> groupAttendeeId1 = businessGroupService.findBusinessGroupsAttendedBy(id1, null); + Assert.assertEquals("0 BuddyGroup where id1 is partipicating", 0, groupAttendeeId1.size()); - /* - * id3 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id3, null); - assertTrue("1 BuddyGroup owned by id3", sqlRes.size() == 1); - assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(0); - // equality by comparing PersistenObject.getKey()!!! - assertTrue("It's the correct BuddyGroup", three.getKey().longValue() == found.getKey().longValue()); - sqlRes = businessGroupService.findBusinessGroupsAttendedBy(id3, null); - assertTrue("1 BuddyGroup where id3 is partipicating", sqlRes.size() == 1); - assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(0); - assertTrue("It's the correct BuddyGroup", two.getKey().longValue() == found.getKey().longValue()); + // id2 + List<BusinessGroup> groupOwnedId2 = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + Assert.assertEquals("1 BuddyGroup owned by id2", 1, groupOwnedId2.size()); + Assert.assertTrue(groupOwnedId2.contains(two)); + + List<BusinessGroup> groupAttendeeId2 = businessGroupService.findBusinessGroupsAttendedBy(id2, null); + Assert.assertEquals("1 BuddyGroup where id2 is partipicating", 1, groupAttendeeId2.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId2.contains(three)); + + // id3 + List<BusinessGroup> groupOwnedId3 = businessGroupService.findBusinessGroupsOwnedBy(id3, null); + Assert.assertEquals("1 BuddyGroup owned by id3", 1, groupOwnedId3.size()); + assertTrue("It's the correct BuddyGroup", groupOwnedId3.contains(three)); + + List<BusinessGroup> groupAttendeeId3 = businessGroupService.findBusinessGroupsAttendedBy(id3, null); + Assert.assertEquals("1 BuddyGroup where id3 is partipicating", 1, groupAttendeeId3.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId3.contains(two)); + + // id4 + List<BusinessGroup> groupOwnedId4 = businessGroupService.findBusinessGroupsOwnedBy(id4, null); + Assert.assertEquals("0 BuddyGroup owned by id4", 0, groupOwnedId4.size()); + + List<BusinessGroup> groupAttendeeId4 = businessGroupService.findBusinessGroupsAttendedBy(id4, null); + Assert.assertEquals("1 BuddyGroup where id4 is partipicating", 1, groupAttendeeId4.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId4.contains(two)); - /* - * id4 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id4, null); - assertTrue("0 BuddyGroup owned by id4", sqlRes.size() == 0); - // - sqlRes = businessGroupService.findBusinessGroupsAttendedBy(id4, null); - assertTrue("1 BuddyGroup where id4 is partipicating", sqlRes.size() == 1); - assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); - found = (BusinessGroup) sqlRes.get(0); - assertTrue("It's the correct BuddyGroup", two.getKey().longValue() == found.getKey().longValue()); - /* - * - */ suiteIsAborted = false; nrOfTestCasesAlreadyRun++; } diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java index 1890c1e0dd6d928afb927dcb6754e0494cfba465..ee5b3b73cfad9b95660c08ec59c57bd549630b88 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java @@ -1,3 +1,22 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ package org.olat.group.test; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/org/olat/restapi/ContactsTest.java b/src/test/java/org/olat/restapi/ContactsTest.java index 0c3b13a758c7123af36e3b410d09c8651135fbb5..b03f6a7e73ecbae9876e6bac0ae551bb23bc126f 100644 --- a/src/test/java/org/olat/restapi/ContactsTest.java +++ b/src/test/java/org/olat/restapi/ContactsTest.java @@ -113,45 +113,47 @@ public class ContactsTest extends OlatJerseyTestCase { DBFactory.getInstance().intermediateCommit(); //create learn group - BaseSecurity secm = BaseSecurityManager.getInstance(); - - // 1) context one: learning groups - OLATResource c1 = JunitTestHelper.createRandomResource(); - // create groups without waiting list - g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, new Integer(0), new Integer(10), false, false, c1); - - //permission to see owners and participants - BusinessGroupPropertyManager bgpm1 = new BusinessGroupPropertyManager(g1); - bgpm1.updateDisplayMembers(false, false, false); - BusinessGroupPropertyManager bgpm2 = new BusinessGroupPropertyManager(g2); - bgpm2.updateDisplayMembers(true, true, false); - - // members g1 - secm.addIdentityToSecurityGroup(owner1, g1.getOwnerGroup()); - secm.addIdentityToSecurityGroup(owner2, g1.getOwnerGroup()); - secm.addIdentityToSecurityGroup(part1, g1.getPartipiciantGroup()); - secm.addIdentityToSecurityGroup(part2, g1.getPartipiciantGroup()); - - // members g2 - secm.addIdentityToSecurityGroup(owner1, g2.getOwnerGroup()); - secm.addIdentityToSecurityGroup(part1, g2.getPartipiciantGroup()); - - - // 2) context two: right groups - OLATResource c2 = JunitTestHelper.createRandomResource(); - // groups - g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2); - g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2); - // members -> default participants are visible - secm.addIdentityToSecurityGroup(owner1, g3.getPartipiciantGroup()); - secm.addIdentityToSecurityGroup(part3, g3.getPartipiciantGroup()); - - secm.addIdentityToSecurityGroup(owner2, g4.getPartipiciantGroup()); - secm.addIdentityToSecurityGroup(part3, g4.getPartipiciantGroup()); - - DBFactory.getInstance().commitAndCloseSession(); // simulate user clicks - initialized = true; + BaseSecurity secm = BaseSecurityManager.getInstance(); + + // 1) context one: learning groups + OLATResource c1 = JunitTestHelper.createRandomResource(); + // create groups without waiting list + g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1); + + //permission to see owners and participants + BusinessGroupPropertyManager bgpm1 = new BusinessGroupPropertyManager(g1); + bgpm1.updateDisplayMembers(false, false, false); + BusinessGroupPropertyManager bgpm2 = new BusinessGroupPropertyManager(g2); + bgpm2.updateDisplayMembers(true, true, false); + + // members g1 + secm.addIdentityToSecurityGroup(owner1, g1.getOwnerGroup()); + secm.addIdentityToSecurityGroup(owner2, g1.getOwnerGroup()); + secm.addIdentityToSecurityGroup(part1, g1.getPartipiciantGroup()); + secm.addIdentityToSecurityGroup(part2, g1.getPartipiciantGroup()); + + // members g2 + secm.addIdentityToSecurityGroup(owner1, g2.getOwnerGroup()); + secm.addIdentityToSecurityGroup(part1, g2.getPartipiciantGroup()); + + + // 2) context two: right groups + OLATResource c2 = JunitTestHelper.createRandomResource(); + // groups + g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2); + new BusinessGroupPropertyManager(g3).updateDisplayMembers(false, true, false); + g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2); + new BusinessGroupPropertyManager(g4).updateDisplayMembers(false, true, false); + // members -> default participants are visible + secm.addIdentityToSecurityGroup(owner1, g3.getPartipiciantGroup()); + secm.addIdentityToSecurityGroup(part3, g3.getPartipiciantGroup()); + + secm.addIdentityToSecurityGroup(owner2, g4.getPartipiciantGroup()); + secm.addIdentityToSecurityGroup(part3, g4.getPartipiciantGroup()); + + DBFactory.getInstance().commitAndCloseSession(); // simulate user clicks + initialized = true; } @Test diff --git a/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java b/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java index a1c6fde8926654136dcc73615f416d5dea5b27bd..9e08d661326283822847668a3ef0eee96864b9bd 100644 --- a/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java +++ b/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java @@ -161,7 +161,7 @@ public class CourseGroupMgmtTest extends OlatJerseyTestCase { List<GroupVO> vos = parseGroupArray(body); assertNotNull(vos); - assertEquals(2, vos.size());//g1, g2, g3, g4 + assertEquals(4, vos.size());//g1, g2, g3, g4 List<Long> voKeys = new ArrayList<Long>(4); for(GroupVO vo:vos) { @@ -169,8 +169,8 @@ public class CourseGroupMgmtTest extends OlatJerseyTestCase { } assertTrue(voKeys.contains(g1.getKey())); assertTrue(voKeys.contains(g2.getKey())); - //assertTrue(voKeys.contains(g3.getKey())); - //assertTrue(voKeys.contains(g4.getKey())); + assertTrue(voKeys.contains(g3.getKey())); + assertTrue(voKeys.contains(g4.getKey())); } @Test diff --git a/src/test/java/org/olat/restapi/UserMgmtTest.java b/src/test/java/org/olat/restapi/UserMgmtTest.java index 218644dbff4543b2677b77df8b214d27c47ed16c..af89e29b994b5cfefd4c20b1b1fa8a112f830f7f 100644 --- a/src/test/java/org/olat/restapi/UserMgmtTest.java +++ b/src/test/java/org/olat/restapi/UserMgmtTest.java @@ -774,7 +774,7 @@ public class UserMgmtTest extends OlatJerseyTestCase { InputStream body = response.getEntity().getContent(); List<GroupVO> groups = parseGroupArray(body); assertNotNull(groups); - assertEquals(2, groups.size());//g1 and g2 as g3 and g4 are right groups which are not returned + assertEquals(3, groups.size());//g1, g2 and g3 } @Test @@ -793,7 +793,7 @@ public class UserMgmtTest extends OlatJerseyTestCase { assertNotNull(groups); assertNotNull(groups.getGroups()); assertEquals(1, groups.getGroups().length); - assertEquals(2, groups.getTotalCount());//g1 and g2 as g3 and g4 are right groups which are not returned + assertEquals(3, groups.getTotalCount());//g1, g2 and g3 } @Test @@ -812,7 +812,7 @@ public class UserMgmtTest extends OlatJerseyTestCase { assertNotNull(groups); assertNotNull(groups.getGroups()); assertEquals(1, groups.getGroups().length); - assertEquals(2, groups.getTotalCount());//g1 and g2 as g3 and g4 are right groups which are not returned + assertEquals(3, groups.getTotalCount());//g1, g2 and g3 } @Test diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index ce49e885bb51db62f05123fcb5439b8aca28c136..eb89bc1d3dfa3f5771fd302b171b5419fcb459e0 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -74,9 +74,12 @@ import org.junit.runners.Suite; org.olat.commons.coordinate.cluster.lock.LockTest.class,//ok org.olat.commons.coordinate.CoordinatorTest.class,//ok org.olat.admin.user.delete.service.UserDeletionManagerTest.class,//ok - org.olat.group.test.BGRightManagerTest.class,//fail + org.olat.group.test.BGRightManagerTest.class,//ok org.olat.group.test.BGAreaManagerTest.class,//ok + org.olat.group.test.BusinessGroupServiceTest.class,//ok org.olat.group.test.BusinessGroupServiceImplTest.class,//ok + org.olat.group.test.BusinessGroupDAOTest.class,//ok + org.olat.group.test.BusinessGroupRelationDAOTest.class,//ok org.olat.resource.lock.pessimistic.PLockTest.class,//ok org.olat.resource.references.ReferenceManagerTest.class,//ok org.olat.resource.OLATResourceManagerTest.class,//ok