@Test
  public void getJohnDoeFriendsOrderedByName() throws Exception {
    // Set collection options
    CollectionOptions collectionOptions = new CollectionOptions();
    collectionOptions.setSortBy("name");
    collectionOptions.setSortOrder(SortOrder.ascending);
    collectionOptions.setMax(20);

    // Get all friends of john.doe
    Future<RestfulCollection<Person>> result =
        this.personServiceDb.getPeople(
            SpiTestUtil.buildUserIds("john.doe"),
            new GroupId(GroupId.Type.friends, "@friends"),
            collectionOptions,
            Person.Field.ALL_FIELDS,
            SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN);

    RestfulCollection<Person> peopleCollection = result.get();
    assertEquals(3, peopleCollection.getTotalResults());
    assertEquals(0, peopleCollection.getStartIndex());
    List<Person> people = peopleCollection.getEntry();
    // The users should be in alphabetical order
    SpiTestUtil.assertPersonEquals(people.get(0), "george.doe", "George Doe");
    SpiTestUtil.assertPersonEquals(people.get(1), "jane.doe", "Jane Doe");
  }
  /**
   * Tests getPeople with a couple of UserIds
   *
   * @throws Exception
   */
  @Test
  public void testGetExpectedPeople() throws Exception {
    CollectionOptions options = new CollectionOptions();
    options.setSortBy(PersonService.ALL_FILTER);
    options.setSortOrder(SortOrder.ascending);
    options.setFilter(null);
    options.setFilterOperation(FilterOperation.contains);
    options.setFilterValue("");
    options.setFirst(0);
    options.setMax(5);

    Set<UserId> userIds = new java.util.HashSet<UserId>();
    userIds.add(JOHN_DOE);
    userIds.add(JANE_DOE);
    userIds.add(MAIJA_M);

    RestfulCollection<Person> peopleCollection =
        personService
            .getPeople(
                userIds, null, options, Collections.<String>emptySet(), new FakeGadgetToken())
            .get();
    List<Person> personList = peopleCollection.getEntry();
    assertEquals(true, containsPerson(personList, JOHN_DOE.getUserId()));
    assertEquals(true, containsPerson(personList, MAIJA_M.getUserId()));
    assertEquals(false, containsPerson(personList, GEORGE_DOE.getUserId()));
  }
 public void testGetExpectedActivitiesForPlural() throws Exception {
   RestfulCollection<Activity> responseItem =
       db.getActivities(
               ImmutableSet.of(CANON_USER, JOHN_DOE),
               SELF_GROUP,
               APP_ID,
               Collections.<String>emptySet(),
               null,
               new FakeGadgetToken())
           .get();
   assertSame(3, responseItem.getTotalResults());
 }
  @Test
  public void testGetExpectedFriends() throws Exception {
    CollectionOptions options = new CollectionOptions();
    options.setSortBy(PersonService.TOP_FRIENDS_SORT);
    options.setSortOrder(SortOrder.ascending);
    options.setFilter(null);
    options.setFilterOperation(FilterOperation.contains);
    options.setFilterValue("");
    options.setFirst(0);
    options.setMax(20);

    RestfulCollection<Person> friendsCollection =
        personService
            .getPeople(
                Sets.newHashSet(JOHN_DOE),
                new GroupId(GroupId.Type.friends, null),
                options,
                Collections.<String>emptySet(),
                new FakeGadgetToken())
            .get();
    assertEquals(4, friendsCollection.getEntry().size());
  }
  public void testGetExpectedUsersForPlural() throws Exception {
    CollectionOptions options = new CollectionOptions();
    options.setSortBy(PersonService.TOP_FRIENDS_SORT);
    options.setSortOrder(SortOrder.ascending);
    options.setFilter(null);
    options.setFilterOperation(FilterOperation.contains);
    options.setFilterValue("");
    options.setFirst(0);
    options.setMax(20);

    RestfulCollection<Person> responseItem =
        db.getPeople(
                ImmutableSet.of(JOHN_DOE, JANE_DOE),
                new GroupId(GroupId.Type.friends, null),
                options,
                Collections.<String>emptySet(),
                token)
            .get();
    assertNotNull(responseItem);
    assertEquals(4, responseItem.getTotalResults());
    // Test a couple of users
    assertEquals("john.doe", responseItem.getEntry().get(0).getId());
    assertEquals("jane.doe", responseItem.getEntry().get(1).getId());
  }