@Test
  public void testGeUserGroupHeadersWithDifferentCaseFilter()
      throws ServletException, IOException, DatastoreException, NotFoundException {
    String prefix = "gRoUp";
    int limit = Integer.MAX_VALUE;
    int offset = 0;

    UserGroupHeaderResponsePage response =
        userProfileService.getUserGroupHeadersByPrefix(prefix, offset, limit, null, null);
    assertNotNull(response);
    List<UserGroupHeader> children = response.getChildren();
    assertNotNull(children);

    assertEquals("Incorrect number of results", 10, children.size());

    Set<String> names = new HashSet<String>();
    for (UserGroupHeader ugh : children) {
      names.add(ugh.getDisplayName());
    }
    // check: should find all 10 UserGroups and no UserProfiles
    for (int i = 0; i < 10; i++) {
      assertTrue("Expected 'Group " + i + "', but was not found.", names.contains("Group " + i));
      assertFalse("Did not expect 'User " + i + "', but was found.", names.contains("User " + i));
    }
  }
  @Test
  public void testGetUserGroupHeadersNoFilter()
      throws ServletException, IOException, DatastoreException, NotFoundException {
    String prefix = "";
    int limit = 15;
    int offset = 0;

    UserGroupHeaderResponsePage response =
        userProfileService.getUserGroupHeadersByPrefix(prefix, offset, limit, null, null);
    assertNotNull(response);
    List<UserGroupHeader> children = response.getChildren();
    assertNotNull(children);

    assertEquals("Incorrect number of results", children.size(), limit);

    Set<String> names = new HashSet<String>();
    for (UserGroupHeader ugh : children) {
      names.add(ugh.getDisplayName());
    }
    // spot check: should find first 15 alphabetical names
    assertTrue("Expected 'Group 5', but was not found.", names.contains("Group 5"));
    assertFalse("Did not expect 'User 5', but was found.", names.contains("User 5"));
  }
  @Test
  public void testGeUserGroupHeadersWithFilterSameName()
      throws ServletException, IOException, DatastoreException, NotFoundException {
    String prefix = "user 0";
    int limit = Integer.MAX_VALUE;
    int offset = 0;

    UserGroupHeaderResponsePage response =
        userProfileService.getUserGroupHeadersByPrefix(prefix, offset, limit, null, null);
    assertNotNull(response);
    List<UserGroupHeader> children = response.getChildren();
    assertNotNull(children);

    assertEquals("Expected different number of results", 2, children.size());

    Set<String> ids = new HashSet<String>();
    for (UserGroupHeader ugh : children) {
      assertEquals("Invalid header returned", "User 0", ugh.getDisplayName());
      ids.add(ugh.getOwnerId());
    }
    assertTrue("Expected principal was not returned", ids.contains("p0"));
    assertTrue("Expected principal was not returned", ids.contains("p0_duplicate"));
  }