Helper { public static Role getRole(IdentityManager identityManager, String name) throws IdentityManagementException { if (identityManager == null) { throw MESSAGES.nullArgument("IdentityManager"); } if (isNullOrEmpty(name)) { return null; } IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); List<Role> roles = queryBuilder.createIdentityQuery(Role.class) .where(queryBuilder.equal(Role.NAME, name)).getResultList(); if (roles.isEmpty()) { return null; } else if (roles.size() == 1) { return roles.get(0); } else { throw new IdentityManagementException("Error - multiple Role objects found with same name"); } }  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 role() { assertNull(Helper.getRole(identityManager, "bottle washer")); Role admin = new Role("admin"); Role manager = new Role("manager"); Role user = new Role("user"); identityManager.add(admin); identityManager.add(manager); identityManager.add(user); assertEquals("admin", admin, Helper.getRole(identityManager, "admin")); assertEquals("manager", manager, Helper.getRole(identityManager, "manager")); assertEquals("user", user, Helper.getRole(identityManager, "user")); }