@Test void testCreateGroup() { String id = "group"; Package aPackage = mock(Package.class); when(aPackage.getId()).thenReturn(id); when(aPackage.getLabel()).thenReturn(id); GroupValue groupValue = mock(GroupValue.class); when(groupValue.getName()).thenReturn("group"); Group group = mock(Group.class); Role editorRole = mock(Role.class); Role managerRole = mock(Role.class); RoleValue editorRoleValue = RoleValue.builder().setName("group_EDITOR").setLabel(EDITOR).build(); RoleValue managerRoleValue = RoleValue.builder().setName("group_MANAGER").setLabel(MANAGER).build(); when(groupValueFactory.createGroup(id, id, GroupService.DEFAULT_ROLES, id)) .thenReturn(groupValue); when(groupFactory.create(groupValue)).thenReturn(group); when(editorRole.getName()).thenReturn("group_EDITOR"); when(editorRole.getLabel()).thenReturn(EDITOR); doReturn(editorRole).when(roleFactory).create(editorRoleValue); when(managerRole.getName()).thenReturn("group_MANAGER"); when(managerRole.getLabel()).thenReturn(MANAGER); doReturn(managerRole).when(roleFactory).create(managerRoleValue); Role defaultEditorRole = mock(Role.class); when(defaultEditorRole.getLabel()).thenReturn(EDITOR); Role defaultManagerRole = mock(Role.class); when(defaultManagerRole.getIncludes()).thenReturn(singletonList(defaultEditorRole)); when(groupValue.getRoles()).thenReturn(ImmutableList.of(editorRoleValue, managerRoleValue)); mockDefaultRoleQueries(defaultEditorRole, defaultManagerRole); groupPackageService.createGroup(aPackage); verify(dataService).add(GROUP, group); verify(dataService).add(eq(ROLE), roleCaptor.capture()); assertEquals(Set.of(managerRole, editorRole), roleCaptor.getValue().collect(toSet())); verify(managerRole).setGroup(group); verify(managerRole).setIncludes(asList(defaultManagerRole, editorRole)); verify(editorRole).setGroup(group); verify(editorRole).setIncludes(singletonList(defaultEditorRole)); }
@Override public void createGroup(Package rootPackage) { String groupName = rootPackage.getId(); String groupLabel = rootPackage.getLabel(); GroupValue groupValue = groupValueFactory.createGroup( groupName, groupLabel, GroupService.DEFAULT_ROLES, rootPackage.getId()); Map<String, Role> roles = groupValue.getRoles().stream() .map(roleFactory::create) .collect(toMap(Role::getName, identity())); roles .values() .forEach(role -> addIncludedRolesBasedOnLabels(role, roles, groupValue.getName())); Group group = groupFactory.create(groupValue); group.setRootPackage(rootPackage); group.setRoles(roles.values()); dataService.add(GROUP, group); roles.values().forEach(role -> role.setGroup(group)); dataService.add(ROLE, roles.values().stream()); groupService.grantDefaultPermissions(groupValue); roleMembershipService.addUserToRole( SecurityUtils.getCurrentUsername(), getManagerRoleName(groupValue)); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroup(Package rootPackage) { String groupName = rootPackage.getId(); String groupLabel = rootPackage.getLabel(); GroupValue groupValue = groupValueFactory.createGroup( groupName, groupLabel, GroupService.DEFAULT_ROLES, rootPackage.getId()); Map<String, Role> roles = groupValue.getRoles().stream() .map(roleFactory::create) .collect(toMap(Role::getName, identity())); roles .values() .forEach(role -> addIncludedRolesBasedOnLabels(role, roles, groupValue.getName())); Group group = groupFactory.create(groupValue); group.setRootPackage(rootPackage); group.setRoles(roles.values()); dataService.add(GROUP, group); roles.values().forEach(role -> role.setGroup(group)); dataService.add(ROLE, roles.values().stream()); groupService.grantDefaultPermissions(groupValue); roleMembershipService.addUserToRole( SecurityUtils.getCurrentUsername(), getManagerRoleName(groupValue)); } }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroup(Package rootPackage) { String groupName = rootPackage.getId(); String groupLabel = rootPackage.getLabel(); GroupValue groupValue = groupValueFactory.createGroup( groupName, groupLabel, GroupService.DEFAULT_ROLES, rootPackage.getId()); Map<String, Role> roles = groupValue.getRoles().stream() .map(roleFactory::create) .collect(toMap(Role::getName, identity())); roles .values() .forEach(role -> addIncludedRolesBasedOnLabels(role, roles, groupValue.getName())); Group group = groupFactory.create(groupValue); group.setRootPackage(rootPackage); group.setRoles(roles.values()); dataService.add(GROUP, group); roles.values().forEach(role -> role.setGroup(group)); dataService.add(ROLE, roles.values().stream()); groupService.grantDefaultPermissions(groupValue); roleMembershipService.addUserToRole( SecurityUtils.getCurrentUsername(), getManagerRoleName(groupValue)); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroup(Package rootPackage) { String groupName = rootPackage.getId(); String groupLabel = rootPackage.getLabel(); GroupValue groupValue = groupValueFactory.createGroup( groupName, groupLabel, GroupService.DEFAULT_ROLES, rootPackage.getId()); Map<String, Role> roles = groupValue.getRoles().stream() .map(roleFactory::create) .collect(toMap(Role::getName, identity())); roles .values() .forEach(role -> addIncludedRolesBasedOnLabels(role, roles, groupValue.getName())); Group group = groupFactory.create(groupValue); group.setRootPackage(rootPackage); group.setRoles(roles.values()); dataService.add(GROUP, group); roles.values().forEach(role -> role.setGroup(group)); dataService.add(ROLE, roles.values().stream()); groupService.grantDefaultPermissions(groupValue); roleMembershipService.addUserToRole( SecurityUtils.getCurrentUsername(), getManagerRoleName(groupValue)); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroup(Package rootPackage) { String groupName = rootPackage.getId(); String groupLabel = rootPackage.getLabel(); GroupValue groupValue = groupValueFactory.createGroup( groupName, groupLabel, GroupService.DEFAULT_ROLES, rootPackage.getId()); Map<String, Role> roles = groupValue.getRoles().stream() .map(roleFactory::create) .collect(toMap(Role::getName, identity())); roles .values() .forEach(role -> addIncludedRolesBasedOnLabels(role, roles, groupValue.getName())); Group group = groupFactory.create(groupValue); group.setRootPackage(rootPackage); group.setRoles(roles.values()); dataService.add(GROUP, group); roles.values().forEach(role -> role.setGroup(group)); dataService.add(ROLE, roles.values().stream()); groupService.grantDefaultPermissions(groupValue); roleMembershipService.addUserToRole( SecurityUtils.getCurrentUsername(), getManagerRoleName(groupValue)); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage);  }