Author: doll
Date: Wed Jun 18 17:11:09 2008
New Revision: 669338

URL: http://svn.apache.org/viewvc?rev=669338&view=rev
Log:
Added some end to end tests for people pagination and updates for activities 
and app data. 


Modified:
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.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

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=669338&r1=669337&r2=669338&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 Jun 18 17:11:09 2008
@@ -46,6 +46,7 @@
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
 
 import java.net.URI;
 import java.util.ArrayList;
@@ -78,6 +79,7 @@
     bind(SecurityTokenDecoder.class).to(BasicSecurityTokenDecoder.class);
   }
 
+  @Singleton
   public static class MockXmlStateFileFetcher extends XmlStateFileFetcher {
     public static final Person johnDoe;
     public static final Person janeDoe;

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java?rev=669338&r1=669337&r2=669338&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
 Wed Jun 18 17:11:09 2008
@@ -97,6 +97,7 @@
     EasyMock.replay(req, res);
     servlet.service(req, res);
     EasyMock.verify(req, res);
+    EasyMock.reset(req, res);
 
     writer.flush();
     return outputStream.toString();

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=669338&r1=669337&r2=669338&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
 Wed Jun 18 17:11:09 2008
@@ -22,8 +22,13 @@
 
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.json.JSONArray;
 import org.junit.Test;
 
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
 public class RestfulJsonActivityTest extends AbstractLargeRestfulTests {
 
   /**
@@ -113,6 +118,28 @@
     assertEquals(activity.getBody(), result.getString("body"));
   }
 
+  @Test
+  public void testCreateActivity() throws Exception {
+    Map<String, String> extraParams = Maps.newHashMap();
+    extraParams.put("entry", "{title : 'hi mom!', body : 'and dad.'}");
+    getJsonResponse("/activities/john.doe/@self", "POST", extraParams);
+
+     String resp = getJsonResponse("/activities/john.doe/@self", "GET");
+    JSONObject result = getJson(resp);
+
+    assertEquals(2, result.getInt("totalResults"));
+    assertEquals(0, result.getInt("startIndex"));
+
+    JSONArray activities = result.getJSONArray("entry");
+    int newActivityIndex = 0;
+    if (activities.getJSONObject(0).has("id")) {
+      newActivityIndex = 1;
+    }
+
+    JSONObject jsonActivity = activities.getJSONObject(newActivityIndex);
+    assertEquals("hi mom!", jsonActivity.getString("title"));
+    assertEquals("and dad.", jsonActivity.getString("body"));
+  }
+
   // TODO: Add tests for the fields= parameter
-  // TODO: Add tests for post
 }
\ No newline at end of file

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=669338&r1=669337&r2=669338&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
 Wed Jun 18 17:11:09 2008
@@ -143,7 +143,51 @@
     assertEquals(0, johnsEntries.length());
   }
 
+  @Test
+  public void testDeleteAppData() throws Exception {
+    assertCount("0");
+
+    // With the wrong field
+    Map<String, String> extraParams = Maps.newHashMap();
+    extraParams.put("fields", "peabody");
+    getJsonResponse("/appdata/john.doe/@self/app", "DELETE", extraParams);
+
+    assertCount("0");
+
+    extraParams.put("fields", "count");
+    getJsonResponse("/appdata/john.doe/@self/app", "DELETE", extraParams);
+
+    assertCount(null);
+  }
+
+  @Test
+  public void testUpdateAppData() throws Exception {
+    assertCount("0");
+
+    Map<String, String> extraParams = Maps.newHashMap();
+    extraParams.put("fields", "count");
+    extraParams.put("entry", "{count : 5}");
+    getJsonResponse("/appdata/john.doe/@self/app", "POST", extraParams);
+
+    assertCount("5");
+  }
+
+  private void assertCount(String expectedCount) throws Exception {
+    String resp = getJsonResponse("/appdata/john.doe/@self/app", "GET");
+    JSONObject data = getJson(resp).getJSONObject("entry");
+    assertEquals(1, data.length());
+
+    JSONObject johnsEntries = data.getJSONObject(
+        MockXmlStateFileFetcher.johnDoe.getId());
+
+    if (expectedCount != null) {
+      assertEquals(1, johnsEntries.length());
+      assertEquals(expectedCount, johnsEntries.getString("count"));
+    } else {
+      assertEquals(0, johnsEntries.length());
+    }
+  }
+
   // TODO: support for indexBy??
-  // TODO: support for post and delete
 
 }
\ No newline at end of file

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=669338&r1=669337&r2=669338&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
 Wed Jun 18 17:11:09 2008
@@ -281,14 +281,10 @@
 
   /**
    * Expected response for a list of people in json:
-   * TODO: Fix the question marks...
    *
    * {
-   *  "author" : "<???>",
-   *  "link" : {"rel" : "next", "href" : "<???>"},
    *  "totalResults" : 2,
    *  "startIndex" : 0
-   *  "itemsPerPage" : 10
    *  "entry" : [
    *     {<jane doe>}, // layed out like above
    *     {<simple doe>},
@@ -298,12 +294,12 @@
    * @throws Exception if test encounters an error
    */
   @Test
-  public void testGetPeopleJson() throws Exception {
+  public void testGetPeople() throws Exception {
     Map<String, String> extraParams = Maps.newHashMap();
-    extraParams.put("orderBy", null);
+    extraParams.put("orderBy", "name");
     extraParams.put("filterBy", null);
     extraParams.put("startIndex", null);
-    extraParams.put("count", null);
+    extraParams.put("count", "20");
     extraParams.put("fields", null);
 
     // Currently, for Shindig @all == @friends
@@ -312,27 +308,50 @@
 
     assertEquals(2, result.getInt("totalResults"));
     assertEquals(0, result.getInt("startIndex"));
-    // TODO: Paging not handled yet
-    // assertEquals(10, result.getInt("itemsPerPage"));
 
     JSONArray people = result.getJSONArray("entry");
 
-    for (int i = 0; i < people.length(); i++) {
-      JSONObject person = people.getJSONObject(i);
-      String id = person.getString("id");
-      String name = person.getJSONObject("name").getString("unstructured");
-
-      // TODO: Clean this after we support sorting
-      if (id.equals("jane.doe")) {
-        assertEquals("Jane Doe", name);
-      } else {
-        assertEquals("simple.doe", id);
-        assertEquals("Simple Doe", name);
-      }
-    }
+    // The users should be in alphabetical order
+    assertPerson(people.getJSONObject(0), "jane.doe", "Jane Doe");
+    assertPerson(people.getJSONObject(1), "simple.doe", "Simple Doe");
+  }
+
+  @Test
+  public void testGetPeoplePagination() throws Exception {
+    Map<String, String> extraParams = Maps.newHashMap();
+    extraParams.put("orderBy", "name");
+    extraParams.put("filterBy", null);
+    extraParams.put("startIndex", "0");
+    extraParams.put("count", "1");
+    extraParams.put("fields", null);
+
+    String resp = getJsonResponse("/people/john.doe/@friends", "GET", 
extraParams);
+    JSONObject result = getJson(resp);
+
+    assertEquals(2, result.getInt("totalResults"));
+    assertEquals(0, result.getInt("startIndex"));
+
+    JSONArray people = result.getJSONArray("entry");
+    assertPerson(people.getJSONObject(0), "jane.doe", "Jane 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(1, result.getInt("startIndex"));
+
+    people = result.getJSONArray("entry");
+    assertPerson(people.getJSONObject(0), "simple.doe", "Simple Doe");
+  }
+
+  private void assertPerson(JSONObject person, String expectedId, String 
expectedName)
+      throws Exception {
+    assertEquals(expectedId, person.getString("id"));
+    assertEquals(expectedName, 
person.getJSONObject("name").getString("unstructured"));
   }
 
-  // TODO: Add tests for paging, sorting
   // TODO: Add tests for fields parameter
   // TODO: Add tests for networkDistance
 }
\ No newline at end of file


Reply via email to