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