Author: doll
Date: Wed May 21 00:54:41 2008
New Revision: 658578

URL: http://svn.apache.org/viewvc?rev=658578&view=rev
Log:
SHINDIG-289 
Patch from David Primmer. Updates the ActivityAdapter to support feeds as well 
as entires. Adds tests.


Modified:
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/AbstractSocialEntityCollectionAdapter.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/ActivityAdapter.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.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/abdera/RestfulAtomActivityTest.java

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/AbstractSocialEntityCollectionAdapter.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/AbstractSocialEntityCollectionAdapter.java?rev=658578&r1=658577&r2=658578&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/AbstractSocialEntityCollectionAdapter.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/AbstractSocialEntityCollectionAdapter.java
 Wed May 21 00:54:41 2008
@@ -17,9 +17,13 @@
  */
 package org.apache.shindig.social.abdera;
 
+import org.apache.shindig.common.BasicSecurityToken;
 import org.apache.shindig.common.SecurityToken;
 import org.apache.shindig.common.SecurityTokenDecoder;
 import org.apache.shindig.common.SecurityTokenException;
+import org.apache.shindig.common.crypto.BlobCrypterException;
+import org.apache.shindig.social.opensocial.PeopleService;
+import org.apache.shindig.social.opensocial.model.IdSpec;
 import org.apache.shindig.social.opensocial.util.BeanJsonConverter;
 import org.apache.shindig.social.opensocial.util.BeanXmlConverter;
 
@@ -30,26 +34,37 @@
 import org.apache.abdera.i18n.templates.Route;
 import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
 import org.apache.abdera.model.Person;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
 import org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter;
 
+import org.json.JSONException;
+
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 
 /**
  * By extending this class it becomes easy to build Collections which are 
backed
  * by a set of Social entities - such as a person or activity.
  *
+ * This base class also has the data connection to the People service and some
+ * helper methods for getting social graph information.
+ *
  * @param <T> The entity that this is backed by.
  */
 
 public abstract class AbstractSocialEntityCollectionAdapter<T> extends
     AbstractEntityCollectionAdapter<T> {
+  private static Logger logger = Logger
+      .getLogger(AbstractEntityCollectionAdapter.class.getName());
 
+  protected PeopleService peopleService;
   protected String ID_PREFIX;
   protected Factory factory;
   private BeanXmlConverter beanXmlConverter;
@@ -75,6 +90,18 @@
     }
   }
 
+  /**
+   * All the adapters need access to the PeopleService, which has the basic
+   * social graph information. Each service adapter will also add an instance
+   * of their respective data service.
+   * TODO: Also include groups service in base?
+   * @param peopleService The people service
+   */
+  @Inject
+  public void setPeopleService(PeopleService peopleService) {
+    this.peopleService = peopleService;
+  }
+
   @Inject
   public void setConverters(BeanXmlConverter beanXmlConverter,
       BeanJsonConverter beanJsonConverter) {
@@ -88,6 +115,12 @@
     this.securityTokenDecoder = securityTokenDecoder;
   }
 
+  /**
+   * Get the token from the "st" url parameter or throw an exception.
+   * @param request Abdera's RequestContext
+   * @return SecurityToken
+   * @throws SecurityTokenException If the token is invalid
+   */
   protected SecurityToken getSecurityToken(RequestContext request)
       throws SecurityTokenException {
     String token = request.getParameter("st");
@@ -98,13 +131,56 @@
   }
 
   /**
-   * returns the format (json or atom) from the RequestContext obj created by
-   * Abdera from the URL request.
+   * This alternate version of getSecurityToken adds the ability to generate a
+   * new security token based on some viewerid supplied.
    *
-   * @param request the RequestContext obj from Abdera
-   * @return the format and default to Format.JSON
+   * @param request Abdera's RequestContext
+   * @param viewerId The viewer ID to fake.
+   * @return A call to the parent getSecurityToken which returns a 
SecurityToken
+   */
+  protected SecurityToken getSecurityToken(RequestContext request,
+      final String viewerId) {
+    try {
+      return getSecurityToken(request);
+    } catch (SecurityTokenException se) {
+      // For now, if there's no st param, we'll mock one up.
+      try {
+        return new BasicSecurityToken("o", viewerId, "a", "d", "u", "m");
+      } catch (BlobCrypterException be) {
+        be.printStackTrace();
+        return null;
+      }
+    }
+  }
+
+  /**
+   * Gets the IDs of friends for the given user.
+   *
+   * @param request Abdera's RequestContext
+   * @param uid The User ID to get friends for.
+   * @return A list of ID strings.
+   */
+  protected List<String> getFriendIds(RequestContext request, String uid) {
+    SecurityToken token = getSecurityToken(request, uid);
+    IdSpec idSpec = new IdSpec(null, IdSpec.Type.VIEWER_FRIENDS);
+    try {
+      return peopleService.getIds(idSpec, token);
+    } catch (JSONException e) {
+      // TODO: Ignoring this for now. Eventually we can make the service apis
+      // fit the restful model better. For now, it is worth some hackiness to
+      // keep the interfaces stable.
+      return null;
+    }
+  }
+
+  /**
+   * Returns the format (jsoc or atom) from the RequestContext's URL 
parameters.
+   *
+   * @param request Abdera's RequestContext
+   * @return The format and default to Format.JSON.
    */
   private Format getFormatTypeFromRequest(RequestContext request) {
+    // TODO: should gracefully handle introspection if format param is missing.
     String format = request.getTarget().getParameter("format");
 
     if (format != null && format.equals(Format.ATOM.getDisplayValue())) {
@@ -125,6 +201,9 @@
   public String getFeedIriForEntry(RequestContext request,
       String resourceRouteVariable) {
     Map<String, Object> params = new HashMap<String, Object>();
+    // TODO: currently a bug in Abdera adds this param to the url when there 
are
+    // other parameters in the original request.
+    // fix is coming in https://issues.apache.org/jira/browse/ABDERA-162
     params.put(resourceRouteVariable, null);
     String uri = request.urlFor(getRoute(request).getName(), params);
     return request.getResolvedUri().resolve(uri).toString();
@@ -135,7 +214,7 @@
    * object. If it does not, it throws a NPE for now. It could also deal with a
    * Regex resolver
    *
-   * @param request the request
+   * @param request Abdera's RequestContext
    * @return The Route object that matched the request.
    */
   public Route getRoute(RequestContext request) {
@@ -171,28 +250,78 @@
   /**
    * Add the details to an entry.
    *
-   * @param request The request context
-   * @param e The entry
-   * @param feedIri The feed IRI
+   * @param request Abdera's RequestContext.
+   * @param entry The entry FOM object.
+   * @param feedIri The feed IRI that the entry came from.
    * @param entity The object that the entry is based on.
    */
   @Override
-  protected String addEntryDetails(RequestContext request, Entry e,
+  protected String addEntryDetails(RequestContext request, Entry entry,
       IRI feedIri, T entity) throws ResponseContextException {
-    String link = getLink(entity, feedIri, request);
+    addRequiredEntryDetails(request, entry, feedIri, entity);
+    addOptionalEntryDetails(request, entry, feedIri, entity);
+    return getLink(entity, feedIri, request);
+  }
 
-    e.addLink(link, "self", "application/atom+xml", null, null, 0);
-    e.setId(getId(entity));
-    e.setTitle(getTitle(entity));
-    e.setUpdated(getUpdated(entity));
-    e.setSummary(getSummary(entity));
+  /**
+   * This very similar to the superclass's addEntryDetails but modified to do a
+   * minimum of required fields.
+   *
+   * @param request Abdera's RequestContext.
+   * @param entry The entry FOM object.
+   * @param feedIri The feed IRI that the entry came from.
+   * @param entity The object that the entry is based on.
+   * @throws ResponseContextException If the authors can not be fetched
+   */
+  protected void addRequiredEntryDetails(RequestContext request, Entry entry,
+      IRI feedIri, T entity) throws ResponseContextException {
+    entry.setId(getId(entity));
+    entry.setTitle(getTitle(entity));
+    entry.setUpdated(getUpdated(entity));
+    entry.setSummary(getSummary(entity));
     List<Person> authors = getAuthors(entity, request);
     if (authors != null) {
       for (Person a : authors) {
-        e.addAuthor(a);
+        entry.addAuthor(a);
       }
     }
-    return link;
+  }
+
+  /**
+   * This is a good place for the subclass to do any special processing of the
+   * entry element to customize it beyond the basic atom fields like title and
+   * author.
+   *
+   * @param request Abdera's RequestContext.
+   * @param entry The entry FOM object.
+   * @param feedIri The feed IRI that the entry came from.
+   * @param entity The object that the entry is based on.
+   * @throws ResponseContextException If some entry data can not be fetched
+   */
+  protected void addOptionalEntryDetails(RequestContext request, Entry entry,
+      IRI feedIri, T entity) throws ResponseContextException {
+  }
+
+  /**
+   * Create the base feed for the requested collection.
+   *
+   * TODO: This method needs to be refactored to deal with hoisting and json.
+   *
+   * @param request Abdera's RequestContext
+   */
+  @Override
+  protected Feed createFeedBase(RequestContext request)
+      throws ResponseContextException {
+    Factory factory = request.getAbdera().getFactory();
+    Feed feed = factory.newFeed();
+    String link = getHref(request);
+    // TODO: this should create links that are aware of the request format.
+    feed.addLink(link, "self", "application/atom+xml", null, null, 0);
+    feed.setId(getId(request));
+    feed.setTitle(getTitle(request));
+    feed.addAuthor(getAuthor(request));
+    feed.setUpdated(new Date());
+    return feed;
   }
 
   /**
@@ -214,8 +343,4 @@
     return null;
   }
 
-  @Override
-  public ResponseContext getFeed(RequestContext request) {
-    return null;
-  }
 }

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/ActivityAdapter.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/ActivityAdapter.java?rev=658578&r1=658577&r2=658578&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/ActivityAdapter.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/ActivityAdapter.java
 Wed May 21 00:54:41 2008
@@ -17,37 +17,50 @@
  */
 package org.apache.shindig.social.abdera;
 
-import org.apache.shindig.common.BasicSecurityToken;
 import org.apache.shindig.common.SecurityToken;
-import org.apache.shindig.common.SecurityTokenException;
-import org.apache.shindig.common.crypto.BlobCrypterException;
 import org.apache.shindig.social.opensocial.ActivitiesService;
 import org.apache.shindig.social.opensocial.model.Activity;
 
 import com.google.inject.Inject;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Person;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.logging.Logger;
 
 /**
  * This Collection is backed by a set of Activity entities
  */
 public class ActivityAdapter extends
     AbstractSocialEntityCollectionAdapter<Activity> {
+  private static Logger logger = Logger
+      .getLogger(ActivityAdapter.class.getName());
 
   private ActivitiesService activitiesService;
 
+  /**
+   * The Adapter needs Activities, People and Groups.
+   * The PeopleService comes from the base class. Groups is unimplemented.
+   * @param activitiesService The activities service
+   */
   @Inject
   public ActivityAdapter(ActivitiesService activitiesService) {
     this.activitiesService = activitiesService;
   }
 
+  /**
+   * Query the underlying model for an Activity object.
+   *
+   * @param request RequestContext
+   * @return An Activity entity.
+   */
   @Override
   public Activity getEntry(String resourceName, RequestContext request)
       throws ResponseContextException {
@@ -57,24 +70,14 @@
     return activitiesService.getActivity(uid, aid, authToken).getResponse();
   }
 
-  private SecurityToken getSecurityToken(RequestContext request,
-      final String viewerId) {
-    try {
-      return super.getSecurityToken(request);
-    } catch (SecurityTokenException se) {
-      // For now, if there's no st param, we'll mock one up.
-      try {
-        return new BasicSecurityToken("o", viewerId, "a", "d", "u", "m");
-      } catch (BlobCrypterException be) {
-        be.printStackTrace();
-        return null;
-      }
-    }
-  }
-
+  /**
+   * atom:entry/atom:id aliases the "id" field. In the Atom format, it is
+   * translated into the required URI data type by prepending "urn:guid:" to 
the
+   * OpenSocial ID string.
+   */
   @Override
   public String getId(Activity activityObj) throws ResponseContextException {
-    return activityObj.getId();
+    return ID_PREFIX + activityObj.getId();
   }
 
   // hoisting rule: atom:entry/atom:author/atom:uri aliases "user_id"
@@ -86,6 +89,9 @@
     return Arrays.asList(author);
   }
 
+  /**
+   * Get the name of the entry resource (used to construct links)
+   */
   @Override
   public String getName(Activity activityObj) throws ResponseContextException {
     return activityObj.getId();
@@ -97,6 +103,8 @@
     return activityObj.getTitle();
   }
 
+  // hoisting rule: atom:entry/atom:updated aliases POSTED_TIME for Activity
+  // or the generation time if no better information is available.
   @Override
   public Date getUpdated(Activity activityObj) throws ResponseContextException 
{
     return activityObj.getUpdated();
@@ -109,27 +117,88 @@
     return activityObj.getBody();
   }
 
+  // hoisting rule: atom:entry/atom:published aliases POSTED_TIME
+  public Long getPublished(Activity activityObj)
+      throws ResponseContextException {
+    // TODO: Add published element to the entry object.
+    // TODO: Switch based on output format from RFC date to epoch-based.
+    // POSTED_TIME is seconds since the epoch.
+    return activityObj.getPostedTime();
+  }
+
+  /**
+   * This is where some activity entry format customization happens.
+   *
+   * @param request Abdera's RequestContext.
+   * @param entry The entry FOM object.
+   * @param feedIri The feed IRI that the entry came from.
+   * @param activityObj The object that the entry is based on.
+   * @throws ResponseContextException
+   */
+  protected void addOptionalEntryDetails(RequestContext request, Entry entry,
+      IRI feedIri, Activity activityObj) throws ResponseContextException {
+    String link = getLink(activityObj, feedIri, request);
+    // TODO: this should create links that are aware of the request format.
+    entry.addLink(link, "self", "application/atom+xml", null, null, 0);
+
+    // TODO:
+    // atom:entry/atom:generator/atom:uri aliases "app_id"
+    // atom:entry/atom:published aliases POSTED_TIME
+  }
+
   /**
    * Unimplemented Data methods
    */
   @Override
   public void deleteEntry(String resourceName, RequestContext request)
       throws ResponseContextException {
-    // TODO Auto-generated method stub
+    // TODO: Auto-generated method stub
   }
 
+  /**
+   * Query the underlying model for the list activity objects.
+   *
+   * There is some logic to handle some request dispatching here since this
+   * adapter handles the getFeed method for three Activity collections:
+   * ACTIVITIES_OF_USER, ACTIVITIES_OF_FRIENDS_OF_USER and
+   * ACTIVITIES_OF_GROUP_OF_USER
+   *
+   * @param request RequestContext
+   * @return A List Activity entities.
+   */
   @Override
   public Iterable<Activity> getEntries(RequestContext request)
       throws ResponseContextException {
-    // TODO Auto-generated method stub
-    return null;
+    String uid = request.getTarget().getParameter("uid");
+    String routeName = getRoute(request).getName();
+    List<String> ids = new ArrayList<String>();
+    switch (RequestUrlTemplate.getValue(routeName)) {
+      case ACTIVITIES_OF_USER :
+        ids.add(uid);
+        break;
+      case ACTIVITIES_OF_FRIENDS_OF_USER :
+        // TODO: Change activities service to handle the friend lookup itself
+        ids = getFriendIds(request, uid);
+        break;
+      case ACTIVITIES_OF_GROUP_OF_USER :
+        // TODO: add something like ids = getGroupIds(request, gid);
+        String gid = request.getTarget().getParameter("gid");
+        break;
+      default:
+        // TODO: Clean this code up so we don't need this check
+        throw new UnsupportedOperationException(
+            "The activity adpater was reached with an unsupported url");
+    }
+
+    SecurityToken authToken = getSecurityToken(request, uid);
+    return activitiesService.getActivities(ids, authToken).getResponse();
   }
 
   @Override
   public Activity postEntry(String title, IRI id, String summary, Date updated,
       List<Person> authors, Content content, RequestContext request)
       throws ResponseContextException {
-    // TODO Auto-generated method stub
+    // TODO: Implement
     return null;
   }
 
@@ -137,7 +206,7 @@
   public void putEntry(Activity entry, String title, Date updated,
       List<Person> authors, String summary, Content content,
       RequestContext request) throws ResponseContextException {
-    // TODO Auto-generated method stub
+    // TODO: Implement
   }
 
   /**
@@ -147,8 +216,7 @@
   /**
    * The collection-level URL. Calls the getFeedIriForEntry and nulls "aid".
    *
-   * @param request
-   *          RequestContext
+   * @param request RequestContext
    * @return The absolute request URI (includes server name, port, etc) URL
    */
   @Override
@@ -158,12 +226,16 @@
 
   @Override
   public String getId(RequestContext request) {
-    // TODO what really to return for the feed ID? Better data will help.
+    // TODO: what really to return for the feed ID? Better data will help.
     return getHref(request);
   }
 
+  // hoisting rule: atom:entry/atom:source/atom:[EMAIL PROTECTED]"self" aliases
+  // "stream_url"
+  // TODO: "stream_url"
+
   // hoisting rule: atom:entry/atom:source/atom:title aliases "stream_title"
-  // TODO stream_title can't be accessed right here....
+  // TODO: stream_title can't be accessed right here....
   public String getTitle(RequestContext request) {
     return getRoute(request).getName();
   }
@@ -174,4 +246,6 @@
       throws ResponseContextException {
     return request.getTarget().getParameter("uid");
   }
+
+
 }

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java?rev=658578&r1=658577&r2=658578&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
 Wed May 21 00:54:41 2008
@@ -69,9 +69,9 @@
 
          // Activities
         .addRoute(RequestUrlTemplate.ACTIVITIES_OF_USER,
-            TargetType.TYPE_COLLECTION, activitiesAdapter)
+            TargetType.TYPE_COLLECTION, activityAdapter)
         .addRoute(RequestUrlTemplate.ACTIVITIES_OF_FRIENDS_OF_USER,
-            TargetType.TYPE_COLLECTION, activitiesAdapter)
+            TargetType.TYPE_COLLECTION, activityAdapter)
         .addRoute(RequestUrlTemplate.ACTIVITIES_OF_GROUP_OF_USER,
             TargetType.TYPE_COLLECTION, null)
         .addRoute(RequestUrlTemplate.ACTIVITY_OF_USER,

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=658578&r1=658577&r2=658578&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
 Wed May 21 00:54:41 2008
@@ -18,6 +18,8 @@
  */
 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;
@@ -33,7 +35,6 @@
 import org.apache.shindig.social.opensocial.model.Person;
 import org.apache.shindig.social.opensocial.model.Phone;
 
-import com.google.inject.AbstractModule;
 import org.json.JSONException;
 
 import java.util.ArrayList;
@@ -41,11 +42,14 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Logger;
 
 /**
  * Provides social api component injection for all large tests
  */
 public class SocialApiTestsGuiceModule extends AbstractModule {
+  private static Logger logger =
+    Logger.getLogger(SocialApiTestsGuiceModule.class.getName());
 
   @Override
   protected void configure() {

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=658578&r1=658577&r2=658578&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
 Wed May 21 00:54:41 2008
@@ -17,27 +17,78 @@
  */
 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 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();
   }
 
   @Test
-  public void testGetActivityAtom() throws Exception {
-    resp = client.get(BASEURL + "/activities/john.doe/@all?format=atom");
-    // checkForGoodAtomResponse(resp);
+  public void testGetActivityOfUser() throws Exception {
+    resp = client.get(BASEURL + "/activities/john.doe/@self/1?format=atom");
+    checkForGoodAtomResponse(resp);
+    Document<Entry> doc = resp.getDocument();
+    Entry entry = doc.getRoot();
+    assertEquals("urn:guid:" + activity.getId(), entry.getId().toString());
+    assertEquals("urn:guid:" + activity.getUserId(), entry.getAuthor().getUri()
+        .toString());
+    assertEquals(activity.getTitle(), entry.getTitle());
+    assertEquals(activity.getBody(), entry.getSummary());
+    // TODO Test the content element and more top level elements.
+    resp.release();
   }
 
+  @Test
+  public void testGetActivitiesOfUser() throws Exception {
+    resp = client.get(BASEURL + "/activities/john.doe/@self?format=atom");
+    checkForGoodAtomResponse(resp);
+    // TODO Test all elements.
+    resp.release();
+  }
+
+  @Test
+  public void testGetActivitiesOfFriendsOfUser() throws Exception {
+    resp = client.get(BASEURL + "/activities/john.doe/@friends?format=atom");
+    checkForGoodAtomResponse(resp);
+    // TODO Social graph seems to make everyone friends at this point.
+    // TODO Test all elements.
+    resp.release();
+  }
 }


Reply via email to