/** * 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())); }
@Test public void getJohnDoeFriendsOrderedByNameWithPagination() throws Exception { // Set collection options CollectionOptions collectionOptions = new CollectionOptions(); collectionOptions.setSortBy("name"); collectionOptions.setSortOrder(SortOrder.ascending); collectionOptions.setFirst(0); collectionOptions.setMax(1); // Get first friend 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(); SpiTestUtil.assertPersonEquals(people.get(0), "george.doe", "George Doe"); // Get second friend of john.doe collectionOptions.setFirst(1); result = this.personServiceDb.getPeople( SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.friends, "@friends"), collectionOptions, Person.Field.ALL_FIELDS, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); peopleCollection = result.get(); assertEquals(3, peopleCollection.getTotalResults()); assertEquals(1, peopleCollection.getStartIndex()); people = peopleCollection.getEntry(); SpiTestUtil.assertPersonEquals(people.get(0), "jane.doe", "Jane Doe"); }
@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()); }