Search in sources :

Example 1 with MockExplicitGroupService

use of edu.harvard.iq.dataverse.mocks.MockExplicitGroupService 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

Dataverse (edu.harvard.iq.dataverse.Dataverse)1 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)1 ExplicitGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider)1 MockExplicitGroupService (edu.harvard.iq.dataverse.mocks.MockExplicitGroupService)1 MockRoleAssigneeServiceBean (edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean)1 Test (org.junit.Test)1