@Override public T apply(RestfulCollection<T> c) { if (c != null && c.getTotalResults() > 0) { return c.getList().get(0); } return null; }; };
@Override public T apply(RestfulCollection<T> c) { if (c != null && c.getTotalResults() > 0) { return c.getList().get(0); } return null; }; };
RestfulCollection<?> collection = (RestfulCollection<?>) response; if (collection.getTotalResults() != collection.getList().size()) { map.put("startIndex", collection.getStartIndex()); map.put("itemsPerPage", collection.getItemsPerPage()); map.put("sorted", collection.isSorted()); map.put("list", collection.getList()); addResult(result, map); } else {
@Test public void testGetMessagesSingleId() throws Exception { RestfulCollection<Message> messages = db.getMessages( CANON_USER, "publicMessage", Collections.<String>emptySet(), Collections.<String>singletonList("1"), new CollectionOptions(), token).get(); assertEquals(1, messages.getList().size()); assertEquals("1", messages.getList().get(0).getId()); }
@Test public void testGetMessagesSingleId() throws Exception { RestfulCollection<Message> messages = db.getMessages( CANON_USER, "publicMessage", Collections.<String>emptySet(), Collections.<String>singletonList("1"), new CollectionOptions(), token).get(); assertEquals(1, messages.getList().size()); assertEquals("1", messages.getList().get(0).getId()); }
@Test public void testGetMessagesNoMessageIds() throws Exception { RestfulCollection<Message> messages = db.getMessages( CANON_USER, "publicMessage", Collections.<String>emptySet(), Collections.<String>emptyList(), new CollectionOptions(), token).get(); assertEquals(4, messages.getList().size()); }
@Test public void testGetMessagesNoMessageIds() throws Exception { RestfulCollection<Message> messages = db.getMessages( CANON_USER, "publicMessage", Collections.<String>emptySet(), Collections.<String>emptyList(), new CollectionOptions(), token).get(); assertEquals(4, messages.getList().size()); }
@Test public void testCreateMessage() throws Exception { // Create a new private message Message msg = new MessageImpl(); msg.setBody("Hello"); msg.setRecipients(Collections.singletonList(JANE_DOE.getUserId())); db.createMessage(JOHN_DOE, APP_ID, "privateMessage", msg, token).get(); // Check that the message was created RestfulCollection<Message> messages = db.getMessages( JANE_DOE, "privateMessage", Collections.<String>emptySet(), Collections.<String>singletonList(msg.getId()), new CollectionOptions(), token).get(); assertEquals(1, messages.getList().size()); } }
@Test public void testCreateMessage() throws Exception { // Create a new private message Message msg = new MessageImpl(); msg.setBody("Hello"); msg.setRecipients(Collections.singletonList(JANE_DOE.getUserId())); db.createMessage(JOHN_DOE, APP_ID, "privateMessage", msg, token).get(); // Check that the message was created RestfulCollection<Message> messages = db.getMessages( JANE_DOE, "privateMessage", Collections.<String>emptySet(), Collections.<String>singletonList(msg.getId()), new CollectionOptions(), token).get(); assertEquals(1, messages.getList().size()); } }
@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.getList().get(0).getId()); assertEquals("jane.doe", responseItem.getList().get(1).getId()); }
for (Object o : collection.getList()) { 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.getList().get(0).getId()); assertEquals("jane.doe", responseItem.getList().get(1).getId()); }
@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.getList().get(0).getId()); assertEquals("jane.doe", responseItem.getList().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.getList().get(0).getId()); assertEquals("jane.doe", responseItem.getList().get(1).getId()); }
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setList(entryList); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entryList, collection.getList()); 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> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setList(entryList); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entryList, collection.getList()); 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> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setList(entryList); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entryList, collection.getList()); 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.getList()); 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.getList()); 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.getList()); 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.getList()); 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.getList()); 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.getList()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); assertEquals(resultsPerPage, collection.getItemsPerPage()); }