Group extends DSpaceObject implements DSpaceObjectLegacySupport { void addMember(EPerson e) { getMembers().add(e); } protected  Group(); List<EPerson> getMembers(); List<Group> getMemberGroups(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int getType(); @Override String getName(); boolean isGroupsChanged(); void clearGroupsChanged(); @Override Integer getLegacyId(); List<WorkspaceItem> getSupervisedItems(); Boolean isPermanent(); @Transient
    static final String ANONYMOUS; @Transient
    static final String ADMIN; }
@Test public void addMemberGroup() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { context.turnOffAuthorisationSystem(); Group parentGroup = createGroup("parentGroup"); Group childGroup = createGroup("childGroup"); groupService.addMember(context, parentGroup, childGroup); groupService.update(context, parentGroup); groupService.update(context, childGroup); groupService.delete(context, parentGroup); groupService.delete(context, childGroup); context.restoreAuthSystemState(); }
@Test public void deleteGroupEPersonMembers() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson = null; context.turnOffAuthorisationSystem(); try { Group toDeleteGroup = createGroup("toDelete"); ePerson = createEPerson("deleteGroupEPersonMembers@dspace.org"); groupService.addMember(context, toDeleteGroup, ePerson); groupService.update(context, toDeleteGroup); groupService.delete(context, toDeleteGroup); assertThat("deleteGroupEPersonMembers", ePerson.getGroups().size(), equalTo(0)); } finally { if (ePerson != null) { ePersonService.delete(context, ePerson); } context.restoreAuthSystemState(); } }
@Test public void deleteGroupGroupMembers() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { Group parentGroup = createGroup("toDeleteParent"); Group childGroup = createGroup("toDeleteChild"); groupService.addMember(context, parentGroup, childGroup); groupService.update(context, parentGroup); groupService.update(context, childGroup); groupService.delete(context, parentGroup); groupService.delete(context, childGroup); parentGroup = createGroup("toDeleteParent"); childGroup = createGroup("toDeleteChild"); groupService.addMember(context, parentGroup, childGroup); groupService.update(context, parentGroup); groupService.update(context, childGroup); groupService.delete(context, childGroup); groupService.delete(context, parentGroup); }
@Test public void isMemberContextSpecialGroup() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson = null; Group specialGroup = null; try { specialGroup = createGroup("specialGroup"); groupService.addMember(context, level1Group, specialGroup); groupService.update(context, level1Group); ePerson = createEPerson("isMemberContextGroupSpecial@dspace.org"); context.setCurrentUser(ePerson); context.setSpecialGroup(specialGroup.getID()); assertTrue(groupService.isMember(context, topGroup)); assertTrue(groupService.isMember(context, level1Group)); assertFalse(groupService.isMember(context, level2Group)); assertTrue(groupService.isMember(context, specialGroup)); } finally { if (ePerson != null) { context.turnOffAuthorisationSystem(); ePersonService.delete(context, ePerson); } if (specialGroup != null) { context.turnOffAuthorisationSystem(); groupService.delete(context, specialGroup); } } }
@Test public void isMemberContextSpecialGroupOtherUser() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson1 = null; EPerson ePerson2 = null; Group specialGroup = null; try { specialGroup = createGroup("specialGroup"); groupService.addMember(context, level2Group, specialGroup); groupService.update(context, level2Group); ePerson1 = createEPerson("isMemberContextGroupSpecial@dspace.org"); context.setCurrentUser(ePerson1); context.setSpecialGroup(specialGroup.getID()); ePerson2 = createEPersonAndAddToGroup("isMemberContextSpecialGroupOtherUser@dspace.org", level1Group); assertTrue(groupService.isMember(context, ePerson2, topGroup)); assertTrue(groupService.isMember(context, ePerson2, level1Group)); assertFalse(groupService.isMember(context, ePerson2, level2Group)); assertFalse(groupService.isMember(context, ePerson2, specialGroup)); assertTrue(groupService.isMember(context, ePerson1, level2Group)); assertTrue(groupService.isMember(context, ePerson1, specialGroup)); } finally { if (ePerson1 != null) { context.turnOffAuthorisationSystem(); ePersonService.delete(context, ePerson1); } if (ePerson2 != null) { context.turnOffAuthorisationSystem(); ePersonService.delete(context, ePerson2); } if (specialGroup != null) { context.turnOffAuthorisationSystem(); groupService.delete(context, specialGroup); } } }
@Test public void isMemberContextSpecialGroupDbMembership() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson = null; Group specialGroup = null; try { specialGroup = createGroup("specialGroup"); groupService.addMember(context, level1Group, specialGroup); groupService.update(context, level1Group); ePerson = createEPersonAndAddToGroup("isMemberContextGroupSpecialDbMembership@dspace.org", level2Group); context.setCurrentUser(ePerson); context.setSpecialGroup(specialGroup.getID()); assertTrue(groupService.isMember(context, topGroup)); assertTrue(groupService.isMember(context, level1Group)); assertTrue(groupService.isMember(context, level2Group)); assertTrue(groupService.isMember(context, specialGroup)); } finally { if (ePerson != null) { context.turnOffAuthorisationSystem(); ePersonService.delete(context, ePerson); } if (specialGroup != null) { context.turnOffAuthorisationSystem(); groupService.delete(context, specialGroup); } } }
@Test public void removeMemberEPerson() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson = null; try { ePerson = createEPersonAndAddToGroup("removeMemberEPerson@dspace.org", level2Group); context.setCurrentUser(ePerson); assertTrue(groupService.isMember(context, topGroup)); assertTrue(groupService.isMember(context, level1Group)); assertTrue(groupService.isMember(context, level2Group)); groupService.removeMember(context, level2Group, ePerson); assertFalse(groupService.isMember(context, topGroup)); assertFalse(groupService.isMember(context, level1Group)); assertFalse(groupService.isMember(context, level2Group)); groupService.addMember(context, level2Group, ePerson); assertTrue(groupService.isMember(context, topGroup)); assertTrue(groupService.isMember(context, level1Group)); assertTrue(groupService.isMember(context, level2Group)); groupService.removeMember(context, topGroup, ePerson); assertTrue(groupService.isMember(context, topGroup)); assertTrue(groupService.isMember(context, level1Group)); assertTrue(groupService.isMember(context, level2Group)); } finally { if (ePerson != null) { context.turnOffAuthorisationSystem(); ePersonService.delete(context, ePerson); } } }