secm.addIdentityToSecurityGroup(id1, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id2, g1.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id2, g2.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id3, g1.getOwnerGroup());
// areas
BGArea a1 = am.createAndPersistBGAreaIfNotExists("a1", "desca1",c1);
BGArea a2 = am.createAndPersistBGAreaIfNotExists("a2", null, c1);
BGArea a3 = am.createAndPersistBGAreaIfNotExists("a3", null, c1);
am.addBGToBGArea(g1, a1);
am.addBGToBGArea(g2, a1);
am.addBGToBGArea(g1, a2);
am.addBGToBGArea(g2, a3);
// 2) context two: right groups
BGContext c2 = cm.createAndAddBGContextToResource("c2name", course1, BusinessGroup.TYPE_RIGHTGROUP, id2, true);
// groups
BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2);
BusinessGroup g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2);
// members
secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id1, g4.getPartipiciantGroup());
secm.addIdentityToSecurityGroup(id3, g4.getPartipiciantGroup());
// rights
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g3);
rm.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3);
rm.addBGRight(CourseRights.RIGHT_ARCHIVING, g4);
rm.addBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, g4);
DBFactory.getInstance().closeSession(); // simulate user clicks
// test groups
CourseGroupManager gm = PersistingCourseGroupManager.getInstance(course1);
assertTrue(gm.isIdentityInLearningGroup(id1, g1.getName()));
assertTrue(gm.isIdentityInLearningGroup(id1, g2.getName()));
assertFalse(gm.isIdentityInLearningGroup(id1, g3.getName())); // not a learning group
assertFalse(gm.isIdentityInLearningGroup(id1, g4.getName())); // not a learning group
assertTrue(gm.isIdentityInLearningGroup(id2, g1.getName()));
assertTrue(gm.isIdentityInLearningGroup(id2, g2.getName()));
assertFalse(gm.isIdentityInLearningGroup(id2, g3.getName())); // not a learning group
assertFalse(gm.isIdentityInLearningGroup(id2, g4.getName())); // not a learning group
DBFactory.getInstance().closeSession();
assertTrue(gm.isIdentityInLearningGroup(id3, g1.getName()));
assertFalse(gm.isIdentityInLearningGroup(id3, g2.getName()));
assertFalse(gm.isIdentityInLearningGroup(id3, g3.getName())); // not a learning group
assertFalse(gm.isIdentityInLearningGroup(id3, g4.getName())); // not a learning group
assertTrue(gm.isIdentityInLearningGroup(id1, g1.getName(), c1.getName()));
assertFalse(gm.isIdentityInLearningGroup(id1, g1.getName(), c2.getName()));
assertTrue(gm.isIdentityInLearningGroup(id3, g1.getName(), c1.getName()));
assertFalse(gm.isIdentityInLearningGroup(id3, g1.getName(), c2.getName()));
// test areas
DBFactory.getInstance().closeSession();
assertTrue(gm.isIdentityInLearningArea(id1, a1.getName()));
assertTrue(gm.isIdentityInLearningArea(id1, a2.getName()));
assertTrue(gm.isIdentityInLearningArea(id1, a3.getName()));
assertTrue(gm.isIdentityInLearningArea(id2, a1.getName()));
assertTrue(gm.isIdentityInLearningArea(id2, a2.getName()));
assertTrue(gm.isIdentityInLearningArea(id2, a3.getName()));
DBFactory.getInstance().closeSession();
assertTrue(gm.isIdentityInLearningArea(id3, a1.getName()));
assertTrue(gm.isIdentityInLearningArea(id3, a2.getName()));
assertFalse(gm.isIdentityInLearningArea(id3, a3.getName()));
DBFactory.getInstance().closeSession();
assertTrue(gm.getLearningAreasOfGroupFromAllContexts(g1.getName()).size() == 2);
assertTrue(gm.getLearningAreasOfGroupFromAllContexts(g2.getName()).size() == 2);