Helper { public static Group getGroup(IdentityManager identityManager, String groupPath) throws IdentityManagementException { if (identityManager == null) { throw MESSAGES.nullArgument("IdentityManager"); } if (isNullOrEmpty(groupPath)) { return null; } if (!groupPath.startsWith("/")) { groupPath = "/" + groupPath; } String[] paths = groupPath.split("/"); if (paths.length > 0) { String name = paths[paths.length - 1]; IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); IdentityQuery<Group> query = queryBuilder.createIdentityQuery(Group.class) .where(queryBuilder.equal(Group.NAME, name)); List<Group> result = query.getResultList(); for (Group storedGroup : result) { if (storedGroup.getPath().equals(groupPath)) { return storedGroup; } } } return null; }  static Caller getCaller(IdentityManager identityManager, String loginName); static Role getRole(IdentityManager identityManager, String name); static Group getGroup(IdentityManager identityManager, String groupPath); static Group getGroup(IdentityManager identityManager, String groupName, Group parent); static boolean isMember(RelationshipManager relationshipManager, Account member, Group group); static void addToGroup(RelationshipManager relationshipManager, Account member, Group group); static void removeFromGroup(RelationshipManager relationshipManager, Account member, Group group); static boolean hasRole(RelationshipManager relationshipManager, RoleAssignable assignee, Role role); static void grantRole(RelationshipManager relationshipManager, RoleAssignable assignee, Role role); static void revokeRole(RelationshipManager relationshipManager, RoleAssignable assignee, Role role);  }
@Test public void group() { assertNull(Helper.getGroup(identityManager, "bottle washer")); Group admin = new Group("admin"); Group manager = new Group("manager"); Group user = new Group("user", manager); identityManager.add(admin); identityManager.add(manager); identityManager.add(user); assertEquals("admin", admin, Helper.getGroup(identityManager, "admin")); assertEquals("/admin", admin, Helper.getGroup(identityManager, "/admin")); assertNull("/manager/", Helper.getGroup(identityManager, "/manager/")); assertEquals("/manager", manager, Helper.getGroup(identityManager, "/manager")); assertEquals("manager", manager, Helper.getGroup(identityManager, "manager")); assertNull("user", Helper.getGroup(identityManager, "user")); assertNull("/user", Helper.getGroup(identityManager, "/user")); assertEquals("/manager/user", user, Helper.getGroup(identityManager, "/manager/user")); assertEquals("admin, null", admin, Helper.getGroup(identityManager, "admin", null)); assertNull("/admin, null", Helper.getGroup(identityManager, "/admin", null)); assertEquals("manager, null", manager, Helper.getGroup(identityManager, "manager", null)); assertEquals("user, manager", user, Helper.getGroup(identityManager, "user", manager)); assertNull("manager, user", Helper.getGroup(identityManager, "manager", user)); }