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/03/11 14:47:40 UTC

svn commit: r635923 - in /incubator/shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/social/ test/java/org/apache/shindig/social/

Author: doll
Date: Tue Mar 11 06:47:35 2008
New Revision: 635923

URL: http://svn.apache.org/viewvc?rev=635923&view=rev
Log:
Patch from Vincent Demay - SHINDIG-116

This added more java pojos corresponding to the opensocial objects. Also cleans up the related test to use JSONObjects instead of string comparison. 

I had to move the test from AbstractSocialDataTest to SocialDataTest because it seems that it wasn't being run when the classname started with "Abstract".



Added:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Activity.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Email.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/MediaItem.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Organization.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Url.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/SocialDataTest.java
      - copied, changed from r635885, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/AbstractSocialDataTest.java
Removed:
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/AbstractSocialDataTest.java
Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Person.java

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Activity.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Activity.java?rev=635923&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Activity.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Activity.java Tue Mar 11 06:47:35 2008
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social;
+
+public class Activity extends AbstractSocialData {
+  private String appId;
+  private String body;
+  private String bodyId;
+  private String externalId;
+  @Mandatory private String id;
+  private MediaItem[] mediaItems;
+  private Long postedTime;
+  private Float priority;
+  private String streamFaviconUrl;
+  private String streamSourceUrl;
+  private String streamTitle;
+  private String streamUrl;
+  // private Map<String, String> templateParams
+  private String title;
+  private String titleId;
+  private String url;
+  @Mandatory private String userId;
+
+  public Activity(String id, String appId, String userId) {
+    this.id = id;
+    this.appId = appId;
+    this.userId = userId;
+  }
+
+  public String getAppId() {
+    return appId;
+  }
+
+  public void setAppId(String appId) {
+    this.appId = appId;
+  }
+
+  public String getBody() {
+    return body;
+  }
+
+  public void setBody(String body) {
+    this.body = body;
+  }
+
+  public String getBodyId() {
+    return bodyId;
+  }
+
+  public void setBodyId(String bodyId) {
+    this.bodyId = bodyId;
+  }
+
+  public String getExternalId() {
+    return externalId;
+  }
+
+  public void setExternalId(String externalId) {
+    this.externalId = externalId;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public MediaItem[] getMediaItems() {
+    return mediaItems;
+  }
+
+  public void setMediaItems(MediaItem[] mediaItems) {
+    this.mediaItems = mediaItems;
+  }
+
+  public Long getPostedTime() {
+    return postedTime;
+  }
+
+  public void setPostedTime(Long postedTime) {
+    this.postedTime = postedTime;
+  }
+
+  public Float getPriority() {
+    return priority;
+  }
+
+  public void setPriority(Float priority) {
+    this.priority = priority;
+  }
+
+  public String getStreamFaviconUrl() {
+    return streamFaviconUrl;
+  }
+
+  public void setStreamFaviconUrl(String streamFaviconUrl) {
+    this.streamFaviconUrl = streamFaviconUrl;
+  }
+
+  public String getStreamSourceUrl() {
+    return streamSourceUrl;
+  }
+
+  public void setStreamSourceUrl(String streamSourceUrl) {
+    this.streamSourceUrl = streamSourceUrl;
+  }
+
+  public String getStreamTitle() {
+    return streamTitle;
+  }
+
+  public void setStreamTitle(String streamTitle) {
+    this.streamTitle = streamTitle;
+  }
+
+  public String getStreamUrl() {
+    return streamUrl;
+  }
+
+  public void setStreamUrl(String streamUrl) {
+    this.streamUrl = streamUrl;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getTitleId() {
+    return titleId;
+  }
+
+  public void setTitleId(String titleId) {
+    this.titleId = titleId;
+  }
+
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public String getUserId() {
+    return userId;
+  }
+
+  public void setUserId(String userId) {
+    this.userId = userId;
+  }
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Email.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Email.java?rev=635923&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Email.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Email.java Tue Mar 11 06:47:35 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social;
+
+/**
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Email.Field.html
+ *
+ */
+public class Email extends AbstractSocialData {
+  private String address;
+  private String type;
+
+  public Email(String address, String type) {
+    this.address = address;
+    this.type = type;
+  }
+
+  public String getAddress() {
+    return address;
+  }
+
+  public void setAddress(String address) {
+    this.address = address;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/MediaItem.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/MediaItem.java?rev=635923&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/MediaItem.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/MediaItem.java Tue Mar 11 06:47:35 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social;
+
+/**
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Activity.MediaItem.Field.html
+ *
+ */
+public class MediaItem extends AbstractSocialData {
+  private String mimeType;
+  private Type type;
+  private String url;
+
+  public enum Type {
+    AUDIO("AUDIO"),
+    VIDEO("VIDEO"),
+    IMAGE("IMAGE");
+
+    private final String jsonString;
+
+    private Type(String jsonString) {
+      this.jsonString = jsonString;
+    }
+
+    @Override
+    public String toString() {
+      return this.jsonString;
+    }
+  }
+
+  public MediaItem(String mimeType, Type type, String url) {
+    this.mimeType = mimeType;
+    this.type = type;
+    this.url = url;
+  }
+
+  public String getMimeType() {
+    return mimeType;
+  }
+
+  public void setMimeType(String mimeType) {
+    this.mimeType = mimeType;
+  }
+
+  public Type getType() {
+    return type;
+  }
+
+  public void setType(Type type) {
+    this.type = type;
+  }
+
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Organization.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Organization.java?rev=635923&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Organization.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Organization.java Tue Mar 11 06:47:35 2008
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social;
+
+import java.util.Date;
+
+/**
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Organization.Field.html
+ *
+ */
+public class Organization extends AbstractSocialData {
+  private Address address;
+  private String description;
+  private Date endDate;
+  private String field;
+  private String name;
+  private String salary;
+  private Date startDate;
+  private String subField;
+  private String title;
+  private String webpage;
+
+  public Address getAddress() {
+    return address;
+  }
+
+  public void setAddress(Address address) {
+    this.address = address;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public Date getEndDate() {
+    return endDate;
+  }
+
+  public void setEndDate(Date endDate) {
+    this.endDate = endDate;
+  }
+
+  public String getField() {
+    return field;
+  }
+
+  public void setField(String field) {
+    this.field = field;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getSalary() {
+    return salary;
+  }
+
+  public void setSalary(String salary) {
+    this.salary = salary;
+  }
+
+  public Date getStartDate() {
+    return startDate;
+  }
+
+  public void setStartDate(Date startDate) {
+    this.startDate = startDate;
+  }
+
+  public String getSubField() {
+    return subField;
+  }
+
+  public void setSubField(String subField) {
+    this.subField = subField;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getWebpage() {
+    return webpage;
+  }
+
+  public void setWebpage(String webpage) {
+    this.webpage = webpage;
+  }
+
+}

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Person.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Person.java?rev=635923&r1=635922&r2=635923&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Person.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Person.java Tue Mar 11 06:47:35 2008
@@ -40,7 +40,7 @@
   private Date dateOfBirth;
   // drinker : Person's drinking status, specified as an opensocial.Enum with
   // the enum's key referencing opensocial.Enum.Drinker.
-  // emails :Emails associated with the person, specified as an Array of Emails.
+  private Email[] emails;
   private String ethnicity;
   private String fashion;
   private String[] food;
@@ -52,11 +52,10 @@
   @Mandatory private String id;
   private String[] interests;
   private String jobInterests;
-  // private Organization[] jobs;
+  private Organization[] jobs;
   private String[] languagesSpoken;
   private String livingArrangement;
-  // lookingFor : Person's statement about who or what they are looking for, or
-  // what they are interested in meeting people for.
+  private String lookingFor;
   private String[] movies;
   private String[] music;
   @Mandatory private Name name;
@@ -64,15 +63,15 @@
   private String pets;
   private Phone[] phoneNumbers;
   private String politicalViews;
-  // private Url profileSong
+  private Url profileSong;
   private String profileUrl;
-  // private Url profileVideo
+  private Url profileVideo;
   private String[] quotes;
   private String relationshipStatus;
   private String religion;
   private String romance;
   private String scaredOf;
-  // private Organization[] schools;
+  private Organization[] schools;
   private String sexualOrientation;
   // smoker Person's smoking status, specified as an opensocial.Enum with the
   // enum's key referencing opensocial.Enum.Smoker.
@@ -80,12 +79,11 @@
   private String status;
   private String[] tags;
   private String thumbnailUrl;
-  // time_zone Person's time zone, specified as the difference in minutes
-  // between Greenwich Mean Time (GMT) and the user's local time.
+  private Long timeZone;
   private String[] turnOffs;
   private String[] turnOns;
   private String[] tvShows;
-  // private Url[] urls;
+  private Url[] urls;
 
   public Person(String id, Name name) {
     this.id = id;
@@ -172,6 +170,14 @@
     this.dateOfBirth = dateOfBirth;
   }
 
+  public Email[] getEmails() {
+    return emails;
+  }
+
+  public void setEmails(Email[] emails) {
+    this.emails = emails;
+  }
+
   public String getEthnicity() {
     return ethnicity;
   }
@@ -244,6 +250,14 @@
     this.jobInterests = jobInterests;
   }
 
+  public Organization[] getJobs() {
+    return jobs;
+  }
+
+  public void setJobs(Organization[] jobs) {
+    this.jobs = jobs;
+  }
+
   public String[] getLanguagesSpoken() {
     return languagesSpoken;
   }
@@ -260,6 +274,14 @@
     this.livingArrangement = livingArrangement;
   }
 
+  public String getLookingFor() {
+    return lookingFor;
+  }
+
+  public void setLookingFor(String lookingFor) {
+    this.lookingFor = lookingFor;
+  }
+
   public String[] getMovies() {
     return movies;
   }
@@ -316,6 +338,14 @@
     this.politicalViews = politicalViews;
   }
 
+  public Url getProfileSong() {
+    return profileSong;
+  }
+
+  public void setProfileSong(Url profileSong) {
+    this.profileSong = profileSong;
+  }
+
   public String getProfileUrl() {
     return profileUrl;
   }
@@ -324,6 +354,14 @@
     this.profileUrl = profileUrl;
   }
 
+  public Url getProfileVideo() {
+    return profileVideo;
+  }
+
+  public void setProfileVideo(Url profileVideo) {
+    this.profileVideo = profileVideo;
+  }
+
   public String[] getQuotes() {
     return quotes;
   }
@@ -364,6 +402,14 @@
     this.scaredOf = scaredOf;
   }
 
+  public Organization[] getSchools() {
+    return schools;
+  }
+
+  public void setSchools(Organization[] schools) {
+    this.schools = schools;
+  }
+
   public String getSexualOrientation() {
     return sexualOrientation;
   }
@@ -404,6 +450,14 @@
     this.thumbnailUrl = thumbnailUrl;
   }
 
+  public Long getTimeZone() {
+    return timeZone;
+  }
+
+  public void setTimeZone(Long timeZone) {
+    this.timeZone = timeZone;
+  }
+
   public String[] getTurnOffs() {
     return turnOffs;
   }
@@ -426,5 +480,13 @@
 
   public void setTvShows(String[] tvShows) {
     this.tvShows = tvShows;
+  }
+
+  public Url[] getUrls() {
+    return urls;
+  }
+
+  public void setUrls(Url[] urls) {
+    this.urls = urls;
   }
 }

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Url.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Url.java?rev=635923&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Url.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/Url.java Tue Mar 11 06:47:35 2008
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social;
+
+/**
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Url.Field.html
+ */
+public class Url extends AbstractSocialData {
+  private String address;
+  private String linkText;
+  private String type;
+
+  public Url(String address, String linkText, String type) {
+    this.address = address;
+    this.linkText = linkText;
+    this.type = type;
+  }
+
+  public String getAddress() {
+    return address;
+  }
+
+  public void setAddress(String address) {
+    this.address = address;
+  }
+
+  public String getLinkText() {
+    return linkText;
+  }
+
+  public void setLinkText(String linkText) {
+    this.linkText = linkText;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+}

Copied: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/SocialDataTest.java (from r635885, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/AbstractSocialDataTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/SocialDataTest.java?p2=incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/SocialDataTest.java&p1=incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/AbstractSocialDataTest.java&r1=635885&r2=635923&rev=635923&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/AbstractSocialDataTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/social/SocialDataTest.java Tue Mar 11 06:47:35 2008
@@ -17,10 +17,14 @@
  */
 package org.apache.shindig.social;
 
+import org.json.JSONArray;
+import org.json.JSONObject;
+
 import junit.framework.TestCase;
 
-public class AbstractSocialDataTest extends TestCase {
+public class SocialDataTest extends TestCase {
   private Person johnDoe;
+  private Activity activity;
 
   @Override
   public void setUp() throws Exception {
@@ -35,16 +39,69 @@
       new Address("My home address")
     };
     johnDoe.setAddresses(addresses);
+
+    Email[] emails = {
+      new Email("john.doe@work.bar", "work"),
+      new Email("john.doe@home.bar", "home"),
+    };
+    johnDoe.setEmails(emails);
+
+    activity = new Activity("activityId", "appId", johnDoe.getId());
+    MediaItem[] mediaItems = {
+        new MediaItem("image/jpg", MediaItem.Type.IMAGE, "http://foo.bar")
+    };
+    activity.setMediaItems(mediaItems);
   }
 
   public void testPersonToJson() throws Exception {
-    assertEquals(johnDoe.toJson().toString(),
-        "{\"id\":\"johnDoeId\"," +
-         "\"name\":{\"unstructured\":\"John Doe\"}," +
-         "\"phoneNumbers\":[" +
-            "{\"number\":\"+33H000000000\",\"type\":\"home\"}," +
-            "{\"number\":\"+33M000000000\",\"type\":\"mobile\"}," +
-            "{\"number\":\"+33W000000000\",\"type\":\"work\"}]," +
-         "\"addresses\":[{\"unstructuredAddress\":\"My home address\"}]}");
+    JSONObject result = johnDoe.toJson();
+
+    assertEquals(johnDoe.getId(), result.getString("id"));
+
+    assertEquals(johnDoe.getName().getUnstructured(),
+        result.getJSONObject("name").getString("unstructured"));
+
+    assertEquals(johnDoe.getAddresses()[0].getUnstructuredAddress(),
+        result.getJSONArray("addresses").getJSONObject(0)
+            .getString("unstructuredAddress"));
+
+    JSONArray phoneArray = result.getJSONArray("phoneNumbers");
+    assertEquals(3, phoneArray.length());
+
+    for (int i = 0; i < johnDoe.getPhoneNumbers().length; i++) {
+      Phone expectedPhone = johnDoe.getPhoneNumbers()[i];
+      JSONObject actualPhone = phoneArray.getJSONObject(i);
+      assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
+      assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
+    }
+
+    JSONArray emailArray = result.getJSONArray("emails");
+    assertEquals(2, emailArray.length());
+
+    for (int i = 0; i < johnDoe.getEmails().length; i++) {
+      Email expectedEmail = johnDoe.getEmails()[i];
+      JSONObject actualEmail = emailArray.getJSONObject(i);
+      assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
+      assertEquals(expectedEmail.getAddress(),
+          actualEmail.getString("address"));
+    }
+  }
+
+  public void testActivityToJson() throws Exception {
+    JSONObject result = activity.toJson();
+    assertEquals(activity.getUserId(), result.getString("userId"));
+    assertEquals(activity.getAppId(), result.getString("appId"));
+    assertEquals(activity.getId(), result.getString("id"));
+
+    JSONArray mediaItemsArray = result.getJSONArray("mediaItems");
+    assertEquals(1, mediaItemsArray.length());
+
+    MediaItem expectedItem = activity.getMediaItems()[0];
+    JSONObject actualItem = mediaItemsArray.getJSONObject(0);
+
+    assertEquals(expectedItem.getUrl(), actualItem.getString("url"));
+    assertEquals(expectedItem.getMimeType(), actualItem.getString("mimeType"));
+    assertEquals(expectedItem.getType().toString(),
+        actualItem.getString("type"));
   }
 }