You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/05/22 18:40:11 UTC
svn commit: r659151 - in
/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social:
./ abdera/ opensocial/util/
Author: doll
Date: Thu May 22 09:40:10 2008
New Revision: 659151
URL: http://svn.apache.org/viewvc?rev=659151&view=rev
Log:
Refactored the test data setup for all of the restful large tests. This makes the tests a little cleaner although there seems to be too much logic in the mock classes now. I hope to pull that out into more reusable non-test classes later on.
Also started to test all of the person fields to up our test coverage. More field testing coming...
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java Thu May 22 09:40:10 2008
@@ -18,23 +18,16 @@
*/
package org.apache.shindig.social;
-import com.google.inject.AbstractModule;
-
import org.apache.shindig.common.BasicSecurityTokenDecoder;
import org.apache.shindig.common.SecurityToken;
import org.apache.shindig.common.SecurityTokenDecoder;
import org.apache.shindig.social.opensocial.ActivitiesService;
import org.apache.shindig.social.opensocial.DataService;
import org.apache.shindig.social.opensocial.PeopleService;
-import org.apache.shindig.social.opensocial.model.Activity;
-import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.IdSpec;
-import org.apache.shindig.social.opensocial.model.Name;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
+import org.apache.shindig.social.opensocial.model.*;
+import org.apache.shindig.social.opensocial.model.Enum;
+import com.google.inject.AbstractModule;
import org.json.JSONException;
import java.util.ArrayList;
@@ -42,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.HashMap;
import java.util.logging.Logger;
/**
@@ -49,7 +43,7 @@
*/
public class SocialApiTestsGuiceModule extends AbstractModule {
private static Logger logger =
- Logger.getLogger(SocialApiTestsGuiceModule.class.getName());
+ Logger.getLogger(SocialApiTestsGuiceModule.class.getName());
@Override
protected void configure() {
@@ -60,34 +54,74 @@
bind(SecurityTokenDecoder.class).to(BasicSecurityTokenDecoder.class);
}
- // TODO: These 3 static classes with static params are definitely not the
- // best way to do things. We need to make this integration with Jetty
- // cleaner and easier.
+ // TODO: These 3 static classes have too much logic in them. Once we clean up
+ // the interfaces for restful hopefully we will be able to delete a lot of
+ // this code.
public static class MockPeopleService implements PeopleService {
- public static Person johnDoe;
- public static Person janeDoe;
- public static Person simpleDoe;
- private static ResponseItem<ApiCollection<Person>> people;
- private static ResponseItem<Person> person;
+ public static final Person johnDoe;
+ public static final Person janeDoe;
+ public static final Person simpleDoe;
static {
// setup John Doe
johnDoe = new Person("john.doe", new Name("John Doe"));
- List<Phone> phones = new ArrayList<Phone>();
- phones.add(new Phone("+33H000000000", "home"));
- phones.add(new Phone("+33M000000000", "mobile"));
- phones.add(new Phone("+33W000000000", "work"));
- johnDoe.setPhoneNumbers(phones);
-
- List<Address> addresses = new ArrayList<Address>();
- addresses.add(new Address("My home address"));
- johnDoe.setAddresses(addresses);
-
- List<Email> emails = new ArrayList<Email>();
- emails.add(new Email("john.doe@work.bar", "work"));
- emails.add(new Email("john.doe@home.bar", "home"));
- johnDoe.setEmails(emails);
+
+ // John should have every field filled in
+ johnDoe.setAboutMe("about me");
+ johnDoe.setActivities(newList("activity"));
+ johnDoe.setAddresses(newList(new Address("My home address")));
+ johnDoe.setAge(5);
+ johnDoe.setBodyType(new BodyType()); //TODO
+ johnDoe.setBooks(newList("books"));
+ johnDoe.setCars(newList("cars"));
+ johnDoe.setChildren("children");
+ johnDoe.setCurrentLocation(new Address("my location"));
+ johnDoe.setDateOfBirth(new Date());
+ johnDoe.setDrinker(new Enum<Enum.Drinker>(Enum.Drinker.HEAVILY));
+ johnDoe.setEmails(newList(new Email("john.doe@work.bar", "work")));
+ johnDoe.setEthnicity("purple");
+ johnDoe.setFashion("so fashionable");
+ johnDoe.setFood(newList("gruel"));
+ johnDoe.setGender(new Enum<Enum.Gender>(Enum.Gender.MALE));
+ johnDoe.setHappiestWhen("puppies");
+ johnDoe.setHeroes(newList("the moon"));
+ johnDoe.setHumor("not so good");
+ johnDoe.setInterests(newList("kites"));
+ johnDoe.setJobInterests("penguins");
+ johnDoe.setJobs(newList(new Organization()));
+ johnDoe.setLanguagesSpoken(newList("alligator"));
johnDoe.setUpdated(new Date());
+ johnDoe.setLivingArrangement("hammock");
+ johnDoe.setLookingFor("jane doe");
+ johnDoe.setMovies(newList("movies"));
+ johnDoe.setMusic(newList("music"));
+ johnDoe.setNickname("johnny boy");
+ johnDoe.setPets("simple doe");
+ johnDoe.setPhoneNumbers(newList(new Phone("+33H000000000", "home")));
+ johnDoe.setPoliticalViews("none");
+ johnDoe.setProfileSong(new Url("here", "i", "am"));
+ johnDoe.setProfileUrl("http://niceness");
+ johnDoe.setProfileVideo(new Url("here", "i", "am"));
+ johnDoe.setQuotes(newList("quotes"));
+ johnDoe.setRelationshipStatus("relationships");
+ johnDoe.setReligion("religion");
+ johnDoe.setRomance("romance");
+ johnDoe.setScaredOf("scared of what");
+ johnDoe.setSchools(newList(new Organization()));
+ johnDoe.setSexualOrientation("sexy");
+ johnDoe.setSmoker(new Enum<Enum.Smoker>(Enum.Smoker.REGULARLY));
+ johnDoe.setSports(newList("ping pong"));
+ johnDoe.setStatus("away");
+ johnDoe.setTags(newList("tags"));
+ johnDoe.setThumbnailUrl("http://beauty");
+ johnDoe.setTimeZone(11L);
+ johnDoe.setTurnOffs(newList("off"));
+ johnDoe.setTurnOns(newList("on"));
+ johnDoe.setTvShows(newList("no tv"));
+ johnDoe.setUrls(newList(new Url("where", "are", "you")));
+ johnDoe.setNetworkPresence(new Enum<Enum.NetworkPresence>(
+ Enum.NetworkPresence.DND));
+
// setup Jane Doe
janeDoe = new Person("jane.doe", new Name("Jane Doe"));
@@ -98,88 +132,176 @@
simpleDoe.setUpdated(new Date());
}
- public static void setPeople(ResponseItem<ApiCollection<Person>>
- peopleVal) {
- people = peopleVal;
- }
-
- public static void setPerson(ResponseItem<Person> personVal) {
- person = personVal;
+ private static <T> List<T> newList(T item) {
+ // TODO: Get from Google Collections
+ List<T> items = new ArrayList<T>();
+ items.add(item);
+ return items;
+ }
+
+ public Map<String, Person> allPeople = new HashMap<String, Person>();
+ public Map<String, List<String>> friendIds
+ = new HashMap<String, List<String>>();
+
+ public MockPeopleService() {
+ allPeople.put(johnDoe.getId(), johnDoe);
+ allPeople.put(janeDoe.getId(), janeDoe);
+ allPeople.put(simpleDoe.getId(), simpleDoe);
+
+ // Jane and Simple are John's friends.
+ // Nobody else has friends
+ List<String> johnsFriends = new ArrayList<String>();
+ johnsFriends.add(janeDoe.getId());
+ johnsFriends.add(simpleDoe.getId());
+ friendIds.put(johnDoe.getId(), johnsFriends);
}
public List<String> getIds(IdSpec idSpec, SecurityToken token)
throws JSONException {
- // Not needed yet
- return null;
+ List<String> ids = new ArrayList<String>();
+ switch (idSpec.getType()) {
+ case VIEWER :
+ ids.add(token.getViewerId());
+ break;
+ case OWNER :
+ ids.add(token.getOwnerId());
+ break;
+ case OWNER_FRIENDS:
+ ids.addAll(friendIds.get(token.getOwnerId()));
+ break;
+ case VIEWER_FRIENDS:
+ ids.addAll(friendIds.get(token.getViewerId()));
+ break;
+ case USER_IDS:
+ ids.addAll(idSpec.fetchUserIds());
+ break;
+ }
+ return ids;
}
public ResponseItem<ApiCollection<Person>> getPeople(List<String> ids,
SortOrder sortOrder, FilterType filter, int first, int max,
Set<String> profileDetails, SecurityToken token) {
- return people;
+ List<Person> people = new ArrayList<Person>();
+ for (String id : ids) {
+ people.add(allPeople.get(id));
+ }
+ // TODO: paginaton, sorting etc
+ return new ResponseItem<ApiCollection<Person>>(
+ new ApiCollection<Person>(people));
}
public ResponseItem<Person> getPerson(String id, SecurityToken token) {
- return person;
+ Person person = allPeople.get(id);
+ return new ResponseItem<Person>(person);
}
}
public static class MockDataService implements DataService {
- private static ResponseItem<Map<String, Map<String, String>>> personData;
+ private Map<String, Map<String, String>> data
+ = new HashMap<String, Map<String, String>>();
- public static void setPersonData(ResponseItem<Map<String,
- Map<String, String>>> personDataVal) {
- personData = personDataVal;
+ public MockDataService() {
+ Map<String, String> johnData = new HashMap<String, String>();
+ johnData.put("count", "0");
+
+ Map<String, String> janeData = new HashMap<String, String>();
+ janeData.put("count", "5");
+
+ Map<String, String> simpleData = new HashMap<String, String>();
+ simpleData.put("count", "7");
+
+ data.put(MockPeopleService.johnDoe.getId(), johnData);
+ data.put(MockPeopleService.janeDoe.getId(), janeData);
+ data.put(MockPeopleService.simpleDoe.getId(), simpleData);
}
public ResponseItem<Map<String, Map<String, String>>> getPersonData(
List<String> ids, List<String> keys, SecurityToken token) {
- return personData;
+ Map<String, Map<String, String>> dataToReturn
+ = new HashMap<String, Map<String, String>>();
+ for (String id : ids) {
+ Map<String, String> allPersonData = data.get(id);
+
+ // Filter by keys
+ Map<String, String> personDataToReturn = new HashMap<String, String>();
+ if (keys != null) {
+ for (String key : keys) {
+ personDataToReturn.put(key, allPersonData.get(key));
+ }
+ } else {
+ personDataToReturn = allPersonData;
+ }
+
+ dataToReturn.put(id, personDataToReturn);
+ }
+ return new ResponseItem<Map<String, Map<String, String>>>(dataToReturn);
}
public ResponseItem updatePersonData(String id, String key, String value,
SecurityToken token) {
- // Not needed yet
- return null;
+ data.get(id).put(key, value);
+ return new ResponseItem<Object>(null);
}
}
public static class MockActivitiesService implements ActivitiesService {
- public static ResponseItem<List<Activity>> activities;
- public static ResponseItem<Activity> activity;
-
- public static Activity basicActivity;
+ public static Activity johnActivity;
+ public static Activity janeActivity;
static {
- basicActivity = new Activity("1", "john.doe");
- basicActivity.setTitle("yellow");
- basicActivity.setBody("what a color!");
- basicActivity.setUpdated(new Date());
- }
+ johnActivity = new Activity("1", MockPeopleService.johnDoe.getId());
+ johnActivity.setTitle("yellow");
+ johnActivity.setBody("what a color!");
+ johnActivity.setUpdated(new Date());
- public static void setActivity(ResponseItem<Activity> activityVal) {
- activity = activityVal;
+ janeActivity = new Activity("2", MockPeopleService.janeDoe.getId());
+ janeActivity.setTitle("green");
+ janeActivity.setBody("a better color!");
+ janeActivity.setUpdated(new Date());
}
- public static void setActivities(ResponseItem<List<Activity>>
- activitiesVal) {
- activities = activitiesVal;
+ public Map<String, List<Activity>> activities
+ = new HashMap<String, List<Activity>>();
+
+ public MockActivitiesService() {
+ List<Activity> johnsActivities = new ArrayList<Activity>();
+ johnsActivities.add(johnActivity);
+
+ List<Activity> janesActivities = new ArrayList<Activity>();
+ janesActivities.add(janeActivity);
+
+ List<Activity> simplesActivities = new ArrayList<Activity>();
+
+ activities.put(MockPeopleService.johnDoe.getId(), johnsActivities);
+ activities.put(MockPeopleService.janeDoe.getId(), janesActivities);
+ activities.put(MockPeopleService.simpleDoe.getId(), simplesActivities);
}
public ResponseItem<List<Activity>> getActivities(List<String> ids,
SecurityToken token) {
- return activities;
+ List<Activity> allActivities = new ArrayList<Activity>();
+ for (String id : ids) {
+ allActivities.addAll(activities.get(id));
+ }
+ return new ResponseItem<List<Activity>>(allActivities);
}
public ResponseItem createActivity(String personId, Activity activity,
SecurityToken token) {
- // Not needed yet
- return null;
+ activities.get(personId).add(activity);
+ return new ResponseItem<Object>(null);
}
public ResponseItem<Activity> getActivity(String id, String activityId,
SecurityToken token) {
- return activity;
+ List<Activity> allActivities = activities.get(id);
+ for (Activity activity : allActivities) {
+ if (activity.getId().equals(activityId)) {
+ return new ResponseItem<Activity>(activity);
+ }
+ }
+ return new ResponseItem<Activity>(ResponseError.BAD_REQUEST, "", null);
}
}
}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTest.java Thu May 22 09:40:10 2008
@@ -17,48 +17,17 @@
*/
package org.apache.shindig.social.abdera;
-import static org.junit.Assert.assertEquals;
-
-import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
import org.apache.shindig.social.opensocial.model.Activity;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
-
-import org.junit.After;
-import org.junit.Before;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
public class RestfulAtomActivityTest extends AbstractLargeRestfulTests {
- private Activity activity;
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- activity = SocialApiTestsGuiceModule.MockActivitiesService.basicActivity;
- List<Activity> activities = new ArrayList<Activity>();
- activities.add(activity);
-
- SocialApiTestsGuiceModule.MockActivitiesService
- .setActivities(new ResponseItem<List<Activity>>(activities));
- SocialApiTestsGuiceModule.MockActivitiesService
- .setActivity(new ResponseItem<Activity>(activity));
- }
-
- @Override
- @After
- public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockActivitiesService.setActivities(null);
- SocialApiTestsGuiceModule.MockActivitiesService.setActivity(null);
-
- super.tearDown();
- }
+ private Activity activity = SocialApiTestsGuiceModule
+ .MockActivitiesService.johnActivity;
@Test
public void testGetActivityOfUser() throws Exception {
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTest.java Thu May 22 09:40:10 2008
@@ -17,23 +17,11 @@
*/
package org.apache.shindig.social.abdera;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
public class RestfulAtomDataTest extends AbstractLargeRestfulTests {
- @Before
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @After
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
@Test
public void testGetDataAtom() throws Exception {
resp = client.get(BASEURL + "/appdata/john.doe/@all?format=atom");
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java Thu May 22 09:40:10 2008
@@ -17,51 +17,19 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
import org.apache.shindig.social.opensocial.model.Person;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.junit.After;
-import org.junit.Before;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import static org.junit.Assert.*;
-import java.util.ArrayList;
import java.util.List;
public class RestfulAtomPeopleTest extends AbstractLargeRestfulTests {
- private List<Person> people;
- private ClientResponse resp;
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
- }
-
- @After
- public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
- }
-
@Test
public void testGetPeople() throws Exception {
resp = client.get(BASEURL + "/people/john.doe/@all?format=atom");
@@ -72,10 +40,20 @@
List<Entry> entries = doc.getRoot().getEntries();
assertEquals(2, entries.size());
- assertEquals(people.get(1).getId(), getIdFromXmlContent(entries.get(0)
- .getContentElement().getValue()));
- assertEquals(people.get(0).getId(), getIdFromXmlContent(entries.get(1)
- .getContentElement().getValue()));
+ String id1 = getIdFromXmlContent(entries.get(0)
+ .getContentElement().getValue());
+ String id2 = getIdFromXmlContent(entries.get(1)
+ .getContentElement().getValue());
+
+ Person janeDoe = SocialApiTestsGuiceModule.MockPeopleService.janeDoe;
+ Person simpleDoe = SocialApiTestsGuiceModule.MockPeopleService.simpleDoe;
+ // TODO: Simplify after we have implement sorting
+ if (id1.equals(janeDoe.getId())) {
+ assertEquals(simpleDoe.getId(), id2);
+ } else {
+ assertEquals(janeDoe.getId(), id2);
+ assertEquals(simpleDoe.getId(), id1);
+ }
}
@Test
@@ -87,7 +65,8 @@
Entry entry = doc.getRoot();
prettyPrint(entry);
- Person expectedJaneDoe = people.get(0);
+ Person expectedJaneDoe = SocialApiTestsGuiceModule
+ .MockPeopleService.janeDoe;
assertEquals(expectedJaneDoe.getId(),
getIdFromXmlContent(entry.getContentElement().getValue()));
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java Thu May 22 09:40:10 2008
@@ -17,46 +17,17 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
import org.apache.shindig.social.opensocial.model.Activity;
-import org.json.JSONObject;
import org.json.JSONException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.json.JSONObject;
import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
+import org.junit.Test;
public class RestfulJsonActivityTest extends AbstractLargeRestfulTests {
- private Activity activity;
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- activity = SocialApiTestsGuiceModule.MockActivitiesService.basicActivity;
- List<Activity> activities = new ArrayList<Activity>();
- activities.add(activity);
-
- SocialApiTestsGuiceModule.MockActivitiesService.setActivities(
- new ResponseItem<List<Activity>>(activities));
- SocialApiTestsGuiceModule.MockActivitiesService.setActivity(
- new ResponseItem<Activity>(activity));
- }
-
- @After
- public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockActivitiesService.setActivities(null);
- SocialApiTestsGuiceModule.MockActivitiesService.setActivity(null);
-
- super.tearDown();
- }
-
+
/**
* Expected response for an activity in json:
* {
@@ -73,7 +44,9 @@
resp = client.get(BASEURL + "/activities/john.doe/@self/1");
checkForGoodJsonResponse(resp);
JSONObject result = getJson(resp);
- assertActivitiesEqual(activity, result);
+ assertActivitiesEqual(
+ SocialApiTestsGuiceModule.MockActivitiesService.johnActivity,
+ result);
}
/**
@@ -101,7 +74,8 @@
assertEquals(1, result.getInt("totalResults"));
assertEquals(0, result.getInt("startIndex"));
- assertActivitiesEqual(activity,
+ assertActivitiesEqual(
+ SocialApiTestsGuiceModule.MockActivitiesService.johnActivity,
result.getJSONArray("entry").getJSONObject(0));
}
@@ -132,7 +106,8 @@
assertEquals(1, result.getInt("totalResults"));
assertEquals(0, result.getInt("startIndex"));
- assertActivitiesEqual(activity,
+ assertActivitiesEqual(
+ SocialApiTestsGuiceModule.MockActivitiesService.janeActivity,
result.getJSONArray("entry").getJSONObject(0));
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java Thu May 22 09:40:10 2008
@@ -17,48 +17,10 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.ResponseItem;
-
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import java.util.HashMap;
-import java.util.Map;
-
public class RestfulJsonDataTest extends AbstractLargeRestfulTests {
- private Map<String, Map<String, String>> data;
- private Map<String, String> janeData;
- private Map<String, String> simpleData;
- private Map<String, String> johnData;
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- data = new HashMap<String, Map<String, String>>();
- janeData = new HashMap<String, String>();
- janeData.put("count", "5");
-
- simpleData = new HashMap<String, String>();
- simpleData.put("count", "7");
-
- johnData = new HashMap<String, String>();
- johnData.put("count", "0");
- }
-
- @After
- public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockDataService.setPersonData(null);
- super.tearDown();
- }
-
- private void updateAppData() {
- SocialApiTestsGuiceModule.MockDataService.setPersonData(
- new ResponseItem<Map<String, Map<String, String>>>(data));
- }
/**
* Expected response for app data in json:
@@ -74,10 +36,6 @@
*/
@Test
public void testGetFriendsAppDataJson() throws Exception {
- data.put("jane.doe", janeData);
- data.put("simple.doe", simpleData);
- updateAppData();
-
// app id is mocked out
resp = client.get(BASEURL + "/appdata/john.doe/@friends/app?fields=count");
// checkForGoodJsonResponse(resp);
@@ -98,9 +56,6 @@
// TODO: Shindig currently throws an exception when no keys are specified
// @Test
public void testGetSelfAppDataJson() throws Exception {
- data.put("john.doe", johnData);
- updateAppData();
-
// app id is mocked out
resp = client.get(BASEURL + "/appdata/john.doe/@self/app");
// checkForGoodJsonResponse(resp);
@@ -120,9 +75,6 @@
*/
@Test
public void testGetSelfAppDataJsonWithKey() throws Exception {
- data.put("john.doe", johnData);
- updateAppData();
-
// app id is mocked out
resp = client.get(BASEURL + "/appdata/john.doe/@self/app?fields=count");
// checkForGoodJsonResponse(resp);
@@ -143,9 +95,6 @@
*/
@Test
public void testGetSelfAppDataJsonWithoutKeys() throws Exception {
- data.put("john.doe", johnData);
- updateAppData();
-
// app id is mocked out
resp = client.get(BASEURL + "/appdata/john.doe/@self/app?fields=peabody");
// checkForGoodJsonResponse(resp);
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTest.java Thu May 22 09:40:10 2008
@@ -17,51 +17,21 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
+import org.apache.shindig.social.opensocial.model.*;
+import org.apache.shindig.social.opensocial.model.Enum;
import org.json.JSONArray;
import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Before;
+import org.json.JSONException;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import static org.junit.Assert.*;
-import java.util.ArrayList;
import java.util.List;
public class RestfulJsonPeopleTest extends AbstractLargeRestfulTests {
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- List<Person> people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
- }
-
- @After
- public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
-
- super.tearDown();
- }
-
/**
* Expected response for john.doe's json:
*
@@ -70,17 +40,18 @@
* 'name' : {'unstructured' : 'John Doe'},
* 'phoneNumbers' : [
* { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
* ],
* 'addresses' : [
* {'unstructuredAddress' : 'My home address'}
* ],
* 'emails' : [
* { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
* ]
+ *
+ * ... etc, etc for all fields in the person object
+ *
* }
+ * TODO: Finish up this test and make refactor so that it is easier to read
*
* @throws Exception if test encounters an error
*/
@@ -92,35 +63,124 @@
JSONObject result = getJson(resp);
Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
+ assertStringField(result, johnDoe.getAboutMe(), Person.Field.ABOUT_ME);
+ assertStringListField(result, johnDoe.getActivities(),
+ Person.Field.ACTIVITIES);
+
+ assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
+ result.getJSONArray(Person.Field.ADDRESSES.toString()).getJSONObject(0)
+ .getString(Address.Field.UNSTRUCTURED_ADDRESS.toString()));
+
+ assertEquals(johnDoe.getAge().intValue(), result.getInt(
+ Person.Field.AGE.toString()));
+ // TODO: body type
+ assertStringListField(result, johnDoe.getBooks(), Person.Field.BOOKS);
+ assertStringListField(result, johnDoe.getCars(), Person.Field.CARS);
+ assertStringField(result, johnDoe.getChildren(), Person.Field.CHILDREN);
+ // TODO: current location
+ assertStringField(result, johnDoe.getDateOfBirth().toString(),
+ Person.Field.DATE_OF_BIRTH);
+ assertEnumField(result, johnDoe.getDrinker(), Person.Field.DRINKER);
+
+ JSONArray emailArray = result.getJSONArray(Person.Field.EMAILS.toString());
+ assertEquals(1, emailArray.length());
+
+ for (int i = 0; i < johnDoe.getEmails().size(); i++) {
+ Email expectedEmail = johnDoe.getEmails().get(i);
+ JSONObject actualEmail = emailArray.getJSONObject(i);
+ assertEquals(expectedEmail.getType(),
+ actualEmail.getString(Email.Field.TYPE.toString()));
+ assertEquals(expectedEmail.getAddress(),
+ actualEmail.getString(Email.Field.ADDRESS.toString()));
+ }
+
+ assertStringField(result, johnDoe.getEthnicity(), Person.Field.ETHNICITY);
+ assertStringField(result, johnDoe.getFashion(), Person.Field.FASHION);
+ assertStringListField(result, johnDoe.getFood(), Person.Field.FOOD);
+ assertEnumField(result, johnDoe.getGender(), Person.Field.GENDER);
+ assertStringField(result, johnDoe.getHappiestWhen(),
+ Person.Field.HAPPIEST_WHEN);
+ assertStringListField(result, johnDoe.getHeroes(), Person.Field.HEROES);
+ assertStringField(result, johnDoe.getHumor(), Person.Field.HUMOR);
+ assertStringField(result, johnDoe.getId(), Person.Field.ID);
+ assertStringListField(result, johnDoe.getInterests(),
+ Person.Field.INTERESTS);
+ assertStringField(result, johnDoe.getJobInterests(),
+ Person.Field.JOB_INTERESTS);
+ // TODO: jobs
+ assertStringListField(result, johnDoe.getLanguagesSpoken(),
+ Person.Field.LANGUAGES_SPOKEN);
+ // TODO: last updated
+ assertStringField(result, johnDoe.getLivingArrangement(),
+ Person.Field.LIVING_ARRANGEMENT);
+ assertStringField(result, johnDoe.getLookingFor(),
+ Person.Field.LOOKING_FOR);
+ assertStringListField(result, johnDoe.getMovies(), Person.Field.MOVIES);
+ assertStringListField(result, johnDoe.getMusic(), Person.Field.MUSIC);
assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
+ result.getJSONObject(Person.Field.NAME.toString()).getString(
+ Name.Field.UNSTRUCTURED.toString()));
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
+ assertStringField(result, johnDoe.getNickname(), Person.Field.NICKNAME);
+ assertStringField(result, johnDoe.getPets(), Person.Field.PETS);
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
+ JSONArray phoneArray = result.getJSONArray(
+ Person.Field.PHONE_NUMBERS.toString());
+ assertEquals(1, phoneArray.length());
for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
+ assertEquals(expectedPhone.getType(), actualPhone.getString(
+ Phone.Field.TYPE.toString()));
+ assertEquals(expectedPhone.getNumber(), actualPhone.getString(
+ Phone.Field.NUMBER.toString()));
}
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
+ assertStringField(result, johnDoe.getPoliticalViews(),
+ Person.Field.POLITICAL_VIEWS);
+ // TODO: profileSong, url, video
+ assertStringListField(result, johnDoe.getQuotes(), Person.Field.QUOTES);
+ assertStringField(result, johnDoe.getRelationshipStatus(),
+ Person.Field.RELATIONSHIP_STATUS);
+ assertStringField(result, johnDoe.getReligion(), Person.Field.RELIGION);
+ assertStringField(result, johnDoe.getRomance(), Person.Field.ROMANCE);
+ assertStringField(result, johnDoe.getScaredOf(), Person.Field.SCARED_OF);
+ // TODO: Schools
+ assertStringField(result, johnDoe.getSexualOrientation(),
+ Person.Field.SEXUAL_ORIENTATION);
+ assertEnumField(result, johnDoe.getSmoker(), Person.Field.SMOKER);
+ assertStringListField(result, johnDoe.getSports(), Person.Field.SPORTS);
+ assertStringField(result, johnDoe.getStatus(), Person.Field.STATUS);
+ assertStringListField(result, johnDoe.getTags(), Person.Field.TAGS);
+ assertStringField(result, johnDoe.getThumbnailUrl(),
+ Person.Field.THUMBNAIL_URL);
+ // TODO: time zone
+ assertStringListField(result, johnDoe.getTurnOffs(),
+ Person.Field.TURN_OFFS);
+ assertStringListField(result, johnDoe.getTurnOns(), Person.Field.TURN_ONS);
+ assertStringListField(result, johnDoe.getTvShows(), Person.Field.TV_SHOWS);
+ assertEnumField(result, johnDoe.getNetworkPresence(),
+ Person.Field.NETWORKPRESENCE);
+ }
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
+ private void assertStringField(JSONObject result, String expected,
+ Person.Field field) throws JSONException {
+ assertEquals(expected, result.getString(field.toString()));
+ }
+
+ private void assertStringListField(JSONObject result, List<String> list,
+ Person.Field field) throws JSONException {
+ JSONArray actual = result.getJSONArray(field.toString());
+ assertEquals(list.get(0), actual.getString(0));
+ }
+
+ private void assertEnumField(JSONObject result, Enum expected,
+ Person.Field field) throws JSONException {
+ JSONObject actual = result.getJSONObject(field.toString());
+ assertEquals(expected.getDisplayValue(), actual.getString("displayValue"));
+ assertEquals(expected.getKey().toString(), actual.getString("key"));
}
/**
@@ -159,7 +219,7 @@
JSONObject person = people.getJSONObject(i);
String id = person.getString("id");
String name = person.getJSONObject("name").getString("unstructured");
-
+
// TODO: Clean this after we support sorting
if (id.equals("jane.doe")) {
assertEquals("Jane Doe", name);
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java?rev=659151&r1=659150&r2=659151&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java Thu May 22 09:40:10 2008
@@ -105,12 +105,19 @@
public void testPersonToXml() throws Exception {
String xml = beanXmlConverter.convertToXml(johnDoe);
// TODO: Make the person xml stop returning empty elements!
- // This test is too messy with them
+ // TODO: Flush out the test to check all the sub fields
+ Element element = XmlUtil.parse(xml);
+ Node id = element.getElementsByTagName("id").item(0);
+ assertEquals(johnDoe.getId(), id.getTextContent());
}
public void testActivityToXml() throws Exception {
String xml = beanXmlConverter.convertToXml(activity);
// TODO: Make the activity xml stop returning empty elements!
+ // TODO: Flush out the test to check all the sub fields
+ Element element = XmlUtil.parse(xml);
+ Node id = element.getElementsByTagName("id").item(0);
+ assertEquals(activity.getId(), id.getTextContent());
}
public void xxxtestMapsToXml() throws Exception {