@Test public void testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), 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 testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), 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 testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), eq(DEFAULT_FIELDS), eq(token))).andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandlePut() throws Exception { String jsonPerson = "{person: {aboutMe: 'A person'}}"; String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "PUT"); Person person = new PersonImpl(); expect(converter.convertToObject(eq(jsonPerson), eq(Person.class))) .andReturn(person); expect(personService.updatePerson(eq(JOHN_DOE.iterator().next()), eq(person), eq(token))).andReturn(Futures.immediateFuture(person)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonPerson), token, converter).get()); verify(); }
@Test public void testHandlePut() throws Exception { String jsonPerson = "{person: {aboutMe: 'A person'}}"; String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "PUT"); Person person = new PersonImpl(); expect(converter.convertToObject(eq(jsonPerson), eq(Person.class))) .andReturn(person); expect(personService.updatePerson(eq(JOHN_DOE.iterator().next()), eq(person), eq(token))).andReturn(Futures.immediateFuture(person)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonPerson), token, converter).get()); verify(); }
@Test public void testHandleAnonymousUser() throws Exception { String path = "/people/-1"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(ANONYMOUS), 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 testHandleAnonymousUser() throws Exception { String path = "/people/-1"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(ANONYMOUS), 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 testHandleGetFriendById() throws Exception { String path = "/people/john.doe/@friends/jane.doe"; RestHandler operation = registry.getRestHandler(path, "GET"); Person person = new PersonImpl(); List<Person> people = Lists.newArrayList(person); RestfulCollection<Person> data = new RestfulCollection<Person>(people); // TODO: We aren't passing john.doe to the service yet. expect(personService.getPeople( eq(ImmutableSet.of(new UserId(UserId.Type.userId, "jane.doe"))), eq(new GroupId(GroupId.Type.self, null)), eq(DEFAULT_OPTIONS), eq(DEFAULT_FIELDS), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleGetFriendById() throws Exception { String path = "/people/john.doe/@friends/jane.doe"; RestHandler operation = registry.getRestHandler(path, "GET"); Person person = new PersonImpl(); List<Person> people = Lists.newArrayList(person); RestfulCollection<Person> data = new RestfulCollection<Person>(people); // TODO: We aren't passing john.doe to the service yet. expect(personService.getPeople( eq(ImmutableSet.of(new UserId(UserId.Type.userId, "jane.doe"))), eq(new GroupId(GroupId.Type.self, null)), eq(DEFAULT_OPTIONS), eq(DEFAULT_FIELDS), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleGetFriendById() throws Exception { String path = "/people/john.doe/@friends/jane.doe"; RestHandler operation = registry.getRestHandler(path, "GET"); Person person = new PersonImpl(); List<Person> people = Lists.newArrayList(person); RestfulCollection<Person> data = new RestfulCollection<Person>(people); // TODO: We aren't passing john.doe to the service yet. expect(personService.getPeople( eq(ImmutableSet.of(new UserId(UserId.Type.userId, "jane.doe"))), eq(new GroupId(GroupId.Type.self, null)), eq(DEFAULT_OPTIONS), eq(DEFAULT_FIELDS), eq(token))) .andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(person, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Before public void setUp() throws Exception { Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule()); johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe")); johnDoe.setPhoneNumbers(Lists.<ListField> newArrayList(new ListFieldImpl( "home", "+33H000000000"), new ListFieldImpl("mobile", "+33M000000000"), new ListFieldImpl("work", "+33W000000000"))); johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl( "My home address"))); johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work", "john.doe@work.bar"), new ListFieldImpl("home", "john.doe@home.bar"))); activity = new ActivityImpl("activityId", johnDoe.getId()); activity.setUrl("http://foo.com/"); activity.setMediaItems(Lists.<MediaItem> newArrayList(new MediaItemImpl( "image/jpg", MediaItem.Type.IMAGE, "http://foo.bar"))); beanXmlConverter = new BeanXStreamConverter(new XStream081Configuration(injector)); }
@Before public void setUp() throws Exception { Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule()); johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe")); johnDoe.setPhoneNumbers(Lists.<ListField> newArrayList(new ListFieldImpl( "home", "+33H000000000"), new ListFieldImpl("mobile", "+33M000000000"), new ListFieldImpl("work", "+33W000000000"))); johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl( "My home address"))); johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work", "john.doe@work.bar"), new ListFieldImpl("home", "john.doe@home.bar"))); activity = new ActivityImpl("activityId", johnDoe.getId()); activity.setUrl("http://foo.com/"); activity.setMediaItems(Lists.<MediaItem> newArrayList(new MediaItemImpl( "image/jpg", MediaItem.Type.IMAGE, "http://foo.bar"))); beanXmlConverter = new BeanXStreamConverter(new XStream081Configuration(injector)); }
@Before public void setUp() throws Exception { Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule()); johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe")); johnDoe.setPhoneNumbers(Lists.<ListField> newArrayList(new ListFieldImpl( "home", "+33H000000000"), new ListFieldImpl("mobile", "+33M000000000"), new ListFieldImpl("work", "+33W000000000"))); johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl( "My home address"))); johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work", "john.doe@work.bar"), new ListFieldImpl("home", "john.doe@home.bar"))); activity = new ActivityImpl("activityId", johnDoe.getId()); activity.setUrl("http://foo.com/"); activity.setMediaItems(Lists.<MediaItem> newArrayList(new MediaItemImpl( "image/jpg", MediaItem.Type.IMAGE, "http://foo.bar"))); beanXmlConverter = new BeanXStreamConverter(new XStream081Configuration(injector)); }
@Test public void testGetProfileUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getProfileUrl()); String address = "hi"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(address, person.getUrls().get(0).getValue()); assertEquals(Person.PROFILE_URL_TYPE, person.getUrls().get(0).getType()); assertNull(person.getUrls().get(0).getLinkText()); address = "something new"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(1, person.getUrls().size()); assertEquals(address, person.getUrls().get(0).getValue()); }
@Test public void testGetProfileUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getProfileUrl()); String address = "hi"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(address, person.getUrls().get(0).getValue()); assertEquals(Person.PROFILE_URL_TYPE, person.getUrls().get(0).getType()); assertNull(person.getUrls().get(0).getLinkText()); address = "something new"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(1, person.getUrls().size()); assertEquals(address, person.getUrls().get(0).getValue()); }
@Test public void testGetThumbnailUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getThumbnailUrl()); String url = "hi"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(url, person.getPhotos().get(0).getValue()); assertEquals(Person.THUMBNAIL_PHOTO_TYPE, person.getPhotos().get(0).getType()); url = "something new"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(1, person.getPhotos().size()); assertEquals(url, person.getPhotos().get(0).getValue()); } }
@Test public void testGetThumbnailUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getThumbnailUrl()); String url = "hi"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(url, person.getPhotos().get(0).getValue()); assertEquals(Person.THUMBNAIL_PHOTO_TYPE, person.getPhotos().get(0).getType()); url = "something new"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(1, person.getPhotos().size()); assertEquals(url, person.getPhotos().get(0).getValue()); } }
@Test public void testGetProfileUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getProfileUrl()); String address = "hi"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(address, person.getUrls().get(0).getValue()); assertEquals(Person.PROFILE_URL_TYPE, person.getUrls().get(0).getType()); assertNull(person.getUrls().get(0).getLinkText()); address = "something new"; person.setProfileUrl(address); assertEquals(address, person.getProfileUrl()); assertEquals(1, person.getUrls().size()); assertEquals(address, person.getUrls().get(0).getValue()); }
@Test public void testGetThumbnailUrl() throws Exception { Person person = new PersonImpl(); assertNull(person.getThumbnailUrl()); String url = "hi"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(url, person.getPhotos().get(0).getValue()); assertEquals(Person.THUMBNAIL_PHOTO_TYPE, person.getPhotos().get(0).getType()); url = "something new"; person.setThumbnailUrl(url); assertEquals(url, person.getThumbnailUrl()); assertEquals(1, person.getPhotos().size()); assertEquals(url, person.getPhotos().get(0).getValue()); } }
@Before public void setUp() throws Exception { Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule()); johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe")); johnDoe.setPhoneNumbers(Lists.<ListField> newArrayList(new ListFieldImpl( "home", "+33H000000000"), new ListFieldImpl("mobile", "+33M000000000"), new ListFieldImpl("work", "+33W000000000"))); johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl( "My home address"))); johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work", "john.doe@work.bar"), new ListFieldImpl("home", "john.doe@home.bar"))); activity = new ActivityImpl("activityId", johnDoe.getId()); MediaItemImpl mediaItem = new MediaItemImpl(); mediaItem.setMimeType("image/jpg"); mediaItem.setType(MediaItem.Type.IMAGE); mediaItem.setUrl("http://foo.bar"); mediaItem.setLocation(new AddressImpl("Foo bar address")); mediaItem.setNumViews("10000"); activity.setMediaItems(Lists.<MediaItem> newArrayList(mediaItem)); activity.setUrl("http://foo.com"); beanXmlConverter = new BeanXStreamAtomConverter( new XStream081Configuration(injector)); }