Search in sources :

Example 11 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class GroupServiceBeanTest method testCollectAncestors.

@Test
public void testCollectAncestors() throws GroupException {
    // Setup
    MockRoleAssigneeServiceBean roleAssigneeSvc = new MockRoleAssigneeServiceBean();
    MockExplicitGroupService explicitGroupSvc = new MockExplicitGroupService();
    ExplicitGroupProvider prv = new ExplicitGroupProvider(null, roleAssigneeSvc);
    ExplicitGroup gA = new ExplicitGroup(prv);
    gA.setDisplayName("A");
    ExplicitGroup gAa = new ExplicitGroup(prv);
    gAa.setDisplayName("Aa");
    ExplicitGroup gAb = new ExplicitGroup(prv);
    gAb.setDisplayName("Ab");
    ExplicitGroup gAstar = new ExplicitGroup(prv);
    gAstar.setDisplayName("A*");
    Dataverse dv = MocksFactory.makeDataverse();
    Stream.of(gA, gAa, gAb, gAstar).forEach(g -> {
        g.setId(MocksFactory.nextId());
        g.setOwner(dv);
        g.setGroupAliasInOwner(g.getDisplayName());
        g.updateAlias();
        roleAssigneeSvc.add(g);
        explicitGroupSvc.registerGroup(g);
    });
    // create some containment hierarchy.
    gA.add(gAa);
    gA.add(gAb);
    gAb.add(gAstar);
    gAa.add(gAstar);
    gAa.add(AuthenticatedUsers.get());
    // Test
    GroupServiceBean sut = new GroupServiceBean();
    sut.roleAssigneeSvc = roleAssigneeSvc;
    sut.explicitGroupService = explicitGroupSvc;
    assertEquals(setOf(gA), sut.collectAncestors(setOf(gA)));
    assertEquals(setOf(gA, gAb), sut.collectAncestors(setOf(gAb)));
    assertEquals(setOf(gA, gAa, AuthenticatedUsers.get()), sut.collectAncestors(setOf(AuthenticatedUsers.get())));
    assertEquals(setOf(gA, gAb, gAa, gAstar), sut.collectAncestors(setOf(gAstar)));
}
Also used : ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) MockRoleAssigneeServiceBean(edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean) MockExplicitGroupService(edu.harvard.iq.dataverse.mocks.MockExplicitGroupService) Dataverse(edu.harvard.iq.dataverse.Dataverse) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) Test(org.junit.Test)

Aggregations

ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)11 ExplicitGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider)4 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 CreateExplicitGroupCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand)2 MockRoleAssigneeServiceBean (edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 RoleAssigneeServiceBean (edu.harvard.iq.dataverse.RoleAssigneeServiceBean)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)1 Group (edu.harvard.iq.dataverse.authorization.groups.Group)1 BuiltInGroupsProvider (edu.harvard.iq.dataverse.authorization.groups.impl.builtin.BuiltInGroupsProvider)1 ExplicitGroupServiceBean (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean)1 IpGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider)1 IpGroupsServiceBean (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean)1