use of edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean in project dataverse by IQSS.
the class GroupServiceBeanTest method testFlattenGroupsCollection.
@Test
public void testFlattenGroupsCollection() throws GroupException {
// Setup
MockRoleAssigneeServiceBean roleAssigneeSvc = new MockRoleAssigneeServiceBean();
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());
roleAssigneeSvc.add(g);
g.updateAlias();
});
// 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;
Set<Group> grps = setOf(AllUsers.get(), gA);
List<Group> result = sut.flattenGroupsCollection(grps).collect(toList());
assertEquals("Groups should appear only once", result.size(), new HashSet<>(result).size());
grps.addAll(listOf(gAa, gAb, gAstar, AuthenticatedUsers.get()));
assertEquals("All groups should appear", grps, new HashSet<>(result));
}
use of edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean 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