@Test
public void testFindRoles() throws UnauthorizedException {

  // findRoles() should return a role per group, not the included roles for each group
  Set<JpaRole> authorities = new HashSet<JpaRole>();
  authorities.add(new JpaRole("ROLE_ASTRO_101_SPRING_2011_STUDENT", org1));
  authorities.add(new JpaRole("ROLE_ASTRO_109_SPRING_2012_STUDENT", org1));
  Set<String> members = new HashSet<String>();
  members.add("admin");
  JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", authorities, members);
  provider.addGroup(group);
  Role role = provider.findRoles("%test%", Role.Target.ALL, 0, 0).next();
  Assert.assertEquals("ROLE_GROUP_TEST", role.getName());
  authorities.clear();
  authorities.add(new JpaRole("ROLE_ASTRO_122_SPRING_2011_STUDENT", org1));
  authorities.add(new JpaRole("ROLE_ASTRO_124_SPRING_2012_STUDENT", org1));
  JpaGroup group2 = new JpaGroup("test2", org1, "Test2", "Test 2 group", authorities, members);
  provider.addGroup(group2);
  authorities = new HashSet<JpaRole>();
  authorities.add(new JpaRole("ROLE_ASTRO_134_SPRING_2011_STUDENT", org2));
  authorities.add(new JpaRole("ROLE_ASTRO_144_SPRING_2012_STUDENT", org2));
  JpaGroup group3 = new JpaGroup("test2", org2, "Test2", "Test 2 group", authorities, members);
  provider.addGroup(group3);
  Assert.assertEquals(0, IteratorUtils.toList(provider.findRoles("%PrIn%", Role.Target.ALL, 0, 0)).size());
  Assert.assertEquals(0, IteratorUtils.toList(provider.findRoles("%PrIn%", Role.Target.ALL, 0, 1)).size());
  Assert.assertEquals(2, IteratorUtils.toList(provider.findRoles("%test%", Role.Target.ALL, 0, 2)).size());
}