assertEquals(actual.getAboutMe(), expected.getAboutMe()); assertEquals(actual.getActivities(), expected.getActivities()); assertCollectionSizeEquals(actual.getAddresses(), expected.getAddresses()); for (int i = 0; i < actual.getAddresses().size(); i++) { assertAddressEquals(actual.getAddresses().get(i), expected.getAddresses().get(i)); assertEquals(actual.getAge(), expected.getAge()); assertBodyTypeEquals(actual.getBodyType(), expected.getBodyType()); assertEquals(actual.getBooks(), expected.getBooks()); assertEquals(actual.getCars(), expected.getCars()); assertEquals(actual.getChildren(), expected.getChildren()); assertAddressEquals(actual.getCurrentLocation(), expected.getCurrentLocation()); assertEquals(actual.getDisplayName(), expected.getDisplayName()); assertEquals(actual.getBirthday(), expected.getBirthday()); assertCollectionSizeEquals(actual.getEmails(), expected.getEmails()); for (int i = 0; i < actual.getEmails().size(); i++) { assertListFieldEquals(actual.getEmails().get(i), expected.getEmails().get(i)); assertEquals(actual.getEthnicity(), expected.getEthnicity()); assertEquals(actual.getFashion(), expected.getFashion()); assertEquals(actual.getFood(), expected.getFood()); assertEquals(actual.getGender(), expected.getGender()); assertEquals(actual.getHappiestWhen(), expected.getHappiestWhen()); assertEquals(actual.getHasApp(), expected.getHasApp()); assertEquals(actual.getHeroes(), expected.getHeroes()); assertEquals(actual.getHumor(), expected.getHumor()); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getInterests(), expected.getInterests()); assertEquals(actual.getJobInterests(), expected.getJobInterests());
/** {@inheritDoc} */ public Future<Person> getPerson(UserId id, Set<String> fields, SecurityToken token) throws ProtocolException { if (id != null && AnonymousSecurityToken.ANONYMOUS_ID.equals(id.getUserId())) { Person anonymous = new PersonImpl(); anonymous.setId(AnonymousSecurityToken.ANONYMOUS_ID); anonymous.setName(new NameImpl(ANONYMOUS_NAME)); anonymous.setNickname(ANONYMOUS_NAME); return Futures.immediateFuture(anonymous); } try { JSONArray people = db.getJSONArray(PEOPLE_TABLE); for (int i = 0; i < people.length(); i++) { JSONObject person = people.getJSONObject(i); if (id != null && person.get(Person.Field.ID.toString()).equals(id.getUserId(token))) { Person personObj = filterFields(person, fields, Person.class); Map<String, Object> appData = getPersonAppData(person.getString(Person.Field.ID .toString()), fields); personObj.setAppData(appData); return Futures.immediateFuture(personObj); } } throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "Person '" + id.getUserId(token) + "' not found"); } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } }
person.setAboutMe("About Me " + i); String personId = getPersonId(i, key); person.setId(personId); person.setActivities(getList("Activities")); int age = random.nextInt(105); Calendar c = new GregorianCalendar(); a.add(getNewPersonAddress(i)); a.add(getNewPersonAddress(i + 2)); person.setAddresses(a); person.setAge(random.nextInt(105)); person.setBodyType(getNewBodyType(i)); person.setBooks(getList("Books")); person.setCars(getList("Cars")); person.setChildren("Yes"); person.setCurrentLocation(getNewAddress(i + 5)); person.setBirthday(c.getTime()); person.setDrinker(new EnumImpl<Drinker>(Drinker.OCCASIONALLY)); List<ListField> emails = Lists.newArrayList(); emails.add(getNewEmail(i)); emails.add(getNewEmail(i + 1)); person.setEmails(emails); person.setEthnicity("ethinicity"); person.setFashion("fashion"); person.setFood(getList("Food")); person.setGender(Gender.female); person.setHappiestWhen("sailing"); person.setHeroes(getList("Heroes"));
@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 testGetPersonDefaultFields() throws Exception { Person person = db .getPerson(CANON_USER, Person.Field.DEFAULT_FIELDS, token).get(); assertNotNull("Canonical user not found", person); assertNotNull("Canonical user has no id", person.getId()); assertNotNull("Canonical user has no name", person.getName()); assertNotNull("Canonical user has no thumbnail", person.getThumbnailUrl()); }
@Test public void testGetPersonAllAppData() throws Exception { Person person = db .getPerson(CANON_USER, ImmutableSet.of("id", "appData"), token).get(); assertNotNull("Canonical user not found", person); assertEquals("Canonical user has wrong id", "canonical", person.getId()); assertEquals("Canonical user has wrong app data", ImmutableMap.of("count", "2", "size", "100"), person.getAppData()); }
@Test public void testGetAnonymousUser() throws Exception { Person person = db.getPerson(ANONYMOUS, Person.Field.DEFAULT_FIELDS, token).get(); assertEquals("-1", person.getId()); assertEquals("Anonymous", person.getName().getFormatted()); assertEquals("Anonymous", person.getNickname()); }
@Test public void testPersonToXml() throws Exception { String xml = beanXmlConverter.convertToString(johnDoe); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals("urn:guid:" + johnDoe.getId(), id.getTextContent()); }
/** * @param o */ public AtomEntry(Object o) { if (o instanceof Person) { Person person = (Person) o; content = new AtomContent(person); id = "urn:guid:" + person.getId(); updated = person.getUpdated(); } else if (o instanceof Activity) { Activity activity = (Activity) o; content = new AtomContent(activity); title = activity.getTitle(); summary = activity.getBody(); link = new AtomLink("self", activity.getUrl()); icon = activity.getStreamFaviconUrl(); source = new AtomSource(activity); generator = new AtomGenerator(activity); author = new AtomAuthor(activity); updated = activity.getUpdated(); } else if ( o instanceof Entry ) { Entry<?, ?> e = (Entry<?, ?>) o; id = (String) e.getKey(); content = new AtomContent(e.getValue()); } else { content = o; } }
canonical.setAboutMe("I have an example of every piece of data"); canonical.setActivities(Lists.newArrayList("Coding Shindig")); address.setType("home"); address.setFormatted("PoBox 3565, 1 OpenStandards Way, Apache, CA"); canonical.setAddresses(Lists.newArrayList(address)); canonical.setAge(33); BodyTypeImpl bodyType = new BodyTypeImpl(); bodyType.setBuild("svelte"); bodyType.setHeight(1.84F); bodyType.setWeight(74F); canonical.setBodyType(bodyType); canonical.setBooks(Lists.newArrayList("The Cathedral & the Bazaar", "Catch 22")); canonical.setCars(Lists.newArrayList("beetle", "prius")); canonical.setChildren("3"); AddressImpl location = new AddressImpl(); location.setLatitude(48.858193F); location.setLongitude(2.29419F); canonical.setCurrentLocation(location); canonical.setBirthday(new Date()); canonical.setDrinker(new EnumImpl<Drinker>(Drinker.SOCIALLY)); ListField email = new ListFieldImpl("work", "dev@shindig.apache.org"); canonical.setEmails(Lists.newArrayList(email)); canonical.setEthnicity("developer");
@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 testGetPersonDefaultFields() throws Exception { Person person = db .getPerson(CANON_USER, Person.Field.DEFAULT_FIELDS, token).get(); assertNotNull("Canonical user not found", person); assertNotNull("Canonical user has no id", person.getId()); assertNotNull("Canonical user has no name", person.getName()); assertNotNull("Canonical user has no thumbnail", person.getThumbnailUrl()); }
@Test public void testGetPersonMultipleAppDataFields() throws Exception { Person person = db .getPerson(CANON_USER, ImmutableSet.of("id", "appData.size", "appData.count", "appData.bogus"), token).get(); assertNotNull("Canonical user not found", person); assertEquals("Canonical user has wrong id", "canonical", person.getId()); assertEquals("Canonical user has wrong app data", ImmutableMap.of("count", "2", "size", "100"), person.getAppData()); }
@Test public void testGetAnonymousUser() throws Exception { Person person = db.getPerson(ANONYMOUS, Person.Field.DEFAULT_FIELDS, token).get(); assertEquals("-1", person.getId()); assertEquals("Anonymous", person.getName().getFormatted()); assertEquals("Anonymous", person.getNickname()); }
@Test public void testPersonToXml() throws Exception { String xml = beanXmlConverter.convertToString(johnDoe); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals("urn:guid:" + johnDoe.getId(), id.getTextContent()); }
Person person = (Person) o; content = new AtomContent(person); id = "urn:guid:" + person.getId(); updated = person.getUpdated(); } else if (o instanceof Activity) { Activity activity = (Activity) o;
canonical.setAboutMe("I have an example of every piece of data"); canonical.setActivities(Lists.newArrayList("Coding Shindig")); address.setType("home"); address.setFormatted("PoBox 3565, 1 OpenStandards Way, Apache, CA"); canonical.setAddresses(Lists.newArrayList(address)); canonical.setAge(33); BodyTypeImpl bodyType = new BodyTypeImpl(); bodyType.setBuild("svelte"); bodyType.setHeight(1.84F); bodyType.setWeight(74F); canonical.setBodyType(bodyType); canonical.setBooks(Lists.newArrayList("The Cathedral & the Bazaar", "Catch 22")); canonical.setCars(Lists.newArrayList("beetle", "prius")); canonical.setChildren("3"); AddressImpl location = new AddressImpl(); location.setLatitude(48.858193F); location.setLongitude(2.29419F); canonical.setCurrentLocation(location); canonical.setBirthday(new Date()); canonical.setDrinker(new EnumImpl<Drinker>(Drinker.SOCIALLY)); ListField email = new ListFieldImpl("work", "dev@shindig.apache.org"); canonical.setEmails(Lists.newArrayList(email)); canonical.setEthnicity("developer");