Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=685294&r1=685293&r2=685294&view=diff ============================================================================== --- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java (original) +++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java Tue Aug 12 13:23:44 2008 @@ -34,8 +34,11 @@ import com.google.common.collect.Sets; import com.google.inject.Guice; import com.google.inject.Injector; + import junit.framework.TestCase; +import java.util.Collections; + /** * Test the JSONOpensocialService */ @@ -44,10 +47,17 @@ private JsonDbOpensocialService db; private static final UserId CANON_USER = new UserId(UserId.Type.userId, "canonical"); + + private static final UserId JOHN_DOE = new UserId(UserId.Type.userId, "john.doe"); + + private static final UserId JANE_DOE = new UserId(UserId.Type.userId, "jane.doe"); + private static final GroupId SELF_GROUP = new GroupId(GroupId.Type.self, null); + private static final String APP_ID = "1"; private static final String CANONICAL_USER_ID = "canonical"; + private SecurityToken token = new FakeGadgetToken(); @@ -76,8 +86,21 @@ public void testGetExpectedFriends() throws Exception { ResponseItem<RestfulCollection<Person>> responseItem = db.getPeople( - CANON_USER, new GroupId(GroupId.Type.friends, null), PersonService.SortOrder.topFriends, - PersonService.FilterType.all, 0, Integer.MAX_VALUE, null, token).get(); + Sets.newHashSet(CANON_USER), new GroupId(GroupId.Type.friends, null), + PersonService.SortOrder.topFriends, PersonService.FilterType.all, 0, + Integer.MAX_VALUE, Collections.<String>emptySet(), token).get(); + assertNotNull(responseItem.getResponse()); + assertEquals(responseItem.getResponse().getTotalResults(), 4); + // Test a couple of users + assertEquals(responseItem.getResponse().getEntry().get(0).getId(), "john.doe"); + assertEquals(responseItem.getResponse().getEntry().get(1).getId(), "jane.doe"); + } + + public void testGetExpectedUsersForPlural() throws Exception { + ResponseItem<RestfulCollection<Person>> responseItem = db.getPeople( + Sets.newLinkedHashSet(JOHN_DOE, JANE_DOE), new GroupId(GroupId.Type.friends, null), + PersonService.SortOrder.topFriends, PersonService.FilterType.all, 0, + Integer.MAX_VALUE, Collections.<String>emptySet(), token).get(); assertNotNull(responseItem.getResponse()); assertEquals(responseItem.getResponse().getTotalResults(), 4); // Test a couple of users @@ -87,10 +110,18 @@ public void testGetExpectedActivities() throws Exception { ResponseItem<RestfulCollection<Activity>> responseItem = db.getActivities( - CANON_USER, SELF_GROUP, APP_ID, null, new FakeGadgetToken()).get(); + Sets.newHashSet(CANON_USER), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); assertTrue(responseItem.getResponse().getTotalResults() == 2); } + public void testGetExpectedActivitiesForPlural() throws Exception { + ResponseItem<RestfulCollection<Activity>> responseItem = db.getActivities( + Sets.newHashSet(CANON_USER, JOHN_DOE), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); + assertTrue(responseItem.getResponse().getTotalResults() == 3); + } + public void testGetExpectedActivity() throws Exception { ResponseItem<Activity> responseItem = db.getActivity( CANON_USER, SELF_GROUP, APP_ID, @@ -103,7 +134,7 @@ } public void testDeleteExpectedActivity() throws Exception { - db.deleteActivity(CANON_USER, SELF_GROUP, APP_ID, APP_ID, + db.deleteActivities(CANON_USER, SELF_GROUP, APP_ID, Sets.newHashSet(APP_ID), new FakeGadgetToken()); // Try to fetch the activity @@ -115,7 +146,8 @@ public void testGetExpectedAppData() throws Exception { ResponseItem<DataCollection> responseItem = db.getPersonData( - CANON_USER, SELF_GROUP, APP_ID, null, new FakeGadgetToken()).get(); + Sets.newHashSet(CANON_USER), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); assertTrue(!responseItem.getResponse().getEntry().isEmpty()); assertTrue(!responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).isEmpty()); assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).size() == 2); @@ -123,6 +155,21 @@ assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).containsKey("size")); } + public void testGetExpectedAppDataForPlural() throws Exception { + ResponseItem<DataCollection> responseItem = db.getPersonData( + Sets.newHashSet(CANON_USER, JOHN_DOE), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); + assertTrue(!responseItem.getResponse().getEntry().isEmpty()); + assertTrue(!responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).isEmpty()); + assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).size() == 2); + assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).containsKey("count")); + assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).containsKey("size")); + assertTrue(!responseItem.getResponse().getEntry().get(JOHN_DOE.getUserId()).isEmpty()); + assertTrue(responseItem.getResponse().getEntry().get(JOHN_DOE.getUserId()).size() == 1); + assertTrue( + responseItem.getResponse().getEntry().get(JOHN_DOE.getUserId()).containsKey("count")); + } + public void testDeleteExpectedAppData() throws Exception { // Delete the data db.deletePersonData(CANON_USER, SELF_GROUP, APP_ID, @@ -130,7 +177,8 @@ //Fetch the remaining and test ResponseItem<DataCollection> responseItem = db.getPersonData( - CANON_USER, SELF_GROUP, APP_ID, null, new FakeGadgetToken()).get(); + Sets.newHashSet(CANON_USER), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); assertTrue(!responseItem.getResponse().getEntry().isEmpty()); assertTrue(!responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).isEmpty()); assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).size() == 1); @@ -145,7 +193,8 @@ //Fetch the remaining and test ResponseItem<DataCollection> responseItem = db.getPersonData( - CANON_USER, SELF_GROUP, APP_ID, null, new FakeGadgetToken()).get(); + Sets.newHashSet(CANON_USER), SELF_GROUP, APP_ID, Collections.<String>emptySet(), + new FakeGadgetToken()).get(); assertTrue(!responseItem.getResponse().getEntry().isEmpty()); assertTrue(!responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).isEmpty()); assertTrue(responseItem.getResponse().getEntry().get(CANONICAL_USER_ID).size() == 3);
