public static Set<UserId> buildUserIds(String... userIds) { // Set user id list Set<UserId> userIdSet = Sets.newHashSet(); for (String userId: userIds) { userIdSet.add(new UserId(Type.userId, userId)); } return userIdSet; }
@Test public void getCanonicalPerson() throws Exception { Future<Person> person = this.personServiceDb.getPerson(new UserId(Type.userId, "canonical"), Person.Field.ALL_FIELDS, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); SpiTestUtil.assertPersonEquals(person.get(), canonical); }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); messageService = EasyMock.createMock(MessageService.class); messageService = EasyMock.createMock(MessageService.class); converter = EasyMock.createMock(BeanJsonConverter.class); sender = new UserId(UserId.Type.userId, "message.sender"); recipients = ImmutableList.of("second.recipient", "first.recipient"); handler = new MessageHandler(messageService); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(ImmutableSet.<Object>of(handler)); }
@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); }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); messageService = EasyMock.createMock(MessageService.class); messageService = EasyMock.createMock(MessageService.class); converter = EasyMock.createMock(BeanJsonConverter.class); sender = new UserId(UserId.Type.userId, "message.sender"); recipients = ImmutableList.of("second.recipient", "first.recipient"); handler = new MessageHandler(messageService, new CollectionOptionsFactory()); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(ImmutableSet.<Object>of(handler)); }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); messageService = EasyMock.createMock(MessageService.class); messageService = EasyMock.createMock(MessageService.class); converter = EasyMock.createMock(BeanJsonConverter.class); sender = new UserId(UserId.Type.userId, "message.sender"); recipients = ImmutableList.of("second.recipient", "first.recipient"); handler = new MessageHandler(messageService, new CollectionOptionsFactory()); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(ImmutableSet.<Object>of(handler)); }
@Test public void testGetUserId() throws Exception { UserId owner = new UserId(UserId.Type.owner, "hello"); assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner"))); UserId viewer = new UserId(UserId.Type.viewer, "hello"); assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId me = new UserId(UserId.Type.me, "hello"); assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId user = new UserId(UserId.Type.userId, "hello"); assertEquals("hello", user.getUserId(new FakeGadgetToken())); }
@Test public void testGetUserId() throws Exception { UserId owner = new UserId(UserId.Type.owner, "hello"); assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner"))); UserId viewer = new UserId(UserId.Type.viewer, "hello"); assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId me = new UserId(UserId.Type.me, "hello"); assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId user = new UserId(UserId.Type.userId, "hello"); assertEquals("hello", user.getUserId(new FakeGadgetToken())); }
@Test public void testGetUserId() throws Exception { UserId owner = new UserId(UserId.Type.owner, "hello"); assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner"))); UserId viewer = new UserId(UserId.Type.viewer, "hello"); assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId me = new UserId(UserId.Type.me, "hello"); assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer"))); UserId user = new UserId(UserId.Type.userId, "hello"); assertEquals("hello", user.getUserId(new FakeGadgetToken())); }
@Test public void testHandleGetPlural() throws Exception { String path = "/appdata/john.doe,jane.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE); userIdSet.add(new UserId(UserId.Type.userId, "jane.doe")); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(userIdSet), eq(new GroupId(GroupId.Type.self, 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(); }
@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 testHandleGetPlural() throws Exception { String path = "/appdata/john.doe,jane.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE); userIdSet.add(new UserId(UserId.Type.userId, "jane.doe")); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(userIdSet), eq(new GroupId(GroupId.Type.self, 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(); }
@Test public void testHandleGetPlural() throws Exception { String path = "/people/john.doe,jane.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); List<Person> people = ImmutableList.of(); RestfulCollection<Person> data = new RestfulCollection<Person>(people); Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE); userIdSet.add(new UserId(UserId.Type.userId, "jane.doe")); expect(personService.getPeople(eq(userIdSet), eq(new GroupId(GroupId.Type.self, null)), eq(DEFAULT_OPTIONS), eq(DEFAULT_FIELDS), eq(token))).andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@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 testHandleGetPlural() throws Exception { String path = "/appdata/john.doe,jane.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE); userIdSet.add(new UserId(UserId.Type.userId, "jane.doe")); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(userIdSet), eq(new GroupId(GroupId.Type.self, 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 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); }