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/06/13 00:04:26 UTC

svn commit: r667259 - in /incubator/shindig/trunk/java/social-api/src: main/java/org/apache/shindig/social/dataservice/ test/java/org/apache/shindig/social/dataservice/

Author: doll
Date: Thu Jun 12 15:04:25 2008
New Revision: 667259

URL: http://svn.apache.org/viewvc?rev=667259&view=rev
Log:
More tests for the new dataservice package. It now has 100% unit test coverage. Still need to add some end to end tests. 


Added:
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataCollectionTest.java
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/RestfulCollectionTest.java
Modified:
    incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataRequestHandler.java
    incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataServiceServlet.java
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataRequestHandlerTest.java
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataServiceServletTest.java

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataRequestHandler.java?rev=667259&r1=667258&r2=667259&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataRequestHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataRequestHandler.java Thu Jun 12 15:04:25 2008
@@ -30,6 +30,8 @@
 import java.io.PrintWriter;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
+
 public abstract class DataRequestHandler {
   protected BeanJsonConverter converter;
 
@@ -41,7 +43,7 @@
   public void handleMethod(String httpMethod, HttpServletRequest servletRequest,
       HttpServletResponse servletResponse, SecurityToken token)
       throws IOException {
-    if (httpMethod == null || httpMethod.length() == 0) {
+    if (StringUtils.isBlank(httpMethod)) {
       throw new IllegalArgumentException("Unserviced Http method type");
     }
     ResponseItem responseItem;
@@ -53,24 +55,17 @@
       responseItem = handlePut(servletRequest, token);
     } else if (httpMethod.equals("DELETE")) {
       responseItem = handleDelete(servletRequest, token);
-    } else if (httpMethod.equals("HEAD")) {
-      responseItem = handleHead(servletRequest);
     } else {
       throw new IllegalArgumentException("Unserviced Http method type");
     }
     if (responseItem.getError() == null) {
       PrintWriter writer = servletResponse.getWriter();
-      writer.write(converter.convertToJson(
-          responseItem.getResponse()).toString());
+      writer.write(converter.convertToJson(responseItem.getResponse()).toString());
     } else {
       // throw an error
     }
   }
 
-  ResponseItem handleHead(HttpServletRequest servletRequest) {
-    throw new RuntimeException("Not Implemented");
-  }
-
   abstract ResponseItem handleDelete(HttpServletRequest servletRequest,
       SecurityToken token);
 
@@ -87,7 +82,7 @@
     return getQueryPath(servletRequest).split("/");
   }
 
-  private String getQueryPath(HttpServletRequest servletRequest) {
+  /*package-protected*/ String getQueryPath(HttpServletRequest servletRequest) {
     String pathInfo = servletRequest.getPathInfo();
     int index = pathInfo.indexOf('/', 1);
     return pathInfo.substring(index + 1);

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataServiceServlet.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataServiceServlet.java?rev=667259&r1=667258&r2=667259&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataServiceServlet.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/DataServiceServlet.java Thu Jun 12 15:04:25 2008
@@ -30,6 +30,8 @@
 import java.util.Map;
 import java.util.logging.Logger;
 
+import org.apache.commons.lang.StringUtils;
+
 public class DataServiceServlet extends InjectedServlet {
 
   public static enum GroupId {
@@ -105,7 +107,7 @@
     String route = getRouteFromParameter(servletRequest.getPathInfo());
     DataRequestHandler handler = handlers.get(route);
     if (handler == null) {
-      throw new RuntimeException("No handler for route: "+route);
+      throw new RuntimeException("No handler for route: " + route);
     }
 
     String method = getHttpMethodFromParameter(servletRequest.getMethod(),
@@ -123,7 +125,7 @@
 
   /*package-protected*/ String getHttpMethodFromParameter(String method,
       String overrideParameter) {
-    if (overrideParameter != null && overrideParameter.length() != 0) {
+    if (!StringUtils.isBlank(overrideParameter)) {
       return overrideParameter;
     } else {
       return method;

Added: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataCollectionTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataCollectionTest.java?rev=667259&view=auto
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataCollectionTest.java (added)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataCollectionTest.java Thu Jun 12 15:04:25 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.dataservice;
+
+import com.google.common.collect.Maps;
+import junit.framework.TestCase;
+
+import java.util.Map;
+
+public class DataCollectionTest extends TestCase {
+
+  public void testBasicMethods() throws Exception {
+    Map<String, Map<String,String>> entry = Maps.newHashMap();
+    DataCollection collection = new DataCollection(entry);
+    assertEquals(entry, collection.getEntry());
+
+    Map<String, Map<String, String>> newEntry = Maps.newHashMap();
+    Map<String, String> value = Maps.newHashMap();
+    value.put("knock knock", "who's there?");
+    value.put("banana", "banana who?");
+    value.put("banana!", "banana who?");
+    value.put("orange!", "?");
+    newEntry.put("orange you glad I didn't type banana", value);
+    collection.setEntry(newEntry);
+    assertEquals(newEntry, collection.getEntry());
+  }
+
+}
\ No newline at end of file

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataRequestHandlerTest.java?rev=667259&r1=667258&r2=667259&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataRequestHandlerTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataRequestHandlerTest.java Thu Jun 12 15:04:25 2008
@@ -20,16 +20,28 @@
 import junit.framework.TestCase;
 import org.easymock.classextension.EasyMock;
 import org.apache.shindig.social.ResponseItem;
+import org.apache.shindig.social.ResponseError;
+import org.apache.shindig.social.opensocial.util.BeanJsonConverter;
 import org.apache.shindig.common.SecurityToken;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
-public class DataRequestHandlerTest extends TestCase {
+import com.google.common.collect.Lists;
 
-  public void testgetParamsFromRequest() throws Exception {
-    HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
-    EasyMock.expect(req.getPathInfo()).andReturn("/people/5/@self");
-    DataRequestHandler drh = new DataRequestHandler(null) {
+import java.io.PrintWriter;
+import java.io.IOException;
+
+public class DataRequestHandlerTest extends TestCase {
+  private DataRequestHandler drh;
+  private HttpServletRequest req;
+  private HttpServletResponse resp;
+
+  @Override
+  protected void setUp() throws Exception {
+    req = EasyMock.createMock(HttpServletRequest.class);
+    resp = EasyMock.createMock(HttpServletResponse.class);
+    drh = new DataRequestHandler(null) {
       ResponseItem handleDelete(HttpServletRequest servletRequest,
           SecurityToken token) {
         return null;
@@ -50,6 +62,100 @@
         return null;
       }
     };
+  }
+
+  public void testHandleMethodSuccess() throws Exception {
+    BeanJsonConverter converter = EasyMock.createMock(BeanJsonConverter.class);
+    drh = new DataRequestHandler(converter) {
+      ResponseItem handleDelete(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return new ResponseItem<String>("DELETE");
+      }
+
+      ResponseItem handlePut(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return new ResponseItem<String>("PUT");
+      }
+
+      ResponseItem handlePost(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return new ResponseItem<String>("POST");
+      }
+
+      ResponseItem handleGet(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return new ResponseItem<String>("GET");
+      }
+    };
+
+    verifyDispatchMethodCalled("DELETE", converter);
+    verifyDispatchMethodCalled("PUT", converter);
+    verifyDispatchMethodCalled("POST", converter);
+    verifyDispatchMethodCalled("GET", converter);
+  }
+
+  private void verifyDispatchMethodCalled(String methodName, BeanJsonConverter converter)
+      throws IOException {
+    String jsonObject = "my lovely json";
+    EasyMock.expect(converter.convertToJson(methodName)).andReturn(jsonObject);
+
+    PrintWriter writerMock = EasyMock.createMock(PrintWriter.class);
+    EasyMock.expect(resp.getWriter()).andReturn(writerMock);
+    writerMock.write(jsonObject);
+
+    EasyMock.replay(req, resp, converter, writerMock);
+    drh.handleMethod(methodName, req, resp, null);
+    EasyMock.verify(req, resp, converter, writerMock);
+    EasyMock.reset(req, resp, converter, writerMock);
+  }
+
+  public void testHandleMethodWithInvalidMethod() throws Exception {
+    verifyExceptionThrown(null);
+    verifyExceptionThrown("  ");
+    verifyExceptionThrown("HEAD");
+  }
+
+  public void testHandleMethodFailure() throws Exception {
+    drh = new DataRequestHandler(null) {
+      ResponseItem handleDelete(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return null;
+      }
+
+      ResponseItem handlePut(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return null;
+      }
+
+      ResponseItem handlePost(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return null;
+      }
+
+      ResponseItem handleGet(HttpServletRequest servletRequest,
+          SecurityToken token) {
+        return new ResponseItem<String>(ResponseError.INTERNAL_ERROR, "", "");
+      }
+    };
+
+    EasyMock.replay(req, resp);
+    drh.handleMethod("GET", req, resp, null);
+    // TODO: Assert the right actions occur based on the error type
+    EasyMock.verify(req, resp);
+  }
+
+  private void verifyExceptionThrown(String methodName) throws IOException {
+    try {
+      drh.handleMethod(methodName, req, resp, null);
+      fail("The invalid method " + methodName + " should throw an exception.");
+    } catch (IllegalArgumentException e) {
+      // Yea! We like exeptions
+      assertEquals("Unserviced Http method type", e.getMessage());
+    }
+  }
+
+  public void testGetParamsFromRequest() throws Exception {
+    EasyMock.expect(req.getPathInfo()).andReturn("/people/5/@self");
 
     EasyMock.replay(req);
     String[] params = drh.getParamsFromRequest(req);
@@ -57,4 +163,67 @@
     assertEquals("@self", params[1]);
     EasyMock.verify(req);
   }
+
+  public void testGetQueryPath() throws Exception {
+    EasyMock.expect(req.getPathInfo()).andReturn("/people/5/@self");
+
+    EasyMock.replay(req);
+    assertEquals("5/@self", drh.getQueryPath(req));
+    EasyMock.verify(req);
+  }
+
+  public void testGetEnumParam() throws Exception {
+    EasyMock.expect(req.getParameter("field")).andReturn("name");
+
+    EasyMock.replay(req);
+    assertEquals(PersonService.SortOrder.name, drh.getEnumParam(req, "field",
+        PersonService.SortOrder.topFriends, PersonService.SortOrder.class));
+    EasyMock.verify(req);
+
+    EasyMock.reset(req);
+
+    // Should return the default value if the parameter is null
+    EasyMock.expect(req.getParameter("field")).andReturn(null);
+
+    EasyMock.replay(req);
+    assertEquals(PersonService.SortOrder.topFriends, drh.getEnumParam(req, "field",
+        PersonService.SortOrder.topFriends, PersonService.SortOrder.class));
+    EasyMock.verify(req);
+  }
+
+  public void testGetIntegerParam() throws Exception {
+    EasyMock.expect(req.getParameter("field")).andReturn("5");
+
+    EasyMock.replay(req);
+    assertEquals(5, drh.getIntegerParam(req, "field", 100));
+    EasyMock.verify(req);
+
+    EasyMock.reset(req);
+
+    // Should return the default value if the parameter is null
+    EasyMock.expect(req.getParameter("field")).andReturn(null);
+
+    EasyMock.replay(req);
+    assertEquals(100, drh.getIntegerParam(req, "field", 100));
+    EasyMock.verify(req);
+  }
+
+  public void testGetListParam() throws Exception {
+    EasyMock.expect(req.getParameter("field")).andReturn("happy,sad,grumpy");
+
+    EasyMock.replay(req);
+    assertEquals(Lists.newArrayList("happy", "sad", "grumpy"),
+        drh.getListParam(req, "field", Lists.newArrayList("alpha")));
+    EasyMock.verify(req);
+
+    EasyMock.reset(req);
+
+    // Should return the default value if the parameter is null
+    EasyMock.expect(req.getParameter("field")).andReturn(null);
+
+    EasyMock.replay(req);
+    assertEquals(Lists.newArrayList("alpha"),
+        drh.getListParam(req, "field", Lists.newArrayList("alpha")));
+    EasyMock.verify(req);
+  }
 }
\ No newline at end of file

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataServiceServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataServiceServletTest.java?rev=667259&r1=667258&r2=667259&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataServiceServletTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/DataServiceServletTest.java Thu Jun 12 15:04:25 2008
@@ -19,30 +19,31 @@
 
 import org.apache.shindig.common.BasicSecurityTokenDecoder;
 import org.apache.shindig.common.SecurityTokenException;
+import org.apache.shindig.common.testing.FakeGadgetToken;
 
 import com.google.common.collect.Maps;
 import junit.framework.TestCase;
 import org.easymock.classextension.EasyMock;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.util.HashMap;
+import java.util.Map;
 
 public class DataServiceServletTest extends TestCase {
   private HttpServletRequest req;
   private HttpServletResponse res;
-  private DataServiceServlet servlet ;
+  private DataServiceServlet servlet;
   private PersonHandler peopleHandler;
   private ActivityHandler activityHandler;
   private AppDataHandler appDataHandler;
+  private BasicSecurityTokenDecoder tokenDecoder;
 
   protected void setUp() throws Exception {
     req = EasyMock.createMock(HttpServletRequest.class);
     res = EasyMock.createMock(HttpServletResponse.class);
 
-    HashMap<String, DataRequestHandler> handlers = Maps.newHashMap();
+    Map<String, DataRequestHandler> handlers = Maps.newHashMap();
     peopleHandler = EasyMock.createMock(PersonHandler.class);
     activityHandler = EasyMock.createMock(ActivityHandler.class);
     appDataHandler = EasyMock.createMock(AppDataHandler.class);
@@ -52,49 +53,118 @@
     handlers.put(DataServiceServlet.APPDATA_ROUTE, appDataHandler);
     servlet = new DataServiceServlet();
     servlet.setHandlers(handlers);
-    BasicSecurityTokenDecoder tokenDecoder
-        = EasyMock.createMock(BasicSecurityTokenDecoder.class);
 
+    tokenDecoder = EasyMock.createMock(BasicSecurityTokenDecoder.class);
     servlet.setSecurityTokenDecoder(tokenDecoder);
-
-    EasyMock.expect(req.getMethod()).andReturn("POST");
-    req.setCharacterEncoding("UTF-8");
   }
 
-
   public void testPeopleUriRecognition() throws Exception {
     verifyHandlerWasFoundForPathInfo("/"
-        + DataServiceServlet.PEOPLE_ROUTE+"/5/@self", peopleHandler);
+        + DataServiceServlet.PEOPLE_ROUTE + "/5/@self", peopleHandler);
   }
 
   public void testActivitiesUriRecognition() throws Exception {
     verifyHandlerWasFoundForPathInfo("/"
-        + DataServiceServlet.ACTIVITY_ROUTE +"/5/@self", activityHandler);
+        + DataServiceServlet.ACTIVITY_ROUTE + "/5/@self", activityHandler);
   }
 
   public void testAppDataUriRecognition() throws Exception {
     verifyHandlerWasFoundForPathInfo("/"
-        + DataServiceServlet.APPDATA_ROUTE+"/5/@self", appDataHandler);
+        + DataServiceServlet.APPDATA_ROUTE + "/5/@self", appDataHandler);
   }
 
   public void testMethodOverride() throws Exception {
-    EasyMock.expect(req.getHeader("X-HTTP-Method-Override")).andReturn("GET");
+    String route = "/" + DataServiceServlet.APPDATA_ROUTE;
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "POST", "GET", "GET");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "POST", "", "POST");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "POST", null, "POST");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "POST", "POST", "POST");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "GET", null, "GET");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "DELETE", null, "DELETE");
+    verifyHandlerWasFoundForPathInfo(route, appDataHandler, "PUT", null, "PUT");
+  }
+
+  private void verifyHandlerWasFoundForPathInfo(String peoplePathInfo, DataRequestHandler handler)
+      throws Exception {
+    String post = "POST";
+    verifyHandlerWasFoundForPathInfo(peoplePathInfo, handler, post, post, post);
   }
 
-  private void verifyHandlerWasFoundForPathInfo(String peoplePathInfo,
-      DataRequestHandler handler) throws ServletException, IOException,
-      SecurityTokenException {
-    EasyMock.expect(req.getPathInfo()).andReturn(peoplePathInfo);
-    EasyMock.expect(req.getMethod()).andReturn("POST");
-    EasyMock.expect(req.getParameter(
-        DataServiceServlet.X_HTTP_METHOD_OVERRIDE)).andReturn("POST");
-    String tokenStr = "owner:viewer:app:container.com:foo:bar";
-    EasyMock.expect(req.getParameter(
-        DataServiceServlet.SECURITY_TOKEN_PARAM)).andReturn(tokenStr);
-    handler.handleMethod("POST", req, res, null);
-    EasyMock.replay(req, res, handler);
+  private void verifyHandlerWasFoundForPathInfo(String pathInfo, DataRequestHandler handler,
+      String actualMethod, String overrideMethod, String expectedMethod) throws Exception {
+    req.setCharacterEncoding("UTF-8");
+
+    EasyMock.expect(req.getPathInfo()).andReturn(pathInfo);
+    EasyMock.expect(req.getMethod()).andReturn(actualMethod);
+    EasyMock.expect(req.getMethod()).andReturn(actualMethod);
+    EasyMock.expect(req.getParameter(DataServiceServlet.X_HTTP_METHOD_OVERRIDE)).andReturn(
+        overrideMethod);
+
+    String tokenString = "owner:viewer:app:container.com:foo:bar";
+    FakeGadgetToken token = new FakeGadgetToken();
+    EasyMock.expect(req.getParameter(DataServiceServlet.SECURITY_TOKEN_PARAM))
+        .andReturn(tokenString);
+    EasyMock.expect(tokenDecoder.createToken(tokenString)).andReturn(token);
+
+    handler.handleMethod(expectedMethod, req, res, token);
+
+    EasyMock.replay(req, res, handler, tokenDecoder);
     servlet.service(req, res);
-    EasyMock.verify(req, res, handler);
+    EasyMock.verify(req, res, handler, tokenDecoder);
+    EasyMock.reset(req, res, handler, tokenDecoder);
+  }
+
+  public void testInvalidRoute() throws Exception {
+    req.setCharacterEncoding("UTF-8");
+    EasyMock.expect(req.getPathInfo()).andReturn("/ahhh!");
+
+    EasyMock.replay(req);
+    try {
+      servlet.doPost(req, res);
+      fail("The route should not have found a valid handler.");
+    } catch (RuntimeException e) {
+      // Yea!
+      assertEquals("No handler for route: ahhh!", e.getMessage());
+    }
+    EasyMock.verify(req);
+  }
+
+  public void testSecurityTokenException() throws Exception {
+    req.setCharacterEncoding("UTF-8");
+    EasyMock.expect(req.getPathInfo()).andReturn("/" + DataServiceServlet.APPDATA_ROUTE);
+    EasyMock.expect(req.getMethod()).andReturn("POST");
+    EasyMock.expect(req.getParameter(DataServiceServlet.X_HTTP_METHOD_OVERRIDE)).andReturn("POST");
+
+    String tokenString = "owner:viewer:app:container.com:foo:bar";
+    EasyMock.expect(req.getParameter(DataServiceServlet.SECURITY_TOKEN_PARAM))
+        .andReturn(tokenString);
+    EasyMock.expect(tokenDecoder.createToken(tokenString)).andThrow(new SecurityTokenException(""));
+
+    EasyMock.replay(req, tokenDecoder);
+    try {
+      servlet.doPost(req, res);
+      fail("The route should have thrown an exception due to the invalid security token.");
+    } catch (RuntimeException e) {
+      // Yea!
+      // TODO: The impl being tested here is not finished. We should return a proper error
+      // instead of just throwing an exception.
+      assertEquals("Implement error return for bad security token.", e.getMessage());
+    }
+    EasyMock.verify(req, tokenDecoder);
+  }
+
+  public void testGetHttpMethodFromParameter() throws Exception {
+    String method = "POST";
+    assertEquals(method, servlet.getHttpMethodFromParameter(method, null));
+    assertEquals(method, servlet.getHttpMethodFromParameter(method, ""));
+    assertEquals(method, servlet.getHttpMethodFromParameter(method, "  "));
+    assertEquals("DELETE", servlet.getHttpMethodFromParameter(method, "DELETE"));
+  }
+
+  public void testRouteFromParameter() throws Exception {
+    assertEquals("path", servlet.getRouteFromParameter("/path"));
+    assertEquals("path", servlet.getRouteFromParameter("/path/fun"));
+    assertEquals("path", servlet.getRouteFromParameter("/path/fun/yes"));
   }
 
 }

Added: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/RestfulCollectionTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/RestfulCollectionTest.java?rev=667259&view=auto
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/RestfulCollectionTest.java (added)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/RestfulCollectionTest.java Thu Jun 12 15:04:25 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.dataservice;
+
+import com.google.common.collect.Lists;
+import junit.framework.TestCase;
+
+import java.util.List;
+
+public class RestfulCollectionTest extends TestCase {
+
+  public void testBasicMethods() throws Exception {
+    RestfulCollection<String> collection
+        = new RestfulCollection<String>(Lists.<String>newArrayList());
+
+    List<String> entry = Lists.newArrayList("banana");
+    int startIndex = 5;
+    int totalResults = 8675309;
+
+    collection.setEntry(entry);
+    collection.setStartIndex(startIndex);
+    collection.setTotalResults(totalResults);
+
+    assertEquals(entry, collection.getEntry());
+    assertEquals(startIndex, collection.getStartIndex());
+    assertEquals(totalResults, collection.getTotalResults());
+  }
+
+  public void testConstructors() throws Exception {
+    List<String> entry = Lists.newArrayList("banana", "who");
+    RestfulCollection<String> collection = new RestfulCollection<String>(entry);
+
+    assertEquals(entry, collection.getEntry());
+    assertEquals(0, collection.getStartIndex());
+    assertEquals(entry.size(), collection.getTotalResults());
+
+    int startIndex = 9;
+    int totalResults = 10;
+    collection = new RestfulCollection<String>(entry, startIndex, totalResults);
+
+    assertEquals(entry, collection.getEntry());
+    assertEquals(startIndex, collection.getStartIndex());
+    assertEquals(totalResults, collection.getTotalResults());
+  }
+
+}
\ No newline at end of file