/** * Backwards compatibility. * * @param jsonId JSON string value of a GroupId * @return GroupId * @throws IllegalArgumentException */ public static GroupId fromJson(String jsonId) throws IllegalArgumentException { return new GroupId(jsonId); }
/** * Backwards compatibility. * * @param jsonId JSON string value of a GroupId * @return GroupId * @throws IllegalArgumentException */ public static GroupId fromJson(String jsonId) throws IllegalArgumentException { return new GroupId(jsonId); }
@Test(expected=IllegalArgumentException.class) public void testGroupIdException() { new GroupId("195mg90a39v/937194"); } }
@Test(expected=IllegalArgumentException.class) public void testGroupIdException() { new GroupId("195mg90a39v/937194"); } }
@Test public void getJohnDoeActivityWithAppId1() throws Exception { Future<Activity> result = this.activityServiceDb.getActivity(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), null, ACTIVITY_ALL_FIELDS, "1", SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); Activity activity = result.get(); SpiTestUtil.assertActivityEquals(activity, testActivity); }
@Test public void getJohnDoeApplicationData() throws Exception { Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, null, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals("0", data.getEntry().get("john.doe").get("count")); }
@Test public void updateJohnDoeApplicationDataSettingCountTo5() throws Exception { // Do update Map<String, String> values = new MapMaker().makeMap(); values.put("count", "5"); this.appDataServiceDb.updatePersonData(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), values, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); // Verify that update succeeded Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, null, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals("5", data.getEntry().get("john.doe").get("count")); }
@Test public void getJohnDoeFriendsApplicationDataWithCountField() throws Exception { Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.friends, "@friends"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(3, data.getEntry().size()); assertEquals("7", data.getEntry().get("jane.doe").get("count")); assertEquals("2", data.getEntry().get("george.doe").get("count")); }
@Test public void deleteJohnDoeApplicationDataWithInvalidField() throws Exception { // Do delete with invalid field this.appDataServiceDb.deletePersonData(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("peabody"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); // Verify that delete did not occur Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals("0", data.getEntry().get("john.doe").get("count")); }
@Test public void deleteJohnDoeApplicationDataWithCountField() throws Exception { // Do delete this.appDataServiceDb.deletePersonData(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); // Verify that delete succeeded Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals(null, data.getEntry().get("john.doe").get("count")); }
@Test public void getJohnDoeApplicationDataWithCountField() throws Exception { Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals("0", data.getEntry().get("john.doe").get("count")); }
@Test public void getJohnDoeApplicationDataWithInvalidField() throws Exception { Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("peabody"), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); DataCollection data = results.get(); assertEquals(1, data.getEntry().size()); assertEquals(null, data.getEntry().get("john.doe").get("count")); }
@Test public void testHandleDelete() throws Exception { String path = "/activities/john.doe/@self/@app/1"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(activityService.deleteActivities(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("1")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
@Test public void testHandleDelete() throws Exception { String path = "/activitystreams/john.doe/@self/@app/myObjectId123"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(service.deleteActivityEntries(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("myObjectId123")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
@Test public void testHandleDelete() throws Exception { String path = "/activitystreams/john.doe/@self/@app/myObjectId123"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(service.deleteActivityEntries(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("myObjectId123")), eq(token))).andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void getJohnDoeFriendsActivities() throws Exception { Future<RestfulCollection<Activity>> result = this.activityServiceDb.getActivities(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.friends, "@friends"), null, ACTIVITY_ALL_FIELDS, new CollectionOptions(), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); RestfulCollection<Activity> activityCollection = result.get(); assertEquals(2, activityCollection.getTotalResults()); assertEquals(0, activityCollection.getStartIndex()); }
@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); }