private T getFirstFromCollection(RestfulCollection<T> collection) { if (collection.getTotalResults() > 0) { return collection.getEntry().get(0); } return null; } };
private T getFirstFromCollection(RestfulCollection<T> collection) { if (collection.getTotalResults() > 0) { return collection.getEntry().get(0); } return null; } };
RestfulCollection<?> r = (RestfulCollection<?>) obj; entry = Lists.newArrayList(); List<?> entryList = r.getEntry(); for (Object o : entryList) { entry.add(new AtomEntry(o));
RestfulCollection<?> collection = (RestfulCollection<?>) response; if (collection.getTotalResults() != collection.getEntry().size()) { map.put("startIndex", collection.getStartIndex()); map.put("itemsPerPage", collection.getItemsPerPage()); map.put("sorted", collection.isUpdatedSince()); map.put("list", collection.getEntry()); addResult(result, map); } else {
RestfulCollection<?> collection = (RestfulCollection<?>) response; if (collection.getTotalResults() != collection.getEntry().size()) { map.put("startIndex", collection.getStartIndex()); map.put("itemsPerPage", collection.getItemsPerPage()); map.put("sorted", collection.isUpdatedSince()); map.put("list", collection.getEntry()); addResult(result, map); } else {
for (Object o : collection.getEntry()) { writer.startNode("entry"); writeItem(o, context, writer);
@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> responseItem = db.getPeople( ImmutableSet.of(CANON_USER), 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()); }
@Test 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()); }
@Test public void getJohnDoeActivities() throws Exception { Future<RestfulCollection<Activity>> result = this.activityServiceDb.getActivities(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), null, ACTIVITY_ALL_FIELDS, new CollectionOptions(), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); RestfulCollection<Activity> activityCollection = result.get(); assertEquals(1, activityCollection.getTotalResults()); assertEquals(0, activityCollection.getStartIndex()); SpiTestUtil.assertActivityEquals(activityCollection.getEntry().get(0), testActivity); }
for (Object o : collection.getEntry()) { writer.startNode("entry"); writeItem(o, context, writer);
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entry = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setEntry(entry); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entry = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setEntry(entry); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
@Test public void testConstructors() throws Exception { List<String> entry = Lists.newArrayList("banana", "who"); RestfulCollection<String> collection = new RestfulCollection<String>(entry); assertEquals(entry, collection.getEntry()); assertEquals(0, collection.getStartIndex()); assertEquals(entry.size(), collection.getTotalResults()); assertEquals(entry.size(), collection.getItemsPerPage()); int startIndex = 9; int totalResults = 10; int resultsPerPage = 1; collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); assertEquals(resultsPerPage, collection.getItemsPerPage()); } }
@Test public void testConstructors() throws Exception { List<String> entry = Lists.newArrayList("banana", "who"); RestfulCollection<String> collection = new RestfulCollection<String>(entry); assertEquals(entry, collection.getEntry()); assertEquals(0, collection.getStartIndex()); assertEquals(entry.size(), collection.getTotalResults()); assertEquals(entry.size(), collection.getItemsPerPage()); int startIndex = 9; int totalResults = 10; int resultsPerPage = 1; collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); assertEquals(resultsPerPage, collection.getItemsPerPage()); } }
@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"); }
@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 createNewActivityForJohnDoe() throws Exception { // Create new activity final String title = "hi mom!"; final String body = "and dad."; Activity activity = SpiTestUtil.buildTestActivity("2", "john.doe", title, body); this.activityServiceDb.createActivity(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), "2", ACTIVITY_ALL_FIELDS, activity, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); // Check activity was created as expected Future<RestfulCollection<Activity>> result = this.activityServiceDb.getActivities(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), null, ACTIVITY_ALL_FIELDS, new CollectionOptions(), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); RestfulCollection<Activity> activityCollection = result.get(); assertEquals(2, activityCollection.getTotalResults()); assertEquals(0, activityCollection.getStartIndex()); activity = activityCollection.getEntry().get(1); assertEquals(activity.getTitle(), title); assertEquals(activity.getBody(), body); }