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));
}