Author: doll
Date: Fri Jul 18 11:33:58 2008
New Revision: 677994

URL: http://svn.apache.org/viewvc?rev=677994&view=rev
Log:
Switched the restful tests from using the MockXmlFileFetcher to using the new 
json db code. 

This is the first step in removing the XmlFileFetcher code completely. 


Modified:
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/JsonDbOpensocialService.java
    
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/canonical/JsonDbOpensocialServiceTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulBatchTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
    incubator/shindig/trunk/javascript/sampledata/canonicaldb.json

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/JsonDbOpensocialService.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/JsonDbOpensocialService.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/JsonDbOpensocialService.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/JsonDbOpensocialService.java
 Fri Jul 18 11:33:58 2008
@@ -32,13 +32,13 @@
 import org.apache.shindig.social.dataservice.UserId;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.util.BeanConverter;
 import org.apache.shindig.social.opensocial.util.BeanJsonConverter;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.inject.Inject;
+import com.google.inject.Singleton;
 import com.google.inject.name.Named;
 import org.apache.commons.io.IOUtils;
 import org.json.JSONArray;
@@ -49,13 +49,24 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.concurrent.Future;
 
 /**
  * Implementation of supported services backed by a JSON DB
  */
[EMAIL PROTECTED]
 public class JsonDbOpensocialService implements ActivityService, 
PersonService, AppDataService {
 
+  private static final Comparator<Person> NAME_COMPARATOR = new 
Comparator<Person>() {
+    public int compare(Person person, Person person1) {
+      String name = person.getName().getUnstructured();
+      String name1 = person1.getName().getUnstructured();
+      return name.compareTo(name1);
+    }
+  };
+
   /**
    * The DB
    */
@@ -98,7 +109,6 @@
       GroupId groupId, String appId, Set<String> fields, SecurityToken token) {
     List<Activity> result = Lists.newArrayList();
     try {
-      // TODO Is it really valid to read activities across multiple users in 
one rpc?
       Set<String> idSet = getIdSet(userId, groupId, token);
       for (String id : idSet) {
         if (db.getJSONObject(ACTIVITIES_TABLE).has(id)) {
@@ -107,6 +117,8 @@
             JSONObject activity = activities.getJSONObject(i);
             if (appId != null && 
activity.get(Activity.Field.APP_ID.toString()).equals(appId)) {
               result.add(convertToActivity(activity, fields));
+            } else if (appId == null) {
+              result.add(convertToActivity(activity, fields));
             }
           }
         }
@@ -134,7 +146,8 @@
           }
         }
       }
-      return ImmediateFuture.newInstance(null);
+      return ImmediateFuture.newInstance(new 
ResponseItem<Activity>(ResponseError.BAD_REQUEST,
+          "Activity not found", null));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Activity>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
@@ -163,7 +176,7 @@
         }
       }
       // What is the appropriate response here??
-      return ImmediateFuture.newInstance(new ResponseItem<Object>(null));
+      return ImmediateFuture.newInstance(new ResponseItem<Object>(""));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Object>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
@@ -184,8 +197,7 @@
         db.getJSONObject(ACTIVITIES_TABLE).put(userId.getUserId(token), 
jsonArray);
       }
       jsonArray.put(jsonObject);
-      // TODO ??
-      return null;
+      return ImmediateFuture.newInstance(new ResponseItem<Object>(""));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Object>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
@@ -209,15 +221,31 @@
         // Add group support later
         result.add(convertToPerson(person, fields));
       }
-      return ImmediateFuture.newInstance(new 
ResponseItem<RestfulCollection<Person>>(
-          new RestfulCollection<Person>(result)));
+
+      // We can pretend that by default the people are in top friends order
+      if (sortOrder.equals(PersonService.SortOrder.name)) {
+        Collections.sort(result, NAME_COMPARATOR);
+      }
+
+      // TODO: The samplecontainer doesn't really have the concept of HAS_APP 
so
+      // we can't support any filters yet. We should fix this.
+
+      int totalSize = result.size();
+      int last = first + max;
+      result = result.subList(first, Math.min(last, totalSize));
+
+      RestfulCollection<Person> collection = new 
RestfulCollection<Person>(result,
+          first, totalSize);
+
+      return ImmediateFuture.newInstance(new 
ResponseItem<RestfulCollection<Person>>(collection));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new 
ResponseItem<RestfulCollection<Person>>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
     }
   }
 
-  public Future<ResponseItem<Person>> getPerson(UserId id, Set<String> fields, 
SecurityToken token) {
+  public Future<ResponseItem<Person>> getPerson(UserId id, Set<String> fields,
+      SecurityToken token) {
     try {
       JSONArray people = db.getJSONArray(PEOPLE_TABLE);
 
@@ -229,16 +257,16 @@
               convertToPerson(person, fields)));
         }
       }
-      // TODO What does this mean?
-      return null;
+      return ImmediateFuture.newInstance(new 
ResponseItem<Person>(ResponseError.BAD_REQUEST,
+          "Person not found", null));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Person>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
     }
   }
 
-  public Future<ResponseItem<DataCollection>> getPersonData(UserId userId, 
GroupId groupId, String appId,
-      Set<String> fields, SecurityToken token) {
+  public Future<ResponseItem<DataCollection>> getPersonData(UserId userId, 
GroupId groupId,
+      String appId, Set<String> fields, SecurityToken token) {
     // TODO. Does fields==null imply all?
     try {
       Map<String, Map<String, String>> idToData = Maps.newHashMap();
@@ -248,7 +276,7 @@
         if (!db.getJSONObject(DATA_TABLE).has(id)) {
           personData = new JSONObject();
         } else {
-          if (fields != null) {
+          if (fields != null && !fields.isEmpty()) {
             personData = new JSONObject(
                 db.getJSONObject(DATA_TABLE).getJSONObject(id),
                 fields.toArray(new String[fields.size()]));
@@ -257,6 +285,7 @@
           }
         }
 
+        // TODO: We can use the converter here to do this for us
         Iterator keys = personData.keys();
         Map<String, String> data = Maps.newHashMap();
         while (keys.hasNext()) {
@@ -290,8 +319,7 @@
         }
       }
       db.getJSONObject(DATA_TABLE).put(user, newPersonData);
-      // TODO what is the appropriate return value
-      return null;
+      return ImmediateFuture.newInstance(new ResponseItem<Object>(""));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Object>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));
@@ -300,7 +328,9 @@
 
   public Future<ResponseItem<Object>> updatePersonData(UserId userId, GroupId 
groupId, String appId,
       Set<String> fields, Map<String, String> values, SecurityToken token) {
-    // TODO this seems redundant. No need to pass both fields and a map of 
field->value
+    // TODO: this seems redundant. No need to pass both fields and a map of 
field->value
+    // TODO: According to rest, yes there is. If a field is in the param list 
but not in the map
+    // that means it is a delete
     try {
       JSONObject personData = 
db.getJSONObject(DATA_TABLE).getJSONObject(userId.getUserId(token));
       if (personData == null) {
@@ -311,8 +341,7 @@
       for (Map.Entry<String, String> entry : values.entrySet()) {
         personData.put(entry.getKey(), entry.getValue());
       }
-      // TODO what is the appropriate return value
-      return null;
+      return ImmediateFuture.newInstance(new ResponseItem<Object>(""));
     } catch (JSONException je) {
       return ImmediateFuture.newInstance(new ResponseItem<Object>(
           ResponseError.INTERNAL_ERROR, je.getMessage(), null));

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=677994&r1=677993&r2=677994&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
 Fri Jul 18 11:33:58 2008
@@ -19,38 +19,15 @@
 package org.apache.shindig.social;
 
 import org.apache.shindig.common.servlet.ParameterFetcher;
+import org.apache.shindig.social.canonical.JsonDbOpensocialService;
+import org.apache.shindig.social.dataservice.ActivityService;
+import org.apache.shindig.social.dataservice.AppDataService;
 import org.apache.shindig.social.dataservice.DataServiceServletFetcher;
-import org.apache.shindig.social.opensocial.model.Activity;
-import org.apache.shindig.social.opensocial.model.ActivityImpl;
-import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.AddressImpl;
-import org.apache.shindig.social.opensocial.model.BodyType;
-import org.apache.shindig.social.opensocial.model.BodyTypeImpl;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.EmailImpl;
-import org.apache.shindig.social.opensocial.model.Enum;
-import org.apache.shindig.social.opensocial.model.EnumImpl;
-import org.apache.shindig.social.opensocial.model.NameImpl;
-import org.apache.shindig.social.opensocial.model.Organization;
-import org.apache.shindig.social.opensocial.model.OrganizationImpl;
-import org.apache.shindig.social.opensocial.model.PersonImpl;
-import org.apache.shindig.social.opensocial.model.Phone;
-import org.apache.shindig.social.opensocial.model.PhoneImpl;
-import org.apache.shindig.social.opensocial.model.Url;
-import org.apache.shindig.social.opensocial.model.UrlImpl;
-import org.apache.shindig.social.samplecontainer.XmlStateFileFetcher;
+import org.apache.shindig.social.dataservice.PersonService;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.inject.AbstractModule;
-import com.google.inject.Singleton;
 import com.google.inject.name.Names;
 
-import java.net.URI;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.logging.Logger;
 
 /**
@@ -62,200 +39,13 @@
 
   @Override
   protected void configure() {
-    bind(XmlStateFileFetcher.class).to(MockXmlStateFileFetcher.class);
     
bind(ParameterFetcher.class).annotatedWith(Names.named("DataServiceServlet"))
         .to(DataServiceServletFetcher.class);
-  }
-
-  @Singleton
-  public static class MockXmlStateFileFetcher extends XmlStateFileFetcher {
-    public static final PersonImpl johnDoe;
-    public static final PersonImpl janeDoe;
-    public static final PersonImpl simpleDoe;
-
-    public static final ActivityImpl johnActivity;
-    public static final ActivityImpl janeActivity;
-
-    static {
-      // setup John Doe
-      johnDoe = new PersonImpl("john.doe", new NameImpl("John Doe"));
-
-      // John should have every field filled in
-      johnDoe.setAboutMe("about me");
-      johnDoe.setActivities(Lists.newArrayList("activity"));
-
-      AddressImpl homeAddress = new AddressImpl("My home address");
-      homeAddress.setCountry("super");
-      homeAddress.setExtendedAddress("cali");
-      homeAddress.setLatitude(new Float(1.0));
-      homeAddress.setLocality("fragi");
-      homeAddress.setLongitude(new Float(1.0));
-      homeAddress.setPoBox("listic");
-      homeAddress.setPostalCode("559");
-      homeAddress.setRegion("expi");
-      homeAddress.setStreetAddress("ali");
-      homeAddress.setType("docious");
-      homeAddress.setUnstructuredAddress("supercalifragilisticexpialidocious");
-      johnDoe.setAddresses(Lists.<Address>newArrayList(homeAddress));
-
-      johnDoe.setAge(5);
-
-      BodyType bodyType = new BodyTypeImpl();
-      bodyType.setBuild("flying purple people eater");
-      bodyType.setEyeColor("one eyed");
-      bodyType.setHairColor("one horned");
-      bodyType.setHeight("8675309");
-      bodyType.setWeight("90210");
-      johnDoe.setBodyType(bodyType);
-
-      johnDoe.setBooks(Lists.newArrayList("books"));
-      johnDoe.setCars(Lists.newArrayList("cars"));
-      johnDoe.setChildren("children");
-      johnDoe.setCurrentLocation(new AddressImpl("my location"));
-      johnDoe.setDateOfBirth(new Date());
-      johnDoe.setDrinker(new EnumImpl<Enum.Drinker>(Enum.Drinker.HEAVILY));
-      johnDoe.setEmails(Lists.<Email>newArrayList(
-          new EmailImpl("[EMAIL PROTECTED]", "work")));
-      johnDoe.setEthnicity("purple");
-      johnDoe.setFashion("so fashionable");
-      johnDoe.setFood(Lists.newArrayList("gruel"));
-      johnDoe.setGender(new EnumImpl<Enum.Gender>(Enum.Gender.MALE));
-      johnDoe.setHappiestWhen("puppies");
-      johnDoe.setHasApp(true);
-      johnDoe.setHeroes(Lists.newArrayList("the moon"));
-      johnDoe.setHumor("not so good");
-      johnDoe.setInterests(Lists.newArrayList("kites"));
-      johnDoe.setJobInterests("penguins");
-
-      OrganizationImpl job = new OrganizationImpl();
-      job.setAddress(homeAddress);
-      job.setDescription("um");
-      job.setEndDate(new Date());
-      job.setField("diddle");
-      job.setName("diddle");
-      job.setSalary("um");
-      job.setStartDate(new Date());
-      job.setSubField("diddleye");
-      job.setTitle("Suoicodilaipxecitsiligarfilacrepus!");
-      job.setWebpage("http://en.wikipedia.org/wiki/"; +
-          "Supercalifragilisticexpialidocious");
-      johnDoe.setJobs(Lists.<Organization>newArrayList(job));
-
-      johnDoe.setLanguagesSpoken(Lists.newArrayList("alligator"));
-      johnDoe.setUpdated(new Date());
-      johnDoe.setLivingArrangement("hammock");
-      johnDoe.setLookingFor("jane doe");
-      johnDoe.setMovies(Lists.newArrayList("movies"));
-      johnDoe.setMusic(Lists.newArrayList("music"));
-      johnDoe.setNetworkPresence(new EnumImpl<Enum.NetworkPresence>(
-          Enum.NetworkPresence.DND));
-      johnDoe.setNickname("johnny boy");
-      johnDoe.setPets("simple doe");
-      johnDoe.setPhoneNumbers(Lists.<Phone>newArrayList(
-          new PhoneImpl("+33H000000000", "home")));
-      johnDoe.setPoliticalViews("none");
-      johnDoe.setProfileSong(new UrlImpl("here", "i", "am"));
-      johnDoe.setProfileUrl("http://niceness";);
-      johnDoe.setProfileVideo(new UrlImpl("here", "i", "am"));
-      johnDoe.setQuotes(Lists.newArrayList("quotes"));
-      johnDoe.setRelationshipStatus("relationships");
-      johnDoe.setReligion("religion");
-      johnDoe.setRomance("romance");
-      johnDoe.setScaredOf("scared of what");
-
-      OrganizationImpl school = new OrganizationImpl();
-      school.setAddress(homeAddress);
-      school.setDescription("gummy");
-      school.setEndDate(new Date());
-      school.setField("bears");
-      school.setName("bouncing");
-      school.setSalary("here");
-      school.setStartDate(new Date());
-      school.setSubField("and there");
-      school.setTitle("and everywhere");
-      school.setWebpage("http://en.wikipedia.org/wiki/"; +
-          "Disney's_Adventures_of_the_Gummi_Bears");
-      johnDoe.setSchools(Lists.<Organization>newArrayList(school));
-
-      johnDoe.setSexualOrientation("sexy");
-      johnDoe.setSmoker(new EnumImpl<Enum.Smoker>(Enum.Smoker.REGULARLY));
-      johnDoe.setSports(Lists.newArrayList("ping pong"));
-      johnDoe.setStatus("away");
-      johnDoe.setTags(Lists.newArrayList("tags"));
-      johnDoe.setThumbnailUrl("http://beauty";);
-      johnDoe.setTimeZone(11L);
-      johnDoe.setTurnOffs(Lists.newArrayList("off"));
-      johnDoe.setTurnOns(Lists.newArrayList("on"));
-      johnDoe.setTvShows(Lists.newArrayList("no tv"));
-      johnDoe.setUrls(Lists.<Url>newArrayList(new UrlImpl("where", "are", 
"you")));
-
-      // setup Jane Doe
-      janeDoe = new PersonImpl("jane.doe", new NameImpl("Jane Doe"));
-      janeDoe.setUpdated(new Date());
-
-      // setup Simple Doe
-      simpleDoe = new PersonImpl("simple.doe", new NameImpl("Simple Doe"));
-      simpleDoe.setUpdated(new Date());
-
-      // setup activities
-      johnActivity = new ActivityImpl("1", johnDoe.getId());
-      johnActivity.setTitle("yellow");
-      johnActivity.setBody("what a color!");
-      johnActivity.setUpdated(new Date());
-
-      janeActivity = new ActivityImpl("2", janeDoe.getId());
-      janeActivity.setTitle("green");
-      janeActivity.setBody("a better color!");
-      janeActivity.setUpdated(new Date());
-    }
-
-    public MockXmlStateFileFetcher() {
-      allPeople = Maps.newHashMap();
-      allPeople.put(johnDoe.getId(), johnDoe);
-      allPeople.put(janeDoe.getId(), janeDoe);
-      allPeople.put(simpleDoe.getId(), simpleDoe);
-
-      // Jane and Simple are John's friends.
-      friendIdMap = Maps.newHashMap();
-      friendIdMap.put(johnDoe.getId(), Lists.newArrayList(janeDoe.getId(),
-          simpleDoe.getId()));
-
-      // John is Jane's friend.
-      friendIdMap.put(janeDoe.getId(), Lists.newArrayList(johnDoe.getId()));
-
-      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");
-
-      allData = Maps.newHashMap();
-      allData.put(johnDoe.getId(), johnData);
-      allData.put(janeDoe.getId(), janeData);
-      allData.put(simpleDoe.getId(), simpleData);
-
-      List<Activity> simplesActivities = Lists.newArrayList();
-
-      allActivities = Maps.newHashMap();
-      allActivities.put(johnDoe.getId(), 
Lists.<Activity>newArrayList(johnActivity));
-      allActivities.put(janeDoe.getId(), 
Lists.<Activity>newArrayList(janeActivity));
-      allActivities.put(simpleDoe.getId(), simplesActivities);
-    }
-
-    public void resetStateFile(URI stateFile) {
-      // Ignore
-    }
-
-    public void loadDefaultStateFileIfNoneLoaded() {
-      // Ignore
-    }
-
-    public void setEvilness(boolean doEvil) {
-      // Ignore
-    }
 
+    bind(ActivityService.class).to(JsonDbOpensocialService.class);
+    bind(PersonService.class).to(JsonDbOpensocialService.class);
+    bind(AppDataService.class).to(JsonDbOpensocialService.class);
+    bind(String.class).annotatedWith(Names.named("canonical.json.db"))
+        .toInstance("sampledata/canonicaldb.json");
   }
 }

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/canonical/JsonDbOpensocialServiceTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/canonical/JsonDbOpensocialServiceTest.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/canonical/JsonDbOpensocialServiceTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/canonical/JsonDbOpensocialServiceTest.java
 Fri Jul 18 11:33:58 2008
@@ -29,11 +29,11 @@
 import org.apache.shindig.social.dataservice.UserId;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.util.BeanJsonConverter;
 
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.inject.Guice;
+import com.google.inject.Injector;
 import junit.framework.TestCase;
 
 /**
@@ -53,11 +53,8 @@
 
   @Override
   protected void setUp() throws Exception {
-    BeanJsonConverter beanJsonConverter = new BeanJsonConverter(
-        Guice.createInjector(new SocialApiTestsGuiceModule()));
-    db = new JsonDbOpensocialService(
-        "sampledata/canonicaldb.json",
-        beanJsonConverter);
+    Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule());
+    db = injector.getInstance(JsonDbOpensocialService.class);
   }
 
   public void testGetPersonDefaultFields() throws Exception {
@@ -113,7 +110,7 @@
     ResponseItem<Activity> responseItem = db.getActivity(
         CANON_USER, SELF_GROUP, APP_ID,
         Sets.newHashSet("appId", "body", "mediaItems"), APP_ID, new 
FakeGadgetToken()).get();
-    assertTrue(responseItem == null);
+    assertTrue(responseItem.getResponse() == null);
   }
 
   public void testGetExpectedAppData() throws Exception {

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulBatchTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulBatchTest.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulBatchTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulBatchTest.java
 Fri Jul 18 11:33:58 2008
@@ -67,7 +67,7 @@
     assertFalse(jsonFriends.has("errorMessage"));
 
     JSONObject jsonFriendsResponse = jsonFriends.getJSONObject("response");
-    assertEquals(2, jsonFriendsResponse.getInt("totalResults"));
+    assertEquals(3, jsonFriendsResponse.getInt("totalResults"));
     assertEquals(0, jsonFriendsResponse.getInt("startIndex"));
 
     // john.doe response

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java
 Fri Jul 18 11:33:58 2008
@@ -17,8 +17,8 @@
  */
 package org.apache.shindig.social.dataservice.integration;
 
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
 import org.apache.shindig.social.opensocial.model.Activity;
+import org.apache.shindig.social.opensocial.model.ActivityImpl;
 
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -26,6 +26,15 @@
 import org.junit.Test;
 
 public class RestfulJsonActivityTest extends AbstractLargeRestfulTests {
+  Activity johnsActivity;
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    johnsActivity = new ActivityImpl("1", "john.doe");
+    johnsActivity.setTitle("yellow");
+    johnsActivity.setBody("what a color!");
+  }
 
   /**
    * Expected response for an activity in json:
@@ -42,9 +51,7 @@
   public void testGetActivityJson() throws Exception {
     String resp = getJsonResponse("/activities/john.doe/@self/1", "GET");
     JSONObject result = getJson(resp);
-    assertActivitiesEqual(
-        SocialApiTestsGuiceModule.MockXmlStateFileFetcher.johnActivity,
-        result);
+    assertActivitiesEqual(johnsActivity, result);
   }
 
   /**
@@ -71,9 +78,7 @@
 
     assertEquals(1, result.getInt("totalResults"));
     assertEquals(0, result.getInt("startIndex"));
-    assertActivitiesEqual(
-        SocialApiTestsGuiceModule.MockXmlStateFileFetcher.johnActivity,
-        result.getJSONArray("entry").getJSONObject(0));
+    assertActivitiesEqual(johnsActivity, 
result.getJSONArray("entry").getJSONObject(0));
   }
 
   /**
@@ -82,12 +87,11 @@
    *
    * {
    *  "author" : "<???>",
-   *  "link" : {"rel" : "next", "href" : "<???>"},
-   *  "totalResults" : 1,
+   *  "totalResults" : 3,
    *  "startIndex" : 0
    *  "itemsPerPage" : 10 // Note: the js doesn't support paging. Should rest?
    *  "entry" : [
-   *     {<activity>} // layed out like above
+   *     {<activity>} // layed out like above, except for jane.doe
    *  ]
    * }
    *
@@ -95,15 +99,11 @@
    */
   @Test
   public void testGetFriendsActivitiesJson() throws Exception {
-    // TODO: change this test to use different people
     String resp = getJsonResponse("/activities/john.doe/@friends", "GET");
     JSONObject result = getJson(resp);
 
-    assertEquals(1, result.getInt("totalResults"));
+    assertEquals(2, result.getInt("totalResults"));
     assertEquals(0, result.getInt("startIndex"));
-    assertActivitiesEqual(
-        SocialApiTestsGuiceModule.MockXmlStateFileFetcher.janeActivity,
-        result.getJSONArray("entry").getJSONObject(0));
   }
 
   private void assertActivitiesEqual(Activity activity, JSONObject result)
@@ -119,7 +119,7 @@
     String postData = "{title : 'hi mom!', body : 'and dad.'}";
     getJsonResponse("/activities/john.doe/@self", "POST", postData);
 
-     String resp = getJsonResponse("/activities/john.doe/@self", "GET");
+    String resp = getJsonResponse("/activities/john.doe/@self", "GET");
     JSONObject result = getJson(resp);
 
     assertEquals(2, result.getInt("totalResults"));

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java
 Fri Jul 18 11:33:58 2008
@@ -17,8 +17,6 @@
  */
 package org.apache.shindig.social.dataservice.integration;
 
-import 
org.apache.shindig.social.SocialApiTestsGuiceModule.MockXmlStateFileFetcher;
-
 import com.google.common.collect.Maps;
 import org.json.JSONObject;
 import org.junit.Test;
@@ -33,8 +31,9 @@
    *
    * {
    *  "entry" : {
-   *    "jane.doe" : {"count" : "5"},
-   *    "simple.doe" : {"count" : "7"},
+   *    "jane.doe" : {"count" : "7"},
+   *    "george.doe" : {"count" : "2"},
+   *    "maija.m" : {}, // TODO: Should this entry really be included if she 
doesn't have any data?
    *  }
    * }
    *
@@ -48,17 +47,15 @@
     String resp = getJsonResponse("/appdata/john.doe/@friends/app", "GET", 
extraParams);
 
     JSONObject data = getJson(resp).getJSONObject("entry");
-    assertEquals(2, data.length());
+    assertEquals(3, data.length());
 
-    JSONObject janesEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.janeDoe.getId());
+    JSONObject janesEntries = data.getJSONObject("jane.doe");
     assertEquals(1, janesEntries.length());
-    assertEquals("5", janesEntries.getString("count"));
+    assertEquals("7", janesEntries.getString("count"));
 
-    JSONObject simplesEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.simpleDoe.getId());
-    assertEquals(1, simplesEntries.length());
-    assertEquals("7", simplesEntries.getString("count"));
+    JSONObject georgesEntries = data.getJSONObject("george.doe");
+    assertEquals(1, georgesEntries.length());
+    assertEquals("2", georgesEntries.getString("count"));
   }
 
   /**
@@ -82,8 +79,7 @@
     JSONObject data = getJson(resp).getJSONObject("entry");
     assertEquals(1, data.length());
 
-    JSONObject johnsEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.johnDoe.getId());
+    JSONObject johnsEntries = data.getJSONObject("john.doe");
     assertEquals(1, johnsEntries.length());
     assertEquals("0", johnsEntries.getString("count"));
   }
@@ -109,8 +105,7 @@
     JSONObject data = getJson(resp).getJSONObject("entry");
     assertEquals(1, data.length());
 
-    JSONObject johnsEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.johnDoe.getId());
+    JSONObject johnsEntries = data.getJSONObject("john.doe");
     assertEquals(1, johnsEntries.length());
     assertEquals("0", johnsEntries.getString("count"));
   }
@@ -137,8 +132,7 @@
     JSONObject data = getJson(resp).getJSONObject("entry");
     assertEquals(1, data.length());
 
-    JSONObject johnsEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.johnDoe.getId());
+    JSONObject johnsEntries = data.getJSONObject("john.doe");
     assertEquals(0, johnsEntries.length());
   }
 
@@ -176,8 +170,7 @@
     JSONObject data = getJson(resp).getJSONObject("entry");
     assertEquals(1, data.length());
 
-    JSONObject johnsEntries = data.getJSONObject(
-        MockXmlStateFileFetcher.johnDoe.getId());
+    JSONObject johnsEntries = data.getJSONObject("john.doe");
 
     if (expectedCount != null) {
       assertEquals(1, johnsEntries.length());

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
 Fri Jul 18 11:33:58 2008
@@ -17,17 +17,26 @@
  */
 package org.apache.shindig.social.dataservice.integration;
 
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
 import org.apache.shindig.social.opensocial.model.Address;
+import org.apache.shindig.social.opensocial.model.AddressImpl;
 import org.apache.shindig.social.opensocial.model.BodyType;
+import org.apache.shindig.social.opensocial.model.BodyTypeImpl;
 import org.apache.shindig.social.opensocial.model.Email;
+import org.apache.shindig.social.opensocial.model.EmailImpl;
 import org.apache.shindig.social.opensocial.model.Enum;
+import org.apache.shindig.social.opensocial.model.EnumImpl;
 import org.apache.shindig.social.opensocial.model.Name;
+import org.apache.shindig.social.opensocial.model.NameImpl;
 import org.apache.shindig.social.opensocial.model.Organization;
+import org.apache.shindig.social.opensocial.model.OrganizationImpl;
 import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.model.PersonImpl;
 import org.apache.shindig.social.opensocial.model.Phone;
+import org.apache.shindig.social.opensocial.model.PhoneImpl;
 import org.apache.shindig.social.opensocial.model.Url;
+import org.apache.shindig.social.opensocial.model.UrlImpl;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -39,6 +48,146 @@
 import java.util.Map;
 
 public class RestfulJsonPeopleTest extends AbstractLargeRestfulTests {
+  private Person canonical;
+
+  protected void setUp() throws Exception {
+    super.setUp();
+    NameImpl name = new NameImpl("Sir Shin H. Digg Social Butterfly");
+    name.setAdditionalName("H");
+    name.setFamilyName("Digg");
+    name.setGivenName("Shin");
+    name.setHonorificPrefix("Sir");
+    name.setHonorificSuffix("Social Butterfly");
+    canonical = new PersonImpl("canonical", name);
+
+    canonical.setAboutMe("I have an example of every piece of data");
+    canonical.setActivities(Lists.newArrayList("Coding Shindig"));
+
+    Address address = new AddressImpl("PoBox 3565, 1 OpenStandards Way, 
Apache, CA");
+    address.setCountry("US");
+    address.setExtendedAddress("Next door");
+    address.setLatitude(28.3043F);
+    address.setLongitude(143.0859F);
+    address.setLocality("who knows");
+    address.setPoBox("3653");
+    address.setPostalCode("12345");
+    address.setRegion("Apache, CA");
+    address.setStreetAddress("1 OpenStandards Way");
+    address.setType("home");
+    canonical.setAddresses(Lists.newArrayList(address));
+
+    canonical.setAge(33);
+    BodyTypeImpl bodyType = new BodyTypeImpl();
+    bodyType.setBuild("svelte");
+    bodyType.setEyeColor("blue");
+    bodyType.setHairColor("black");
+    bodyType.setHeight("1.84M");
+    bodyType.setWeight("184lbs");
+    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.setDateOfBirth(new Date());
+    canonical.setDrinker(new EnumImpl<Enum.Drinker>(Enum.Drinker.SOCIALLY));
+    Email email = new EmailImpl("[EMAIL PROTECTED]", "work");
+    canonical.setEmails(Lists.newArrayList(email));
+
+    canonical.setEthnicity("developer");
+    canonical.setFashion("t-shirts");
+    canonical.setFood(Lists.newArrayList("sushi", "burgers"));
+    canonical.setGender(new EnumImpl<Enum.Gender>(Enum.Gender.MALE));
+    canonical.setHappiestWhen("coding");
+    canonical.setHasApp(true);
+    canonical.setHeroes(Lists.newArrayList("Doug Crockford", "Charles 
Babbage"));
+    canonical.setHumor("none to speak of");
+    canonical.setInterests(Lists.newArrayList("PHP", "Java"));
+    canonical.setJobInterests("will work for beer");
+
+    Organization job1 = new OrganizationImpl();
+    job1.setAddress(new AddressImpl("1 Shindig Drive"));
+    job1.setDescription("lots of coding");
+    job1.setEndDate(new Date());
+    job1.setField("Software Engineering");
+    job1.setName("Apache.com");
+    job1.setSalary("$1000000000");
+    job1.setStartDate(new Date());
+    job1.setSubField("Development");
+    job1.setTitle("Grand PooBah");
+    job1.setWebpage("http://incubator.apache.org/projects/shindig.html";);
+
+    Organization job2 = new OrganizationImpl();
+    job2.setAddress(new AddressImpl("1 Skid Row"));
+    job2.setDescription("");
+    job2.setEndDate(new Date());
+    job2.setField("College");
+    job2.setName("School of hard Knocks");
+    job2.setSalary("$100");
+    job2.setStartDate(new Date());
+    job2.setSubField("Lab Tech");
+    job2.setTitle("Gopher");
+    job2.setWebpage("");
+
+    canonical.setJobs(Lists.newArrayList(job1, job2));
+
+    canonical.setUpdated(new Date());
+    canonical.setLanguagesSpoken(Lists.newArrayList("English", "Dutch", 
"Esperanto"));
+    canonical.setLivingArrangement("in a house");
+    canonical.setLookingFor("patches");
+    canonical.setMovies(Lists.newArrayList("Iron Man", "Nosferatu"));
+    canonical.setMusic(Lists.newArrayList("Chieftains", "Beck"));
+    canonical.setNetworkPresence(new 
EnumImpl<Enum.NetworkPresence>(Enum.NetworkPresence.ONLINE));
+    canonical.setNickname("diggy");
+    canonical.setPets("dog,cat");
+    canonical.setPhoneNumbers(Lists.<Phone>newArrayList(new 
PhoneImpl("111-111-111", "work"),
+        new PhoneImpl("999-999-999", "mobile")));
+
+    canonical.setPoliticalViews("open leaning");
+    canonical.setProfileSong(new 
UrlImpl("http://www.example.org/songs/OnlyTheLonely.mp3";,
+        "Feelin' blue", "road"));
+    canonical.setProfileUrl("http://www.example.org/?id=1";);
+    canonical.setProfileVideo(new 
UrlImpl("http://www.example.org/videos/Thriller.flv";,
+        "Thriller", "video"));
+
+    canonical.setQuotes(Lists.newArrayList("I am therfore I code", "Doh!"));
+    canonical.setRelationshipStatus("married to my job");
+    canonical.setReligion("druidic");
+    canonical.setRomance("twice a year");
+    canonical.setScaredOf("COBOL");
+
+    Organization school = new OrganizationImpl();
+    school.setAddress(new AddressImpl("1 Edu St."));
+    school.setDescription("High School");
+    school.setEndDate(new Date());
+    school.setField("");
+    school.setName("");
+    school.setSalary("");
+    school.setStartDate(new Date());
+    school.setSubField("");
+    school.setTitle("");
+    school.setWebpage("");
+    canonical.setSchools(Lists.newArrayList(school));
+
+    canonical.setSexualOrientation("north");
+    canonical.setSmoker(new EnumImpl<Enum.Smoker>(Enum.Smoker.NO));
+    canonical.setSports(Lists.newArrayList("frisbee", "rugby"));
+    canonical.setStatus("happy");
+    canonical.setTags(Lists.newArrayList("C#", "JSON", "template"));
+    canonical.setThumbnailUrl("http://www.example.org/pic/?id=1";);
+    canonical.setTimeZone(-8L);
+    canonical.setTurnOffs(Lists.newArrayList("lack of unit tests", "cabbage"));
+    canonical.setTurnOns(Lists.newArrayList("well document code"));
+    canonical.setTvShows(Lists.newArrayList("House", "Battlestar Galactica"));
+
+    canonical.setUrls(Lists.<Url>newArrayList(
+        new UrlImpl("http://www.example.org/?id=1";, "Profile", "text/html"),
+        new UrlImpl("http://www.example.org/pic/?id=1";, "Thumbnail", 
"img/*")));
+  }
 
   /**
    * Expected response for john.doe's json:
@@ -65,49 +214,58 @@
    */
   @Test
   public void testGetPersonJson() throws Exception {
+    // TODO(doll): Test all of the date fields
+
+    Map<String, String> extraParams = Maps.newHashMap();
+    String allFieldsParam = "";
+    for (String allField : Person.Field.ALL_FIELDS) {
+      allFieldsParam += allField + ",";
+    }
+    extraParams.put("fields", allFieldsParam);
+
     // Currently, for Shindig {pid}/@all/{uid} == {uid}/@self
-    String resp = getJsonResponse("/people/john.doe/@self", "GET");
+    String resp = getJsonResponse("/people/canonical/@self", "GET", 
extraParams);
     JSONObject result = getJson(resp);
 
-    Person johnDoe = SocialApiTestsGuiceModule.MockXmlStateFileFetcher.johnDoe;
-    assertStringField(result, johnDoe.getAboutMe(), Person.Field.ABOUT_ME);
-    assertStringListField(result, johnDoe.getActivities(),
+    assertStringField(result, canonical.getAboutMe(), Person.Field.ABOUT_ME);
+    assertStringListField(result, canonical.getActivities(),
         Person.Field.ACTIVITIES);
 
     JSONObject jsonAddress = result.getJSONArray(
         Person.Field.ADDRESSES.toString()).getJSONObject(0);
-    assertAddressField(johnDoe.getAddresses().get(0), jsonAddress);
+    assertAddressField(canonical.getAddresses().get(0), jsonAddress);
 
-    assertEquals(johnDoe.getAge().intValue(), result.getInt(
+    assertEquals(canonical.getAge().intValue(), result.getInt(
         Person.Field.AGE.toString()));
 
     JSONObject jsonBody = result.getJSONObject(
         Person.Field.BODY_TYPE.toString());
-    BodyType body = johnDoe.getBodyType();
+    BodyType body = canonical.getBodyType();
     assertStringField(jsonBody, body.getBuild(), BodyType.Field.BUILD);
     assertStringField(jsonBody, body.getEyeColor(), BodyType.Field.EYE_COLOR);
     assertStringField(jsonBody, body.getHairColor(), 
BodyType.Field.HAIR_COLOR);
     assertStringField(jsonBody, body.getHeight(), BodyType.Field.HEIGHT);
     assertStringField(jsonBody, body.getWeight(), BodyType.Field.WEIGHT);
 
-    assertStringListField(result, johnDoe.getBooks(), Person.Field.BOOKS);
-    assertStringListField(result, johnDoe.getCars(), Person.Field.CARS);
-    assertStringField(result, johnDoe.getChildren(), Person.Field.CHILDREN);
-
-    assertStringField(result.getJSONObject(
-        Person.Field.CURRENT_LOCATION.toString()),
-        johnDoe.getCurrentLocation().getUnstructuredAddress(),
-        Address.Field.UNSTRUCTURED_ADDRESS);
-
-    assertStringField(result, johnDoe.getDateOfBirth().toString(),
-        Person.Field.DATE_OF_BIRTH);
-    assertEnumField(result, johnDoe.getDrinker(), Person.Field.DRINKER);
+    assertStringListField(result, canonical.getBooks(), Person.Field.BOOKS);
+    assertStringListField(result, canonical.getCars(), Person.Field.CARS);
+    assertStringField(result, canonical.getChildren(), Person.Field.CHILDREN);
+
+    JSONObject currentLocation = 
result.getJSONObject(Person.Field.CURRENT_LOCATION.toString());
+    assertFloatField(currentLocation, 
canonical.getCurrentLocation().getLatitude(),
+        Address.Field.LATITUDE);
+    assertFloatField(currentLocation, 
canonical.getCurrentLocation().getLongitude(),
+        Address.Field.LONGITUDE);
+
+//    assertLongField(result, canonical.getDateOfBirth().getTime(),
+//        Person.Field.DATE_OF_BIRTH);
+//    assertEnumField(result, canonical.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);
+    for (int i = 0; i < canonical.getEmails().size(); i++) {
+      Email expectedEmail = canonical.getEmails().get(i);
       JSONObject actualEmail = emailArray.getJSONObject(i);
       assertEquals(expectedEmail.getType(),
           actualEmail.getString(Email.Field.TYPE.toString()));
@@ -115,49 +273,49 @@
           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(),
+    assertStringField(result, canonical.getEthnicity(), 
Person.Field.ETHNICITY);
+    assertStringField(result, canonical.getFashion(), Person.Field.FASHION);
+    assertStringListField(result, canonical.getFood(), Person.Field.FOOD);
+    assertEnumField(result, canonical.getGender(), Person.Field.GENDER);
+    assertStringField(result, canonical.getHappiestWhen(),
         Person.Field.HAPPIEST_WHEN);
-    assertBooleanField(result, johnDoe.getHasApp(), Person.Field.HAS_APP);
-    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(),
+    assertBooleanField(result, canonical.getHasApp(), Person.Field.HAS_APP);
+    assertStringListField(result, canonical.getHeroes(), Person.Field.HEROES);
+    assertStringField(result, canonical.getHumor(), Person.Field.HUMOR);
+    assertStringField(result, canonical.getId(), Person.Field.ID);
+    assertStringListField(result, canonical.getInterests(),
         Person.Field.INTERESTS);
-    assertStringField(result, johnDoe.getJobInterests(),
+    assertStringField(result, canonical.getJobInterests(),
         Person.Field.JOB_INTERESTS);
 
-    assertOrganizationField(johnDoe.getJobs().get(0),
+    assertOrganizationField(canonical.getJobs().get(0),
         result.getJSONArray(Person.Field.JOBS.toString()).getJSONObject(0));
 
-    assertStringListField(result, johnDoe.getLanguagesSpoken(),
+    assertStringListField(result, canonical.getLanguagesSpoken(),
         Person.Field.LANGUAGES_SPOKEN);
-    assertDateField(result, johnDoe.getUpdated(), Person.Field.LAST_UPDATED);
-    assertStringField(result, johnDoe.getLivingArrangement(),
+//    assertDateField(result, canonical.getUpdated(), 
Person.Field.LAST_UPDATED);
+    assertStringField(result, canonical.getLivingArrangement(),
         Person.Field.LIVING_ARRANGEMENT);
-    assertStringField(result, johnDoe.getLookingFor(),
+    assertStringField(result, canonical.getLookingFor(),
         Person.Field.LOOKING_FOR);
-    assertStringListField(result, johnDoe.getMovies(), Person.Field.MOVIES);
-    assertStringListField(result, johnDoe.getMusic(), Person.Field.MUSIC);
+    assertStringListField(result, canonical.getMovies(), Person.Field.MOVIES);
+    assertStringListField(result, canonical.getMusic(), Person.Field.MUSIC);
 
-    assertEquals(johnDoe.getName().getUnstructured(),
+    assertEquals(canonical.getName().getUnstructured(),
         result.getJSONObject(Person.Field.NAME.toString()).getString(
             Name.Field.UNSTRUCTURED.toString()));
 
-    assertEnumField(result, johnDoe.getNetworkPresence(),
+    assertEnumField(result, canonical.getNetworkPresence(),
         Person.Field.NETWORKPRESENCE);
-    assertStringField(result, johnDoe.getNickname(), Person.Field.NICKNAME);
-    assertStringField(result, johnDoe.getPets(), Person.Field.PETS);
+    assertStringField(result, canonical.getNickname(), Person.Field.NICKNAME);
+    assertStringField(result, canonical.getPets(), Person.Field.PETS);
 
     JSONArray phoneArray = result.getJSONArray(
         Person.Field.PHONE_NUMBERS.toString());
-    assertEquals(1, phoneArray.length());
+    assertEquals(canonical.getPhoneNumbers().size(), phoneArray.length());
 
-    for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
-      Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
+    for (int i = 0; i < canonical.getPhoneNumbers().size(); i++) {
+      Phone expectedPhone = canonical.getPhoneNumbers().get(i);
       JSONObject actualPhone = phoneArray.getJSONObject(i);
       assertEquals(expectedPhone.getType(), actualPhone.getString(
           Phone.Field.TYPE.toString()));
@@ -165,39 +323,38 @@
           Phone.Field.NUMBER.toString()));
     }
 
-    assertStringField(result, johnDoe.getPoliticalViews(),
+    assertStringField(result, canonical.getPoliticalViews(),
         Person.Field.POLITICAL_VIEWS);
 
-    assertUrlField(johnDoe.getProfileSong(), result.getJSONObject(
+    assertUrlField(canonical.getProfileSong(), result.getJSONObject(
         Person.Field.PROFILE_SONG.toString()));
-    assertStringField(result, johnDoe.getProfileUrl(),
+    assertStringField(result, canonical.getProfileUrl(),
         Person.Field.PROFILE_URL);
-    assertUrlField(johnDoe.getProfileVideo(), result.getJSONObject(
+    assertUrlField(canonical.getProfileVideo(), result.getJSONObject(
         Person.Field.PROFILE_VIDEO.toString()));
 
-    assertStringListField(result, johnDoe.getQuotes(), Person.Field.QUOTES);
-    assertStringField(result, johnDoe.getRelationshipStatus(),
+    assertStringListField(result, canonical.getQuotes(), Person.Field.QUOTES);
+    assertStringField(result, canonical.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);
-
-    assertOrganizationField(johnDoe.getJobs().get(0),
-        result.getJSONArray(Person.Field.JOBS.toString()).getJSONObject(0));
-
-    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(),
+    assertStringField(result, canonical.getReligion(), Person.Field.RELIGION);
+    assertStringField(result, canonical.getRomance(), Person.Field.ROMANCE);
+    assertStringField(result, canonical.getScaredOf(), Person.Field.SCARED_OF);
+
+    assertOrganizationField(canonical.getSchools().get(0),
+        result.getJSONArray(Person.Field.SCHOOLS.toString()).getJSONObject(0));
+
+    assertStringField(result, canonical.getSexualOrientation(), 
Person.Field.SEXUAL_ORIENTATION);
+    assertEnumField(result, canonical.getSmoker(), Person.Field.SMOKER);
+    assertStringListField(result, canonical.getSports(), Person.Field.SPORTS);
+    assertStringField(result, canonical.getStatus(), Person.Field.STATUS);
+    assertStringListField(result, canonical.getTags(), Person.Field.TAGS);
+    assertStringField(result, canonical.getThumbnailUrl(),
         Person.Field.THUMBNAIL_URL);
     // TODO: time zone
-    assertStringListField(result, johnDoe.getTurnOffs(),
+    assertStringListField(result, canonical.getTurnOffs(),
         Person.Field.TURN_OFFS);
-    assertStringListField(result, johnDoe.getTurnOns(), Person.Field.TURN_ONS);
-    assertStringListField(result, johnDoe.getTvShows(), Person.Field.TV_SHOWS);
+    assertStringListField(result, canonical.getTurnOns(), 
Person.Field.TURN_ONS);
+    assertStringListField(result, canonical.getTvShows(), 
Person.Field.TV_SHOWS);
   }
 
   private void assertAddressField(Address expected, JSONObject actual)
@@ -229,21 +386,18 @@
 
   private void assertOrganizationField(Organization expected, JSONObject 
actual)
       throws JSONException {
-    assertAddressField(expected.getAddress(), actual.getJSONObject(
-        Organization.Field.ADDRESS.toString()));
+    
assertStringField(actual.getJSONObject(Organization.Field.ADDRESS.toString()),
+        expected.getAddress().getUnstructuredAddress(), 
Address.Field.UNSTRUCTURED_ADDRESS);
     assertStringField(actual, expected.getDescription(),
         Organization.Field.DESCRIPTION);
-    assertDateField(actual, expected.getEndDate(), 
Organization.Field.END_DATE);
+//    assertDateField(actual, expected.getEndDate(), 
Organization.Field.END_DATE);
     assertStringField(actual, expected.getField(), Organization.Field.FIELD);
     assertStringField(actual, expected.getName(), Organization.Field.NAME);
     assertStringField(actual, expected.getSalary(), Organization.Field.SALARY);
-    assertDateField(actual, expected.getStartDate(),
-        Organization.Field.START_DATE);
-    assertStringField(actual, expected.getSubField(),
-        Organization.Field.SUB_FIELD);
+//    assertDateField(actual, expected.getStartDate(), 
Organization.Field.START_DATE);
+    assertStringField(actual, expected.getSubField(), 
Organization.Field.SUB_FIELD);
     assertStringField(actual, expected.getTitle(), Organization.Field.TITLE);
-    assertStringField(actual, expected.getWebpage(),
-        Organization.Field.WEBPAGE);
+    assertStringField(actual, expected.getWebpage(), 
Organization.Field.WEBPAGE);
   }
 
   private void assertBooleanField(JSONObject result, boolean expected,
@@ -283,11 +437,12 @@
    * Expected response for a list of people in json:
    *
    * {
-   *  "totalResults" : 2,
+   *  "totalResults" : 3,
    *  "startIndex" : 0
    *  "entry" : [
    *     {<jane doe>}, // layed out like above
-   *     {<simple doe>},
+   *     {<george doe>},
+   *     {<maija m>},
    *  ]
    * }
    *
@@ -306,14 +461,14 @@
     String resp = getJsonResponse("/people/john.doe/@friends", "GET", 
extraParams);
     JSONObject result = getJson(resp);
 
-    assertEquals(2, result.getInt("totalResults"));
+    assertEquals(3, result.getInt("totalResults"));
     assertEquals(0, result.getInt("startIndex"));
 
     JSONArray people = result.getJSONArray("entry");
 
     // The users should be in alphabetical order
-    assertPerson(people.getJSONObject(0), "jane.doe", "Jane Doe");
-    assertPerson(people.getJSONObject(1), "simple.doe", "Simple Doe");
+    assertPerson(people.getJSONObject(0), "george.doe", "George Doe");
+    assertPerson(people.getJSONObject(1), "jane.doe", "Jane Doe");
   }
 
   @Test
@@ -328,22 +483,22 @@
     String resp = getJsonResponse("/people/john.doe/@friends", "GET", 
extraParams);
     JSONObject result = getJson(resp);
 
-    assertEquals(2, result.getInt("totalResults"));
+    assertEquals(3, result.getInt("totalResults"));
     assertEquals(0, result.getInt("startIndex"));
 
     JSONArray people = result.getJSONArray("entry");
-    assertPerson(people.getJSONObject(0), "jane.doe", "Jane Doe");
+    assertPerson(people.getJSONObject(0), "george.doe", "George Doe");
 
     // Get the second page
     extraParams.put("startIndex", "1");
     resp = getJsonResponse("/people/john.doe/@friends", "GET", extraParams);
     result = getJson(resp);
 
-    assertEquals(2, result.getInt("totalResults"));
+    assertEquals(3, result.getInt("totalResults"));
     assertEquals(1, result.getInt("startIndex"));
 
     people = result.getJSONArray("entry");
-    assertPerson(people.getJSONObject(0), "simple.doe", "Simple Doe");
+    assertPerson(people.getJSONObject(0), "jane.doe", "Jane Doe");
   }
 
   private void assertPerson(JSONObject person, String expectedId, String 
expectedName)

Modified: incubator/shindig/trunk/javascript/sampledata/canonicaldb.json
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/sampledata/canonicaldb.json?rev=677994&r1=677993&r2=677994&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/sampledata/canonicaldb.json (original)
+++ incubator/shindig/trunk/javascript/sampledata/canonicaldb.json Fri Jul 18 
11:33:58 2008
@@ -29,10 +29,12 @@
       "extendedAddress" : "Next door",
       "latitude" : "28.3043",
       "longitude" : "143.0859",
+      "locality" : "who knows",
       "poBox" : "3653",
       "postalCode" : "12345",
       "region" : "Apache, CA",
       "streetAddress" : "1 OpenStandards Way",
+      "type" : "home",
       "unstructuredAddress" : "PoBox 3565, 1 OpenStandards Way, Apache, CA"
       }],
     "age" : 33,
@@ -115,7 +117,7 @@
     },
     "networkPresence" : {
       "key" : "ONLINE",
-      "displayvalue" : "online"
+      "displayvalue" : "Online"
     },
     "nickname" : "diggy",
     "pets" : "dog,cat",
@@ -135,7 +137,8 @@
     "profileUrl" : "http://www.example.org/?id=1";,
     "profileVideo" : {
      "address" : "http://www.example.org/videos/Thriller.flv";,
-     "linkText" : "Thriller"
+     "linkText" : "Thriller",
+     "type" : "video"
     },
     "quotes" : ["I am therfore I code", "Doh!"],
     "relationshipStatus" : "married to my job",
@@ -148,7 +151,13 @@
       },
       "description" : "High School",
       "endDate" : "1991-01-01",
-      "startDate" : "1982-01-01"
+      "field" : "",
+      "name" : "",
+      "salary" : "",
+      "startDate" : "1982-01-01",
+      "subField" : "",
+      "title" : "",
+      "webpage" : ""
       }],
     "sexualOrientation" : "north",
     "smoker" : {
@@ -233,9 +242,9 @@
     },
     "hasApp" : true,
     "name" : {
-      "familyName" : "Meikäläinen",
+      "familyName" : "Meikäläinen",
       "givenName" : "Maija",
-      "unstructured" : "Maija Meikäläinen"
+      "unstructured" : "Maija Meikäläinen"
     }
   }],
   //
@@ -246,6 +255,9 @@
       "count" : "2",
       "size" : "100"
     },
+    "john.doe" : {
+      "count" : "0"
+    },
     "george.doe" : {
       "count" : "2"
     },
@@ -306,16 +318,22 @@
       "url" : "http://www.example.org/canonical/activities/2";,
       "userId" : "canonical"
     }],
+    "john.doe" : [{
+      "id" : "1",
+      "userId" : "john.doe",
+      "title" : "yellow",
+      "body" : "what a color!",
+    }],
     "jane.doe" : [{
       "id" : "1",
       "body" : "and she thinks you look like him",
       "mediaItems" : [{
         "mimeType" : "image/jpeg",
-        "type" : "IMAGE",
+        "type" : "image",
         "url" : 
"http://animals.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/animals/images/primary/black-spider-monkey.jpg";
       },{
         "mimeType" : "image/jpeg",
-        "type" : "IMAGE",
+        "type" : "image",
         "url" : 
"http://image.guardian.co.uk/sys-images/Guardian/Pix/gallery/2002/01/03/monkey300.jpg";
       }],
       "streamTitle" : "jane's photos",
@@ -326,7 +344,7 @@
       "body" : "or is it you?",
       "mediaItems" : [{
         "mimeType" : "image/jpeg",
-        "type" : "IMAGE",
+        "type" : "image",
         "url" : 
"http://www.funnyphotos.net.au/images/fancy-dress-dog-yoda-from-star-wars1.jpg";
       }],
       "streamTitle" : "jane's photos",
@@ -339,7 +357,7 @@
   // ----------------------------- Data ---------------------------------------
   //
   "friendLinks" : {
-    "canonical" : ["john.doe", "jane.doe", "george.doe", "maija.m"], 
+    "canonical" : ["john.doe", "jane.doe", "george.doe", "maija.m"],
     "john.doe" : ["jane.doe", "george.doe", "maija.m"],
     "jane.doe" : ["john.doe"],
     "george.doe" : ["john.doe"],


Reply via email to