/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.group;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.log4j.Logger;
import org.olat.basesecurity.Manager;
import org.olat.basesecurity.ManagerFactory;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.AssertException;
import org.olat.core.test.OlatTestCase;
import org.olat.core.util.resource.OresHelper;
import org.olat.course.groupsandrights.CourseGroupManager;
import org.olat.course.groupsandrights.CourseRights;
import org.olat.course.groupsandrights.PersistingCourseGroupManager;
import org.olat.group.area.BGArea;
import org.olat.group.area.BGAreaManager;
import org.olat.group.area.BGAreaManagerImpl;
import org.olat.group.context.BGContext;
import org.olat.group.context.BGContextManager;
import org.olat.group.context.BGContextManagerImpl;
import org.olat.group.right.BGRightManager;
import org.olat.group.right.BGRightManagerImpl;
import org.olat.resource.OLATResource;
import org.olat.resource.OLATResourceManager;
import org.olat.test.JunitTestHelper;
/**
* Description:<BR>
* Initial Date: Aug 18, 2004
*
* @author gnaegi
*/
public class BusinessGroupTest extends OlatTestCase {
private static Logger log = Logger.getLogger(BusinessGroupTest.class.getName());
private Identity id1, id2, id3, id4;
private OLATResource course1;
/**
* @param arg
*/
public BusinessGroupTest(String arg) {
super(arg);
}
/**
* SetUp is called before each test.
*/
public void setUp() {
try {
super.setUp();
DBFactory.getJunitInstance().clearDatabase();
id1 = JunitTestHelper.createAndPersistIdentityAsUser("one");
id2 = JunitTestHelper.createAndPersistIdentityAsUser("twoo");
id3 = JunitTestHelper.createAndPersistIdentityAsUser("three");
id4 = JunitTestHelper.createAndPersistIdentityAsUser("four");
DB db = DBFactory.getInstance();
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", new Long(456));
course1 = rm.createOLATResourceInstance(resourceable);
db.saveObject(course1);
DBFactory.getInstance().closeSession();
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
e.printStackTrace();
}
}
/**
* @return the test suite
* @throws Exception
*/
public static Test suite() throws Exception {
try {
return new TestSuite(BusinessGroupTest.class);
} catch (Exception e) {
log.error("Exception in suite(): " + e);
e.printStackTrace();
throw e;
}
}
/**
* TearDown is called after each test.
*
* @throws Exception
*/
public void tearDown() throws Exception {
try {
super.tearDown();
DBFactory.getInstance().closeSession();
} catch (Exception e) {
log.error("Exception in tearDown(): " + e);
e.printStackTrace();
throw e;
}
}
/** BGContextManagerImpl:createAndPersistBGContext * */
public void testCreateAndPersistBGContext() {
BGContextManager bgcm = BGContextManagerImpl.getInstance();
BGContext c1 = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true);
assertNotNull(c1);
BGContext c2 = bgcm.createAndPersistBGContext("c2name", "c2desc", BusinessGroup.TYPE_LEARNINGROUP, id1, false);
assertNotNull(c2);
try {
bgcm.createAndPersistBGContext("name", "desc", null, id2, false);
fail("context groupType can not be null");
} catch (AssertException e) {
// expected exception
assertTrue(true);
}
try {
bgcm.createAndPersistBGContext(null, "desc", BusinessGroup.TYPE_LEARNINGROUP, id2, false);
fail("context name can not be null");
} catch (AssertException e) {
// expected exception
assertTrue(true);
}
}
/** BGContextManagerImpl:deleteBGContext() * */
public void testDeleteBGContext() {
BGContextManager bgcm = BGContextManagerImpl.getInstance();
BGContext c1 = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true);
BGContext c2 = bgcm.createAndPersistBGContext("c2name", "c2desc", BusinessGroup.TYPE_RIGHTGROUP, id1, false);
DBFactory.getInstance().closeSession(); // simulate user clicks
BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance();
BusinessGroup g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g1", null, new Integer(0),
new Integer(10), false, false, c1);
BusinessGroup g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0),
new Integer(10), false, false, c1);
BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g3", null, new Integer(0),
new Integer(10), false, false, c2);
DBFactory.getInstance().closeSession(); // simulate user clicks
Manager secm = ManagerFactory.getManager();
secm.addIdentityToSecurityGroup(id1, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id1, g1.getOwnerGroup());
secm.addIdentityToSecurityGroup(id2, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id3, g1.getOwnerGroup());
secm.addIdentityToSecurityGroup(id4, g2.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id4, g1.getOwnerGroup());
secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id2, g3.getPartipiciantGroup());
BGRightManagerImpl rm = BGRightManagerImpl.getInstance();
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g3);
rm.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id1, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, id1, c2));
assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id2, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id3, c2));
DBFactory.getInstance().closeSession(); // simulate user clicks
BGAreaManager am = BGAreaManagerImpl.getInstance();
BGArea a1 = am.createAndPersistBGAreaIfNotExists("a1-delete", "desca1", c1);
BGArea a2 = am.createAndPersistBGAreaIfNotExists("a2-delete", null, c1);
BGArea a3 = am.createAndPersistBGAreaIfNotExists("a3-delete", "desca3", c1);
BGArea a4 = am.createAndPersistBGAreaIfNotExists("a4-delete", "desca4", c1);
am.addBGToBGArea(g1, a1);
am.addBGToBGArea(g2, a1);
am.addBGToBGArea(g1, a2);
am.addBGToBGArea(g2, a3);
am.addBGToBGArea(g1, a4);
DBFactory.getInstance().closeSession(); // simulate user clicks
// test isIdentityInBGArea
assertTrue(am.isIdentityInBGArea(id1, "a1-delete", c1));
assertTrue(am.isIdentityInBGArea(id1, "a2-delete", c1));
assertFalse(am.isIdentityInBGArea(id1, "a3-delete", c1)); // not in group g2
assertTrue(am.isIdentityInBGArea(id1, "a4-delete", c1));
assertFalse(am.isIdentityInBGArea(id1, "xx", c1)); // wrong area name
assertFalse(am.isIdentityInBGArea(id1, "a1-delete", c2)); // wrong context
assertTrue(am.isIdentityInBGArea(id2, "a1-delete", c1));
assertTrue(am.isIdentityInBGArea(id2, "a2-delete", c1));
assertFalse(am.isIdentityInBGArea(id2, "a3-delete", c1)); // not in group g2
assertTrue(am.isIdentityInBGArea(id2, "a4-delete", c1));
assertTrue(am.isIdentityInBGArea(id3, "a1-delete", c1));
assertTrue(am.isIdentityInBGArea(id3, "a2-delete", c1));
assertFalse(am.isIdentityInBGArea(id3, "a3-delete", c1)); // not in group g2
assertTrue(am.isIdentityInBGArea(id3, "a4-delete", c1));
assertTrue(am.isIdentityInBGArea(id4, "a1-delete", c1));
assertTrue(am.isIdentityInBGArea(id4, "a2-delete", c1));
assertTrue(am.isIdentityInBGArea(id4, "a3-delete", c1));
assertTrue(am.isIdentityInBGArea(id4, "a4-delete", c1));
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.findBGAreasOfBusinessGroup(g1).size() == 3);
assertTrue(am.findBGAreasOfBusinessGroup(g2).size() == 2);
assertTrue(am.findBGAreasOfBusinessGroup(g3).size() == 0);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.findBGAreasOfBGContext(c1).size() == 4);
assertTrue(am.findBGAreasOfBGContext(c2).size() == 0);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.findBusinessGroupsOfArea(a1).size() == 2);
assertTrue(am.findBusinessGroupsOfArea(a2).size() == 1);
assertTrue(am.findBusinessGroupsOfArea(a3).size() == 1);
assertTrue(am.findBusinessGroupsOfArea(a4).size() == 1);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.countBGAreasOfBGContext(c1) == 4);
assertTrue(am.countBGAreasOfBGContext(c2) == 0);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id1, "a1-delete", c1).size() == 1);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id1, "a2-delete", c1).size() == 1);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id1, "a3-delete", c1).size() == 0);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id1, "a4-delete", c1).size() == 1);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id4, "a1-delete", c1).size() == 1);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id4, "a2-delete", c1).size() == 0);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id4, "a3-delete", c1).size() == 1);
assertTrue(am.findBusinessGroupsOfAreaAttendedBy(id4, "a4-delete", c1).size() == 0);
bgcm.deleteBGContext(c1);
// assertNull(DB.getInstance().findObject(BGContextImpl.class,
// c1.getKey()));
bgcm.deleteBGContext(c2);
// assertNull(DB.getInstance().findObject(BGContextImpl.class,
// c2.getKey()));
assertTrue(am.findBGAreasOfBGContext(c1).size() == 0);
assertNull(am.findBGArea("a1-delete", c1));
assertTrue(am.findBGAreasOfBusinessGroup(g1).size() == 0);
assertTrue(am.findBGAreasOfBGContext(c2).size() == 0);
assertNull(am.findBGArea("a2-delete", c1));
assertTrue(am.findBusinessGroupsOfArea(a1).size() == 0);
assertTrue(am.findBusinessGroupsOfArea(a2).size() == 0);
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id1, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, id1, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id2, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id3, c2));
}
/** BGContextManagerImpl:copyBGContext() * */
public void testCopyBGContext() {
BGContextManager bgcm = BGContextManagerImpl.getInstance();
BGContext c1 = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true);
BGContext c2 = bgcm.createAndPersistBGContext("c2name", "c2desc", BusinessGroup.TYPE_RIGHTGROUP, id1, false);
DBFactory.getInstance().closeSession(); // simulate user clicks
BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance();
BusinessGroup g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g1", null, new Integer(0),
new Integer(10), false, false, c1);
BusinessGroup g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0),
new Integer(10), false, false, c1);
BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g3", null, new Integer(0),
new Integer(10), false, false, c2);
DBFactory.getInstance().closeSession(); // simulate user clicks
Manager secm = ManagerFactory.getManager();
secm.addIdentityToSecurityGroup(id1, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id1, g1.getOwnerGroup());
secm.addIdentityToSecurityGroup(id2, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id3, g1.getOwnerGroup());
secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id2, g3.getPartipiciantGroup());
DBFactory.getInstance().closeSession(); // simulate user clicks
BGRightManagerImpl rm = BGRightManagerImpl.getInstance();
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g3);
rm.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3);
DBFactory.getInstance().closeSession(); // simulate user clicks
BGAreaManager am = BGAreaManagerImpl.getInstance();
BGArea a1 = am.createAndPersistBGAreaIfNotExists("a1-copy", "desca1", c1);
BGArea a2 = am.createAndPersistBGAreaIfNotExists("a2-copy", null, c1);
am.addBGToBGArea(g1, a1);
am.addBGToBGArea(g2, a1);
am.addBGToBGArea(g1, a2);
DBFactory.getInstance().closeSession(); // simulate user clicks
BGContext c1copy = bgcm.copyAndAddBGContextToResource(c1.getName(), course1, c1);
DBFactory.getInstance().closeSession(); // simulate user clicks
try {
bgcm.copyAndAddBGContextToResource(c2.getName(), course1, c2);
fail("expecting exeption");
} catch (AssertException e) {
// ok, passed
}
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(am.findBGAreasOfBGContext(c1copy).size() == 2);
assertNotNull(am.findBGArea("a1-copy", c1));
assertNotNull(am.findBGArea("a2-copy", c1));
assertNotNull(bgcm.findGroupOfBGContext(g1.getName(), c1copy));
assertNotNull(bgcm.findGroupOfBGContext(g2.getName(), c1copy));
assertTrue(bgcm.getGroupsOfBGContext(c1copy).size() == 2);
}
/** BGContextManagerImpl:deleteBGContext() * */
public void testBGRights() {
BGContextManager bgcm = BGContextManagerImpl.getInstance();
BGContext c1 = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_RIGHTGROUP, null, true);
BGContext c2 = bgcm.createAndPersistBGContext("c2name", "c2desc", BusinessGroup.TYPE_RIGHTGROUP, id1, false);
BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance();
BusinessGroup g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g1", null, null, null, false, false, c1);
BusinessGroup g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g2", null, null, null, false, false, c1);
BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g3", null, null, null, false, false, c2);
Manager secm = ManagerFactory.getManager();
secm.addIdentityToSecurityGroup(id1, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id2, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id1, g2.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id3, g3.getPartipiciantGroup());
BGRightManager rm = BGRightManagerImpl.getInstance();
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g1);
rm.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g1);
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g2);
rm.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3);
DBFactory.getInstance().closeSession(); // simulate user clicks
// secm.createAndPersistPolicy(rightGroup.getPartipiciantGroup(), bgRight,
// rightGroup.getGroupContext());
List groups = secm.getGroupsWithPermissionOnOlatResourceable(CourseRights.RIGHT_ARCHIVING, g1.getGroupContext());
assertTrue(groups.size() == 2);
List identities = secm.getIdentitiesWithPermissionOnOlatResourceable(CourseRights.RIGHT_ARCHIVING, g1.getGroupContext());
assertTrue(identities.size() == 2);
List policies = secm.getPoliciesOfSecurityGroup(g1.getPartipiciantGroup());
assertTrue(policies.size() == 3); // read, archiving, courseeditor
DBFactory.getInstance().closeSession(); // simulate user clicks
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id1, c2));
assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id1, c1));
assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id2, c1));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, id2, c1));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id3, c2));
assertTrue(rm.hasBGRight(CourseRights.RIGHT_COURSEEDITOR, id3, c2));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_COURSEEDITOR, id3, c1));
/*
* assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, g1));
* assertTrue(rm.hasBGRight(CourseRights.RIGHT_COURSEEDITOR, g1));
* assertTrue(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, g2));
* assertFalse(rm.hasBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, g1));
*/
assertTrue(rm.findBGRights(g1).size() == 2);
assertTrue(rm.findBGRights(g2).size() == 1);
DBFactory.getInstance().closeSession(); // simulate user clicks
rm.removeBGRight(CourseRights.RIGHT_ARCHIVING, g1);
rm.removeBGRight(CourseRights.RIGHT_COURSEEDITOR, g1);
rm.removeBGRight(CourseRights.RIGHT_ARCHIVING, g2);
rm.removeBGRight(CourseRights.RIGHT_COURSEEDITOR, g3);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id1, c1));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_ARCHIVING, id2, c1));
assertFalse(rm.hasBGRight(CourseRights.RIGHT_COURSEEDITOR, id3, c2));
assertTrue(rm.findBGRights(g1).size() == 0);
assertTrue(rm.findBGRights(g2).size() == 0);
}
/** BGContextManagerImpl:getGroupsOfBGContext and countGroupsOfBGContext* */
public void testGroupsOfBGContext() {
BGContextManager bgcm = BGContextManagerImpl.getInstance();
BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance();
BGContext c1 = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true);
BGContext c2 = bgcm.createAndPersistBGContext("c2name", "c2desc", BusinessGroup.TYPE_LEARNINGROUP, id1, false);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(bgcm.getGroupsOfBGContext(c1).size() == 0);
assertTrue(bgcm.countGroupsOfBGContext(c1) == 0);
DBFactory.getInstance().closeSession(); // simulate user clicks
BusinessGroup g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g1", null, new Integer(0),
new Integer(10), false, false, c1);
assertNotNull(g1);
BusinessGroup g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0),
new Integer(10), false, false, c1);
assertNotNull(g2);
BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g3", null, new Integer(0),
new Integer(10), false, false, c2);
assertNotNull(g3);
BusinessGroup g2douplicate = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0),
new Integer(10), false, false, c1);
assertNull(g2douplicate); // name douplicate names allowed per group context
BusinessGroup g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0),
new Integer(10), false, false, c2);
assertNotNull(g4); // name douplicate in other context allowed
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(bgcm.getGroupsOfBGContext(c1).size() == 2);
assertTrue(bgcm.countGroupsOfBGContext(c1) == 2);
}
/** BGContext2ResourceManager tests */
public void testFindContextMethods() {
BGContextManager cm = BGContextManagerImpl.getInstance();
BGContext c1 = cm.createAndAddBGContextToResource("c1name", course1, BusinessGroup.TYPE_LEARNINGROUP, null, true);
cm.createAndAddBGContextToResource("c2name", course1, BusinessGroup.TYPE_LEARNINGROUP, id1, false);
cm.createAndAddBGContextToResource("c3name", course1, BusinessGroup.TYPE_RIGHTGROUP, id2, false);
DBFactory.getInstance().closeSession(); // simulate user clicks
assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 3);
assertTrue(cm.findBGContextsForResource(course1, true, false).size() == 1);
assertTrue(cm.findBGContextsForResource(course1, false, true).size() == 2);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 2);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 1);
assertTrue(cm.findBGContextsForIdentity(id1, true, true).size() == 1);
assertTrue(cm.findBGContextsForIdentity(id1, true, false).size() == 0);
assertTrue(cm.findBGContextsForIdentity(id1, false, true).size() == 1);
DBFactory.getInstance().closeSession(); // simulate user clicks
cm.removeBGContextFromResource(c1, course1);
assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 2);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 1);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 1);
DBFactory.getInstance().closeSession(); // simulate user clicks
// cm.removeAllBGContextsFromResource(course1);
CourseGroupManager cgm = PersistingCourseGroupManager.getInstance(course1);
cgm.deleteCourseGroupmanagement();
assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 0);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 0);
assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 0);
}
public void testRemoveBGFromArea() {
BGContextManager cm = BGContextManagerImpl.getInstance();
BGContext bgContext = cm.createAndAddBGContextToResource("c2name", course1, BusinessGroup.TYPE_LEARNINGROUP, null, true);
assertEquals( 1,cm.findBGContextsForResource(course1, true, true).size() );
cm.removeBGContextFromResource(bgContext, course1);
assertEquals( 0,cm.findBGContextsForResource(course1, true, true).size() );
}
}