You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/05/20 20:27:00 UTC

svn commit: r658376 - /incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java

Author: doll
Date: Tue May 20 11:27:00 2008
New Revision: 658376

URL: http://svn.apache.org/viewvc?rev=658376&view=rev
Log:
Add some more restful json data tests.


Modified:
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java?rev=658376&r1=658375&r2=658376&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTest.java Tue May 20 11:27:00 2008
@@ -17,30 +17,56 @@
  */
 package org.apache.shindig.social.abdera;
 
+import org.apache.shindig.social.SocialApiTestsGuiceModule;
+import org.apache.shindig.social.ResponseItem;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.Map;
+
 
 public class RestfulJsonDataTest extends AbstractLargeRestfulTests {
+  private Map<String, Map<String, String>> data;
+  private Map<String, String> janeData;
+  private Map<String, String> simpleData;
+  private Map<String, String> johnData;
 
   @Before
   public void setUp() throws Exception {
     super.setUp();
+
+    data = new HashMap<String, Map<String, String>>();
+    janeData = new HashMap<String, String>();
+    janeData.put("count", "5");
+
+    simpleData = new HashMap<String, String>();
+    simpleData.put("count", "7");
+
+    johnData = new HashMap<String, String>();
+    johnData.put("count", "0");
   }
 
   @After
   public void tearDown() throws Exception {
+    SocialApiTestsGuiceModule.MockDataService.setPersonData(null);
     super.tearDown();
   }
 
+  private void updateAppData() {
+    SocialApiTestsGuiceModule.MockDataService.setPersonData(
+        new ResponseItem<Map<String, Map<String, String>>>(data));
+  }
+
   /**
    * Expected response for app data in json:
    *
    * {
    *  "entry" : {
-   *    "jane.doe" : {"count" : 5},
-   *    "simple.doe" : {"count" : 7},
+   *    "jane.doe" : {"count" : "5"},
+   *    "simple.doe" : {"count" : "7"},
    *  }
    * }
    *
@@ -48,8 +74,12 @@
    */
   @Test
   public void testGetFriendsAppDataJson() throws Exception {
+    data.put("jane.doe", janeData);
+    data.put("simple.doe", simpleData);
+    updateAppData();
+
     // app id is mocked out
-    resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
+    resp = client.get(BASEURL + "/appdata/john.doe/@friends/app?fields=count");
     // checkForGoodJsonResponse(resp);
     // JSONObject result = getJson(resp);
   }
@@ -59,22 +89,70 @@
    *
    * {
    *  "entry" : {
-   *    "john.doe" : {"count" : 0},
+   *    "john.doe" : {"count" : "0"},
    *  }
    * }
    *
    * @throws Exception if test encounters an error
    */
-  @Test
+   // TODO: Shindig currently throws an exception when no keys are specified
+   // @Test
   public void testGetSelfAppDataJson() throws Exception {
+    data.put("john.doe", johnData);
+    updateAppData();
+
+    // app id is mocked out
+    resp = client.get(BASEURL + "/appdata/john.doe/@self/app");
+    // checkForGoodJsonResponse(resp);
+    // JSONObject result = getJson(resp);
+  }
+
+  /**
+   * Expected response for app data in json:
+   *
+   * {
+   *  "entry" : {
+   *    "john.doe" : {"count" : "0"},
+   *  }
+   * }
+   *
+   * @throws Exception if test encounters an error
+   */
+  @Test
+  public void testGetSelfAppDataJsonWithKey() throws Exception {
+    data.put("john.doe", johnData);
+    updateAppData();
+
+    // app id is mocked out
+    resp = client.get(BASEURL + "/appdata/john.doe/@self/app?fields=count");
+    // checkForGoodJsonResponse(resp);
+    // JSONObject result = getJson(resp);
+  }
+
+  /**
+   * Expected response for app data in json with non-existant key:
+   * TODO: Double check this output with the spec
+   *
+   * {
+   *  "entry" : {
+   *    "john.doe" : {},
+   *  }
+   * }
+   *
+   * @throws Exception if test encounters an error
+   */
+  @Test
+  public void testGetSelfAppDataJsonWithoutKeys() throws Exception {
+    data.put("john.doe", johnData);
+    updateAppData();
+
     // app id is mocked out
-    resp = client.get(BASEURL + "/appdata/john.doe/@self/appId");
+    resp = client.get(BASEURL + "/appdata/john.doe/@self/app?fields=peabody");
     // checkForGoodJsonResponse(resp);
     // JSONObject result = getJson(resp);
   }
 
   // TODO: support for indexBy??
-  // TODO: support for fields parameter
   // TODO: support for post and delete
 
 }